php problem to execute CutyCapt command - php

i'm having this problem
sh: CutyCapt: Permission denied
my php code is
<?php
echo exec('CutyCapt --url=http://www.google.com --out=/var/www/google.png --javascript=on 2>&1');
?>

When calling an executable from PHP, it is called with the permissions of the user PHP runs as (often the Apache server, for example).
That user account does not have permission to call that executable - probably because it belongs to a different user, and has the "executable" bit only for that user or group.
That's all that can be said for sure without more information.

Related

PHP Warning: shell_exec(): unable to execute '[command]'

background: I have a PHP script which calls shell_exec. For the moment i just want to test that it works and am running a basic command through it. Separate copies of the same script exist in two separate webapps on the same server. Both apps' anonymous authentication are set to IUSR.
Here is the example code:
$output = shell_exec('dir 2>&1');
print_r($output);
Trying it on one website in IIS gives the desired output. However, on another, it does not capture any output and instead give the below error:
PHP Warning: shell_exec(): Unable to execute 'dir 2>&1' in C:\inetpub\webapp\script.php on line 4
The only information i could find on this error is from here:
With PHP on Windows, if you get the 'Warning: shell_exec()
[function.shell-exec]: Unable to execute' error, then you need to
check the permissions on file 'C:\WINDOWS\system32\cmd.exe'. You need
read/execute permission on this file. I would recommend using the
sysinternals Process Monitor 'procmon.exe' to confirm the user that is
trying to run 'cmd.exe'. Filter on 'Process Name' is 'php-cgi.exe' and
'Path' ends with 'cmd.exe'. Look at the event properties for the task
with the access denied error, and it will show you the 'Impersonating'
user name. This is usually the 'Internet Guest Account', often 'NT
AUTHORITY\IUSR'.
Yet this doesnt seem like a permissions issue. I cannot understand why its working through on website and not another. Anonymous Authentication for both websites are set to IUSR.
also, safe_mode in php.ini is set to off.
Is there anything else i need to check here? Does cmd.exe need explicit read/execute permissions for IUSR?
It turns out, for whatever reason, that IUSR was the problem. I cannot exactly know why, but changing Anonymous Authentication of the affected website to use another user it worked. So it is permissions related after all.

Trying to run bash command in windows /usr/bin/env: ‘php’: Permission denied

This is my command that I've made but I get an error , I'm on WIN10
The error says that the user account that tries to run the command on that system has not the permissions / rights to do so. Please check, what user is trying to run that command and either give appropriate rights or create / change the permissions on that file.

php exec() rsync ssh to remote server not working

I am trying to rsync file from local to remote server.
When i do this on console it works:
rsync -avzhe ssh /var/www/folder1/file5
root#192.168.56.74:/var/www/folder2
but when i do this on my php and run the php script, it doesn't work:
$rysncCommand = "rsync -avzhe ssh /var/www/folder1/file5 root#192.168.56.74:/var/www/folder2";
shell_exec($rysncCommand);
There is no error shown, so i can't really tell what is the error. Is there something wrong with my php script?
First, you need to check if you need to be a root or (sudo user) for running rsync.
If yes then exec() command will only work if it is run by same user on php-cli (not on browser by Apache user). i.e. Which user you are loggined into shell for run rsync.
If it is root or any elavated permission user with sudo permission then, This rsync command may not be available to apache/www-data user which is working when php script run from browser.
So You try to make a normal user and login through it, Then try rsync if you are successful then it may be interesting to see what are other problems can be, But if you getting access/permission denied then obviously you can not run this script at-least on browser.
Besides this One more thing permission may not be directly related to rsync command itself but with folder /etc/test/ which is owned by root user in normal scenario.
For more details you can check this Stack Overflow Link .

Why it is giving permission denied while running a shell script?

After executing
frama-c -pdg -dot-pdg graph -pdg-print test.c
in a shell_script through php file. I am getting output as permission denied for graph.main.dot while directly executing the above command I am getting correct output.
Because when you run it, you are running it from your user account, and when PHP runs it, it is running it from the webserver account.
You have permission to access graph.main.dot but the web server does not.
You can alter the permissions using the chmod and chgrp commands.

Why cannot PHP execute a command from web browser?

This is really simple but I cannot get it to work at all. Spent many hours and I've always give up. I created php script called copy.php and it should call a python script called copy.py.
I want to execute a command line like this
<?php exec('/var/www/html/copy.py'); ?>
Really simple.
Why cannot I get the python script executed from php exec()? The function inside python script is to get a copy of error_log from a different directory (outside of Apache) into html directory.
If I run that from a terminal
> php copy.php
It did execute the function and made a copy. Why is that the web browser isn't doing it?
Let me simplify this:
why cannot exec("cp /var/log/httpd/error_log /var/www/html/path/to/php/script") work?
it works fine if I type it in terminal but not when run in a browser.
As others have alluded to, the difference is probably permissions. When you run a command from the command line, you're generally not the same users as your apache script is running as.
Put another way, if from the command line you type whoami, you'll probably get whatever name your user account is.
The echo exec('whoami'); from within php shows who the script is running as, which is Apache.
So, whatever command you're trying to run from your web server isn't available to run as the Apache user. You mentioned you've been able to have exec("python /usr/diskpurge/script.py") work, but not to have exec('/var/www/html/copy.py') doesn't. This is due to in one instance you're running python, in the other you're trying to execute your copy.py script. If copy.py doesn't have execute permissions for the Apache user, you're not going to be able to run it from the browser.
Perhaps different settings apply for the Apache environment versus the command line.
Use error_reporting(E_ALL); and ini_set('display_errors', true) to see what errosr may come up.
It is possible that the Apache environment is prohibited from using exec or the fact that Apache runs under a different user that does not have execute rights on the python script.
sounds like a permission error. Check if your server is running with sufficient rights.
echo exec('whoami');
Set your error reporting to report all:
ini_set('display_errors', true);
error_reporting(E_ALL);
and check for errors..
If your whoami returns a user which is not a member of the SU family (linux) or administration (windows) then resite your permissions..
Linux:
Assign the user returned by whoami correct permissions to run python scripts.. Do not allow the resulted username to run as root with total administration powers.. This is a big no no
The only reason its not working is because you didn't set the write permissions!
Do:
sudo nano /etc/sudoers
And then put the following:
www-data ALL=(root) NOPASSWD:ALL

Categories