I'm developing a web server in C #, but I have some problems with BATCH files that get Apache and MySQL running.
The BATCH that makes NGINX work I could do, but PHP does not start, gives an error of syntax and also need help with it.
NGINX-START.BAT (NGINX starts, but PHP does not start and syntax error)
Start Directory: C:\Users\NETO\Documents\Visual Studio 2010\Projects\MHServer\MHServer\bin\Debug\Server\Files\NGINX
Target Directory: C:\Users\NETO\Documents\Visual Studio 2010\Projects\MHServer\MHServer\bin\Debug\ with Php\php-cgi.exe
Error message: The syntax of the file name, directory name or volume label is incorrect.
The system can not find the path specified.
#ECHO OFF
cd \%CD%\
cd ..
cd ..
cd ..
cd Nginx
start nginx
set PATH=\Php;%PATH%
\Php\php-cgi.exe -b 127.0.0.1:9000
:exit
Apache-start.bat (Apache does not start and syntax error)
Error message: The syntax of the file name, directory name or volume label is incorrect.
The system can not find the path specified.
#ECHO OFF
cd \%CD%\
cd ..
cd ..
cd ..
\Apache\bin\Apache.exe
MySQL-start.bat (MySQL does not start and syntax error)
Error message: The syntax of the file name, directory name or volume label is incorrect.
The system can not find the path specified.
#ECHO OFF
cd \%CD%\
cd ..
cd ..
cd ..
\MySql\bin\mysqld.exe --defaults-file=\MySql\my.ini --standalone --console
:exit
Folder Structure (Folders of programs and files)
[C:\MHServer\Apache] - Apache Path
[C:\MHServer\MySql] - MySQL Path
[C:\MHServer\Nginx] - NGINX Path
[C:\MHServer\Php] - PHP Path
BAT folder files
[C:\MHServer\Server\Files\Apache] - Apache BAT Files
[C:\MHServer\Server\Files\MySQL] - MySQL BAT Files
[C:\MHServer\Server\Files\NGINX] - NGINX BAT Files
File Structure
/Files/
/Files/Apache/
/Files/MySQL/
/Files/NGINX/
I am not very good with BAT files, so I have come to you for help!
You just need to remove the backslashes from before the relative directory names.
For example:
\Apache\bin\Apache.exe
should be
Apache\bin\Apache.exe
Also, if you want to add your PHP directory to the PATH environmental variable in NGINX-START.BAT, you will need to use the full path, not a relative one. Something like this will work:
set PATH=%CD%\Php;%PATH%
Also, what are you trying to do with the cd \%CD%\? That should give an error on its own, so remove that from all of the scripts too.
So your first batch file should look like this:
#ECHO OFF
cd ..
cd ..
cd ..
cd Nginx
start nginx
cd ..
set PATH=%CD%\Php;%PATH%
Php\php-cgi.exe -b 127.0.0.1:9000
:exit
Related
I'm trying to run phpunit in my vagrant server in virtualbox(Ubuntu) for a school project, but I'm unable to.
I'm certain that my that phpunit is located in vendor/bin/phpunit and my test project is also in the right directory and everything is spelled correctly so I don't understand why I get this error.
I try to do:
vendor/bin/phpunit test/model/PDOGameModelTest.php
the error that I get is:
usr/bin/env: 'php\r': No such file or directory
Your file uses DOS file ending (CR+LF) and Ubuntu uses Unix one (LF). You have to convert your file with the command dos2unix :
Install it with :
sudo apt install dos2unix
Convert it with :
dos2unix test/model/PDOGameModelTest.php
Then :
vendor/bin/phpunit test/model/PDOGameModelTest.php
Edit : Another solution
awk '{ sub("\r$", ""); print }' test/model/PDOGameModelTest.php > test/model/PDOGameModelTest_converted.php
I have the same problem, but in my case it was a file
\vendor\bin\phpunit
it used DOS file ending (CR+LF) and Ubuntu uses Unix one (LF).
So I changed this file with NetBeans and the issue was fixed.
To change End Of File (EOF) in NetBeans just right click on the "file ending name" on a main window status bar.
I touched Docker for the first time yesterday, and I don't know much about web server administration in general. Just a heads up.
I'm struggling to make a simple PHP "hello world" run inside a Docker container. I have built a Docker container with the following dockerfile:
FROM nanoserver/iis
MAINTAINER nanoserver.es#gmail.com
ADD http://windows.php.net/downloads/releases/php-5.6.31-Win32-VC11-x64.zip php.zip
ADD https://nanoserver.es/nanofiles/vcruntime140.dll C:\\Windows\\System32\\vcruntime140.dll
ADD https://nanoserver.es/nanofiles/iisfcgi.dll C:\\Windows\\System32\\inetsrv\\iisfcgi.dll
ADD https://nanoserver.es/nanofiles/info.dll C:\\inetpub\\wwwroot\\info.php
COPY hello.php C:\\inetpub\\wwwroot\\hello.php
ENV PHP C:\\php
RUN powershell -command Expand-Archive -Path c:\php.zip -DestinationPath C:\php
RUN setx PATH /M %PATH%;C:\php
ADD https://nanoserver.es/nanofiles/php.ini C:\\php\\php.ini
RUN powershell -command \
rm C:\Windows\System32\inetsrv\config\Applicationhost.config ; \
Invoke-WebRequest -uri https://nanoserver.es/nanofiles/Applicationhost.txt -outfile C:\\Windows\\System32\\inetsrv\\config\\Applicationhost.config ; \
Remove-Item c:\php.zip -Force
# The above request fails, but I don't see how it would be relevant to my question.
CMD ["powershell.exe"]
I would expect this Dockerfile to create a container with c:\inetpub\wwwroot\info.php, c:\inetpub\wwwroot\hello.php and c:\php. However, Powershell inside the container gives me this output:
PS C:\inetpub\wwwroot> ls
Directory: C:\inetpub\wwwroot
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/11/2017 11:55 AM 703 iisstart.htm
-a---- 4/11/2017 11:55 AM 99710 iisstart.png
It feels like there is some fundamental that I haven't grasped. Could someone help me out here?
On windows you have to use forward slashes in paths in the Dockerfile.
Official docs: https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile
From docs
On Windows, the destination format must use forward slashes. For example, these are valid COPY instructions.
COPY test1.txt /temp/
COPY test1.txt c:/temp/
However, the following will NOT work.
COPY test1.txt c:\temp\
If either source or destination include whitespace, enclose the path in square brackets and double quotes.
COPY ["<source>", "<destination>"]
Also note that copying to non-existing paths in the image normally do not trigger an error. The directory must exist.
I was using XAMPP, and added a XAMPP sub-directory to my PATH in ~/.bash_profile, and now for some reason all of a sudden /Applications/XAMPP is my home directory (e.g. when I type "cd ~" and do "ls", it only lists the contents of the XAMPP folder. And because of this, I can't find my ~/.bash_profile to revert the PATH back to normal. It seems to have disappeared. Any suggestions?
I'm not completely sure what causes you to end up in /Applications/XAMPP. But I can tell you a way to debug a login shell:
PS4='+ $BASH_SOURCE:$LINENO: ' bash -xlic ''
-x is for debug, -l is login, -i is interactive, and -c '' is a NOP command.
PS4 will be appended on each line printed by -x, and in our case it will print file and line number from where the code is executed.
I have very annoying problem here that I am completely lost on.
Am just trying to run a bash script from a php page.
The bash script is a long one.... so I created a caller.sh which calls the ./mainScript.sh to run in the background in the following:
nohup /bin/bash /home/test/customcoincode/CoinCreationBashFile.sh $coinName $coinNameAbreviation $blockReward $blockSpacing $targetTimespan $totalCoins $seedNode $nameSeedNode $headline >> /tmp/BASH2log.txt 2>&1 &
in reading my log file it seems some variables are not being passed in...
and at the following lines of code:
echo "Creating New Coin - Downloading code base repo"
echo "$localFolder/$coinName"
mkdir -p "$localFolder/$coinName";
cd "$localFolder/$coinName"
git clone "$baseRepository" "$localFolder/$coinName"
echo "Made it here 1"
i get outputs of:
Creating New Coin - Downloading code base repo
/home/test/Foocoin
cloning into '/home/test/Foocoin'
could not create directory '/var/www/.ssh'
host key verification failed
blah blah ....
Why is it looking in the /var/www/ directory?? works fine if I run the script from terminal?
many thanks
So to pack up my comments in an answer:
The shell script is now run as apache, as git uses ssh, corresponding config files are needed. Which were created in /var/www; apaches home directory. Apache did not have write permissions in /var/www thus could not create these files.
To resolve, create the /var/www/.ssh directory yourself and give www-data (or whatever user apache runs under in your system) write access to that folder.
Next, github requires you to authorize ssh keys. It is safer to create a new one for apache in the newly created /var/www/.ssh directory and add this key to your github keychain.
Just a Question Regarding unix and PHP today.
What I am doing on my PHP is using the Unix system to untar a tarred file.
exec("tar -xzf foo.tar.gz");
Generally everything works fine until I run into this particular foo.tar.gz, which has a file system as follows:
Applications/
Library/
Systems/
After running the tar command, it seems that the file permissions get changed to 644 (instead of 755).
This causes Permission denied (errno 13) and therefore disabling most of my code. (I'm guessing from lack of privileges)
Any way I can stop this tar command completely ruining my permissions?
Thanks.
Oh and this seems to only happen when I have a foo.tar.gz file that Has this particular file system. Anything else and I'm good.
If you want to keep the permissions on files then you have to add the -p (or --preserve-permissions or --same-permissions) switch when extracting the tarball. From the tar man pages :
--preserve-permissions
--same-permissions
-p
When `tar' is extracting an archive, it normally subtracts the
users' umask from the permissions specified in the archive and
uses that number as the permissions to create the destination
file. Specifying this option instructs `tar' that it should use
the permissions directly from the archive.
So PHP code should be :
exec("tar -xzfp foo.tar.gz");
Edit: --delay-directory-restore solved the problem below about being unable to untar a file. The permissions of pwd are still altered, so the problem of the original poster might not be solved.
Not really an answer, but a way to reproduce the error.
First create some files and directories. Remove write access to the directories:
mkdir hello
mkdir hello/world
echo "bar" > hello/world/foo.txt
chmod -w hello/world
chmod -w hello
Next, create the tar file from within the directory, preserving permissions.
cd hello
tar -cpf ../hw.tar --no-recursion ./ world world/foo.txt
cd ..
Listing the archive:
tar -tvf hw.tar
# dr-xr-xr-x ./
# dr-xr-xr-x world/
# -rw-r--r-- world/foo.txt
So far, I've been unable to untar the archive as a normal user due to the "Permission denied"-error. The archive can't be untarred naively. The permissions of the local directory change as well.
mkdir untar
cd untar
ls -ld .
# drwxr-xr-x ./
tar -xvf ../hw.tar
# ./
# world/
# tar: world: Cannot mkdir: Permission denied
# world/foo.txt
# tar: world/foo.txt: Cannot open: No such file or directory
# tar: Exiting with failure status due to previous errors
ls -ld .
# dr-xr-xr-x ./
Experimenting with umask and/or -p did not help. However, adding --delay-directory-restore does help untarring:
tar -xv --delay-directory-restore -f ../hw.tar
# ./
# world/
# world/foo.txt
ls -ld .
# dr-xr-xr-x ./
chmod +w .
It is also possible to untar the file as root. What suprised me most is that tar apparently can change the permissions of pwd, which is still unsolved.
By the way, I originally got into this problem by creating a tarball for / with
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /
as root (pwd=/) and untarring it as a normal user to create a linux container.