When I use the PHP exec() command on a mounted shared folder I do not get an output. When I run the same command via the command line it works fine. Example:
My W:\ drive is a shared drive. When I am in CMD.exe and I run this command it works:
dir W:\
When I run this command in PHP I do not get an output:
shell_exec("dir W:\")
I don't think its a permissions issue; the user manually running the command on CMD.exe is the same user that PHP is using to run the script. I verified this by running shell_exec("whoami").
Please note, when I run shell_exec("C:\") it works fine, its simply not working on shared drives.
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've been trying to run the php script:
shell_exec("bash /etc/example.sh")
from the browser but it does not work. This bash file creates a new one on the /etc directory.
I've also tried the functions exec() && system() but they don't work either. The weird thing happens when I run other Linux commands on these php function like:
shell_exec(rm -r /etc/fake);
they work fine, I have also tested my bash file on the linux command line and it works great.
I am sure this is not a permission issue, since I previously set the 777 permission on the file i am trying to execute.
shell_exec("bash /etc/example.sh")
I am using php7.0.33 and Debian 9, so I suppose this may be an issue with this PHP version 7.0.
Thank you for the help.
I have a binary file whose path is mentioned in the .bashrc file, I am able to execute it through command line. I copied the command to run the binary file into a bash(test.sh) file.
I am trying to execute this test.sh file through Php using the command
<php
shell_exec("test.sh")
?>
This says that command not found.
Maybe, your webserver configuration forbid execution of system commands.
Check your php.ini "disable_functions" section. If you see there something like below, this is the reason.
disable_functions=exec,passthru,shell_exec,system
I'm trying to execute docker command in that runApp.sh file
Remember, you script executes INSIDE docker container. It doesn't have access to the mother system.
If you want to execute docker commands inside docker container, your need docker in docker
I have a php script that works perfectly when ran form command line; including the exec().
The exec I do are calling some .sh scripts.
These .sh script are of type bash
So I call them:
exec('/bin/bash /home/user/soft/bin/mybash.sh > /dev/null');
It works great when I run my php from command line I see all the instructions; works also when use with an alias. but when I it via a daemon:
sudo -u myuser php -f /home/user/bin/serverwait.php eveything that should be done in the .sh are not being done. but the rest of the file is doing what it is suppose to do (it checks for open ports and write to a log file)
I tried looking at my php.ini for cli and all seems right.
I have a php script where some system commands are running fine and others are not. The commands that are not running can be copy and pasted to the shell and be ran just fine.
System: OSX 10.9.2 (everything is updated).
I have tried many different commands like the following.
backticks, exec(), shell_exec(), system(), passthru()
This command works fine.
exec("drush si -y --db-url=mysql://user:pass#localhost:3306/dbname");
But these commands do not run.
exec("drush sql-sync #remote.staging #dev.anme -y");
exec("git ls-remote --heads git#github.com:blablaname/name.git");
The commands that do not run can be copy and pasted into the shell and run great. I have made sure the script is being ran in the proper directory using the getcwd() function.
If you call php program having exec() from web browser,It executes as www user. So www user may not have privilege to connect/sync to remote host.That's why it works on localhost and failing on remote host.
So one solution is
1)save the command as bash script
2)set uid bit(It can be root or user having sufficient privilege).
3)execute that bash script by exec so that it will run as previlged user.
4)You should ip restrict your program since setuid is dangerous.
setuid