I have installed webp package in my server and i want to use "dwebp" command in my PHP application.
My command is simple, it is like
dwebp "/full/path/test.webp" -o "/full/path/test.png"
If i run it from SSH terminal, it is 100% succesful.
But that command can't be run from PHP.
I have tried to use system(), passthru(), exec(). All failed which means the PNG file is not created.
However these commands succesfully called from PHP :
touch. If i use this, the created file is under "apache" owner.
ls -la
I have tried to change the directory permission from 777 / 775 / 755.
Using passthru, the result from calling from PHP is empty string.
In php.ini, disable_functions is empty
No error message, error_reporting is on.
Related
I am running a php file through browser which run the shell script but i recive the error ".sh: Permission denied"
My Php File is
<?php
$output = shell_exec('/var/www/html/test.sh 2>&1');
echo "$output";
My Shell Script is
#! /bin/bash
scp -r -i /home/ec2-user/key.pem /var/www/html/test ec2-user#172.16.11.12:/var/www/html/
echo "hello world"
Any help will be appreciated
We found that the script, test.sh, would fail with "Permission denied" when executed by php's shell_exec when the script was located in either /var/www/html/ and /root (which was the id commands being executed by shell_exec). It executed just fine when when we moved the script to /usr/local/bin. The script also worked when executed manually on a console in all 3 directories. This also excludes the mount noexec theory. I don't see any restrictions documented in php documentation for shell_exec, or php.ini. Neither AppArmor or SELinux are enabled on the host. There were no errors in /var/log that mentioned the script. int_get('open_basedir') and strace of the the php process when running the .php file (you can do that on the command line) would be the only other thing that has come up. Any other ideas? I am stumped.
I am running Ubuntu 16.04 and I am programming in PHP. Here is my problem:
I have a need to use the wget linux command to download all files from a website. So I am using PHP's shell_exec() function to execute the command:
$wgetCommand = "wget --recursive --page-requisites --convert-links $url 2>&1";
$wgetCommandOutput = shell_exec($wgetCommand);
This command downloads all files and folders from a website, recursively, to the current working directory (unless otherwise specified). The problem is that when these files and folders are downloaded, I do not have permissions to read them programmatically after that.
But if I do something like sudo chmod 777 -R path/to/downloaded/website/directory after they are downloaded with the wget command and before they are read programmatically, they are read just fine and everything works.
So I need a way to download folders and files from a website using wget command and they should have read permissions for all users, not just sudo.
How can I achieve that?
This sounds like a umask issue with the user running the PHP script.
Normally, Ubuntu would have a default umask of 0002. This would create a file with (-rw-rw-r--).
From the console you can check and set the umask for the PHP user via:
$umask
And inside the PHP script, do a
<?php
umask()
If you are on a running webserver, it would, however be better to alter the files permissions of the downloaded files afterwards, via
<?php
chmod()
The reason is, that the umask handles file creation for all files - not just your script.
I'm trying to compile a C program with shell_exec() (I tried using exec() also). I'm using nginx on CentOS 6 as a server. Here is the command I try to execute:
/usr/bin/gcc /MyStuff/program.c -o program
I set the permissions of the files and the parent folders to 755 and also tried:
/usr/sbin/setenforce Permissive
But none of them seems to give result. The php is under user apache. The output of the command execution when
/usr/sbin/setenforce Permissive
is:
collect2: cannot find 'ld'
When
/usr/sbin/setenforce Enforcing
is
cc1: error: /MyStuff/program.c: Permission denied
Any ideas what's the problem?
I SSH'd into my OpenShift application and compiled the C++ file using gcc and then downloaded it to my computer (for backup). I added it to git repo and pushed it.
How do I execute it in the current directory? I have tried changing permissions to 777 using chmod. I've tried exec(), shell_exec(), passthru(), system() in PHP with no luck. None of them gives me the output of the program.
Commands I used
Compiling C++: gcc code.cpp -o code.out
Inside run.php: chmod 777 code.out && ./code.out input-file (also tried chmod("code.out", 777);)
input-file is also pushed together with the code.out in same directory.
After a bit of testing, I found that it returns code 126 which is Permission problem or command is not an executable, but the permissions is 777 and it is in fact an executable.
Am I missing something?
(I'm sorry, but I don't have any experience with this)
Change the permission of the file so all can execute.
chmod a+rwx file
I prefer to use this instead of using 0777. That depends on your preference though.
When I'm trying to execute a PHP script using shell_exec(), it's not working.
In the error_log file it shows:
PHP Warning: shell_exec() [function.shell-exec]: Unable to execute
'php /home/snabbsam/public_html/.....
System
Centos
shell_exec works with clamscan
shell_exec() works on clamscan() function of clamav.
But it's not executing PHP script
Things I've checked:
PHP safe_mode is off
shell_exec() is not present in disable_functions in php.ini
Tried giving executable permission to the file & the parent folders as suggested in https://stackoverflow.com/a/8668666/402089
Try adding a full path to where the executable for php is in your shell_exec call, just in case it's in a directory that's not accessible by default for the webserver user.