I have trouble running wget through php exec or system functions. The configuration is with MAMP.
I successfully run basic commands like ('whoami', 'pwd', etc.).
I even changed the apache user to the root user and still nothing. In the error log it output "wget: command not found".
I can run with the terminal and it works fine. The wget is installed through Macports.
What should I do?
Regards!
From a terminal, run which wget, and use the full path in the call to exec/system.
Related
Trying to execute aws cli commands with php shell_exec on local server (for tests).
I'm using xampp,
windows operating system,
Laravel and php,
I installed aws cli on windows.
Windows cmd recognizes the aws commands, but when I try to execute the aws command with shell_exec i get an error: "aws is not recognized as an internal or external command".
Tried this simple script:
$exec = shell_exec('aws --version');
$exec return null.
Appreciate any help.
if you can't run the command directly in shell_exec(), then what you can do is make a batch file with the command and place it on the root of your website. Then, just run:
<?php echo exec("script.bat"); ?>
also, make sure to put any environment variables needed and recommend to use full path for the aws executable
I solved it. It was pretty simple. It doesn't enough to restart xampp. I also had to quit xampp and re enter
I have meshlab installed in my machine running Ubuntu 14.04 OS. I can access it from command line using meshlabserver command. But problem arises whenever I try to call it from a php script using the command
<?php
system('meshlabserver 2>&1');
?>
It shows the error meshlabserver: cannot connect to X server. After going through a few websites I did the following things:
I moved the meshlabserver executable from /usr/bin to /usr/local/bin and gave it executable permissions using
sudo chmod a+x meshlabserver
But when I ran the whoami command from my php script (calling the meshlabserver), it showed www-data. So I gave executable permissions for all users to the meshlabserver using
sudo chmod 777 /usr/local/bin/meshlabserver
But still it is showing the same meshlabserver: cannot connect to X server error. meshlabserver comamnd is working fine when ran from the command line.
I really need to call meshlab from the php script for my website. Thus any help would be highly appreciated. Thanks in advance.
It seems the php script can't access your display variable. If you logged in via ssh remember to tunnel your X-server via 'ssh -X ...' Your second option is to create a virtual frame buffer using Xvfb and redirect the display variable to it:
export DISPLAY=:100.0
Xvfb :100 &
Note the ampersand for the second command as Xvfb needs to be running in the background.
a combo of prior answers works for me:
ssh -X, as well as export DISPLAY=:0.0 (on remote)
on my local machine I execute the following:
exec('sudo nohup '.PHP_BINDIR.'/php '.ROOT.'/index.php controller=imports action=import id=12 > /dev/null 2>&1 &');
where "ROOT" is a constant with the complete path.
Everything works fine and the script is executed asyncronously with no problems.
When I run the same script on production environment (a bitnami LAMP stack running on AWS) instead: if I run it directly from the terminal it works, when I run it from php it doesn't.
I have nothing in the apache error_log and if I run it with shell_exec the returned value is NULL.
If I try to execute a different script from php (like exec('whoami')) it works, so I don't think is a permissions thing.
I also tried replacing php command with php-cli, nothing changes.
Hope someone can help.
Thanks in advance.
i have installed on my server phantomJS (to /usr/bin/phantomjs) when i run it from the shell as root it works perfectly fine, but when i try to run it via PHP it does not work,
those are the commands i have tried:
exec('/usr/bin/phantomjs --version');
shell_exec('/usr/binphantomjs --version')
exec('phantomjs --version');
shell_exec('phantomjs --version')
all of them return empty,
i have checked that the apache user have access to this folder and even moved it using the php exec function.
i have tried to run it with both system types (i run Linux redhat 64bit)
what else could be my problem ?
I've installed git-ftp onto my CentOS Server so that I can do deployments from an activeCollab installation running the ac_gitolite module.
Everything installed fine and the app lives at
/usr/local/bin/git-ftp
When I log into the server via ssh I can run git-ftp commands without the full path, but when attempting to use PHP to run commands with exec ie:
exec ("git-ftp --version 2>&1", $output);
I receive the following error:
sh: git-ftp: command not found
Is there an environment path I need to specify somewhere specifically for PHP, or what am I doing wrong?
The two options discussed in "command not found - error in exec() command" are:
One easy solution would be to put the full path of the git-ftp executable.
The other is to add git-ftp to the php server user's PATH.