OS X PATH problems: Home directory set to /Applications/XAMPP - php

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.

Related

php\r nu such file or directory when trying to run phpunit

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.

Running a Shell script from php

I have a question that have been asked many time over the web, but none of the solutions help my case.
I need a very simple website with a single button, by which on click, a single shell command is executed to deploy a docker container.
For this I have 3 files all located in /var/www/html/:
1- Depl-Script (a simple Linux file, made executable by chmod +x and chmod 777, and does not have .sh extension, including a single command:
docker run -it -p 8080:8080 surrogate
2- a DepGUI.php
<?php
// $output=shell-exec("/var/www/html/Depl-Script"); //didn't work
$output=shell_exec("./Depl-Script"); //this doesn't work neither
echo $output; //prints 0
$output1=shell_exec("whoami"); //prints www-data
echo $output1;
?>
3- a Main.html, including:
<form action="DepGUI.php">
<input type="submit" value="Open Script">
</form>
Shell-exec doesn't work for running the shell script.
How do I know it doesn't work? I check docker containers, nothing is created.
What solutions I have tried:
1) The shell script (Dep-Script) works fine when I run it from CLI, by root user.
2)Just to make sure, I changed the etc/passwd file, found the line with www-data user and changed it's login shell to /bin/bash, and then by www-data (apache) user, I executed the same shell script, and it works. (I returned the /etc/passwd file to the original shape)
3)I have checked the /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini and the exec, and shell_exec is not disabled.
4) I have checked the shell-exec and exec command with "sh" parameter, it did not work.
Any help/comment is appreciated in advance.
Thanks
Update:
I redirected errors to the output,
$output=shell_exec("./Depl-Script 2>&1");
I noticed the error is related to docker, "The input device is not a TTY" , then I got rid of -t in the docker command in the script (Dep-Script) and the error disappeared. I got a new error related to docker permissions and solved it using following link:
https://techoverflow.net/2017/03/01/solving-docker-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket/

CentOS Linux console command versus PHP exec(command)

I have a C program that I wrote called convert3to5, originally written for CentOS / Fedora 32bit system in early 2010. I am moving it to new CentOS 6.x 64bit system host.
From a CentOS Putty console I can run the convert3to5 command just fine; here is a sample of it running from my console:
[root#cloud convert3to5]# ls
CircleStar convert3to5 Convert3To5.txt test.tif
[root#cloud convert3to5]# ./convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
TIFFReadDirectory: Warning, /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif: wrong data type 7 for "RichTIFFIPTC"; tag ignored. Image has an undefined fillorder - using default: MSB2LSB
The above is a normal completion of convert3to5 and I get a SV-DIS160217B.bmp that is placed in /var/www/webadmin/data/www/mydomain.com/uploads/ So running it from console works fine.
Question - I am attempting to run the same exact command from PHP using the exec(command, output, return) command as follows:
chdir($sv_path.$c3to5_path); //change our working directory to "/convert3to5" directory
$command = "./convert3to5 $targetFile 2>&1";
$result = exec($command, $output, $return);
// the output of the above command - is a .bmp file it will be placed in the same path as the input .tif file
I get the following $result:
ERROR: Unable to convert
/var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif to 5
color BMP file: Open file Error: Tiff_3_to_BMP_5_.lut!
My convert3to5 does need to open Tiff_3_to_BMP_5_.lut
Why does it find Tiff_3_to_BMP_5_.lut when I run convert3to5 from a console prompt but not from PHP exec(...) in both cases my pwd shows that I am in
[root#cloud convert3to5]# pwd
/var/www/webadmin/data/www/mydomain.com/myView/convert3to5
I have also verified pwd is correct from my PHP script after the
chdir($sv_path.$c3to5_path);
Tiff_3_to_BMP_5_.lut is in CircleStar directory - the path to CircleStar is /var/www/webadmin/data/www/mydomain.com/myView/convert3to5/CircleStar
Summary: ./convert3to5 works while PHP exec('convert3to5 ..) does not appear to work.
Can anyone suggest the difference and how to fix and/or debug?
Thanks
You're running the console from the convert3to5 directory, and I suspect your old C program used a relative path to the .lut file, possible relative to the .tif?
What if in the console example you did
cd ../..
./path/to/convert3to5/convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
Might be related to $targetFile. Print that and see if it's the full path.
Finally, run
/full/path/to/convert3to5 fullTargetPath
If that works, then as a workaround, if you just do exec('/full/path/to/convert3to5 $fullTargetPath, ..) it should behave like the console.
Per my above comment to wonton:
From the console I was running as root (so fully privileged). I supposed my PHP script will run as the "apache" user on the server?
Here was the problem I believe: I looked at the CircleStar directory privileges where the Tiff_3_to_BMP_5_.lut file exists. CircleStar had rw-r--r-- (0644) when running as root from console this allowed my convert3to5 program to find and open Tiff_3_to_BMP_5_.lut file just fine. However not the PHP exec(...) once I changed the privilege on CircleStar to rwxr-xr-x (0755) PHP exec(...) ran fine!
So ultimately it was a permission issue.

Command not found: PHP exec()

This is driving me crazy. I need to have php execute a command to restart a script running in node. I'm using a node app called forever to run said script. The code is as follows:
<?php
echo '<pre>';
echo exec('sudo -u dalton forever restart botti.js 2>&1');
echo '</pre>';
?>
However, when I run that, I get sudo: forever: command not found
Next, I try which forever and type forever, both which give me:
forever: /usr/local/bin/forever
I edit my code to:
echo exec('sudo -u dalton /usr/local/bin/forever restart botti.js 2>&1');
Edit: After a typo, the error is now:
/usr/bin/env: node: No such file or directory
I'm at my wit's end. Any ideas?
As the forever command only runs, when you give the full path, I suspect, that /usr/local/bin is not in your PATH environment variable, which contains all directories, that are searched for executable commands by default, separated by : (I suspect you're on Linux, may differ for other OS)
I suspect forever calls /usr/bin/env node. The error from env is probably caused by node being outside your PATH too.
To set your PATH in php, use putenv('PATH=<your path here>');
e.g. to append /usr/local/bin:
putenv('PATH=' . getenv('PATH') . ':/usr/local/bin')
This may also be a sudo issue, try the -E (preserve environment) switch.
Figured it out, I needed to define node as well:
$asdf = system('sudo -E -u dalton /usr/local/bin/node /usr/local/bin/forever restart botti.js 2>&1');
Create a symbolic link for forever
ln -s /usr/local/bin/forever /usr/bin/env/forever
And also for nodejs if incase it's still called "nodejs". Make it call as "node"
ln -s /usr/bin/nodejs /usr/bin/node
I will solve the forever execution problem.
For php side, try with this
echo shell_exec("your command sh");

phpDocumentor - Could not open input file: phpdoc.php

I'm trying to use phpDocumentor (for the first time, I have no idea what I'm doing).
Actually, I want to use it only with SublimeText 2 and this plugin. Can you guide me step by step what should I do to make it working?
Here's what I've done now: (I'm using Windows 7)
Downloaded phpDocumentor from here and placed it somewhere.
I've created system PATH's for phpdoc/bin (so phpdoc.bat can be executed by sublime plugin) and then also added system path to php (from WAMPserver installation)
When I try to use my plugin (or execute phpdoc inside console window) I get this error:
Could not open input file: \phpdoc.php
Run:
pear
it will set %PHP_PEAR_PHP_BIN% for you.
You will need to set the environmental path for "PHP_PEAR_BIN_DIR" to the directory where "phpdoc.php" is.
I have changed phpdoc.bat file to point to exactly location of phpdoc.php
#echo off
if "%PHPBIN%" == "" set PHPBIN=php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "C:\wamp\bin\php\php5.3.10\phpdoc.php" %*
On my windows 7 system, I have my set up phpDocumentor (version 2.6.1) in wamp and my paths are like:
D:\Projects\wamp\www\phpDocumentor
D:\Projects\wamp\www\phpDocumentor\bin
Now what I did is I edited the phpdoc.bat file located at path:
D:\Projects\wamp\www\phpDocumentor\bin\phpdoc.bat
It contained code as shown below:
#echo off
if "%PHPBIN%" == "" set PHPBIN=php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "D:\Projects\wamp\www\phpDocumentor\bin\phpdoc" %*
So, I edited the last line "%PHPBIN%" "%PHP_PEAR_BIN_DIR%\phpdoc" %* with new code "%PHPBIN%" "phpdoc" %*. After phpdoc.bat looked like :
#echo off
if "%PHPBIN%" == "" set PHPBIN=php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "phpdoc" %*
Thereafter I again ran the below command in cmd:
D:\Projects\wamp\www\phpDocumentor\bin>phpdoc
And the output was like:
D:\Projects\wamp\www\phpDocumentor\bin>phpdoc
Collecting files .. OK
Initializing parser .. OK
Parsing files
[Exception]
No parsable files were found, did you specify any using the -f or -d parame
ter?
project:run [-t|--target[="..."]] [-f|--filename[="..."]] [-d|--directory[="..."
]] [--encoding[="..."]] [-e|--extensions[="..."]] [-i|--ignore[="..."]] [--ignor
e-tags[="..."]] [--hidden] [--ignore-symlinks] [-m|--markers[="..."]] [--title[=
"..."]] [--force] [--validate] [--visibility[="..."]] [--defaultpackagename[="..
."]] [--sourcecode] [-p|--progressbar] [--template[="..."]] [--parseprivate] [--
log[="..."]]
D:\Projects\wamp\www\phpDocumentor\bin>
So, the output showed that it worked successfully !!
PHP's include_path will need the path to the directory that contains that phpdoc.php file. Otherwise, none of the phpDocumentor code that uses require/include statements with relative paths will be able to find anything.
I just encountered this on Windows 7 having installed phpDocumentor2 via PEAR. I found that running:
phpdoc -d . -t docs
in an elevated command prompt did the trick - I suspect there's still some PATH issue on my machine that makes that the case, but having done all the default install steps for both PEAR and phpDocumentor it has proven the quickest workaround I've found.
I've got the same error message, the already made answers brought me to the right path.
As I don't use wamp/xampp or any of these programms, I thought: why don't run it directly with PHP?
I had already installed PHP7.0.x globally through WebPI.
Only php needs to be prefixed to the command, everything worked:
php .\phpDocumentor\bin\phpdoc -d .\src\ -t .\dst\

Categories