1

I'm using an ajax call to execute "shell_exec" on the server (centos). The line that I'm executing is the following

echo shell_exec("php -q /websockets/timedactions.php");

This is the server response:

X-Powered-By: PHP/5.5.16
Access-Control-Allow-Origin: http://myIpAddress
Access-Control-Allow-Credentials: true
Content-type: text/html

After running this command it seems that the process that it supposed to activate is not running.

Calling the same command on shell with root access

php -q /websockets/timedactions.php

works perfectly.

How can I make the script work using shell_exec ?

more info:

ps aux | grep httpd | awk '{print $1}' = nobody


sestatus|grep enforcing = {no result}


file permissions -rwxr-xr-x 1 root root 


ls -lZ timedactions.php -rwxr-xr-x root root ? timedactions.php*
lior r
  • 121
  • This will depend on your setup. What user is running the php file? Presumably, it is www-data or whatever your webserver's user name is. Does that user have access to the file? Does the script depend on any specific variables? Do you have any errors in your log file? – terdon Oct 06 '14 at 13:38
  • how do i know if im using SELinux ? i have no errors and there are no dependent variables but some included files. I have added #!/usr/bin/env php to the top of the PHP files and a mentioned running the command via the console works – lior r Oct 06 '14 at 13:48
  • Im pretty sure that apache runs as "nobody" – lior r Oct 06 '14 at 13:51
  • What are the permissions you're showing? Of which file or directory? The problem is probably that this is being run by the user nobody and they don't have permissions to execute the script. What happens if you try sudo -u nobody php -q /websockets/timedactions.php? – terdon Oct 06 '14 at 14:35
  • terdon - im getting "sudo: sorry, you must have a tty to run sudo" – lior r Oct 06 '14 at 14:36
  • shell_exec("/websockets/timedactions.php"); - returns the same as mentioned in my question (just the headers) – lior r Oct 06 '14 at 14:47
  • mmm... well im running cpanel if thats relevant. im running CentOS release 6.5 (Final) on – lior r Oct 06 '14 at 15:14
  • Did you try php -f /full/path/timedactions.php? Also check if your $PATH environment contains path to php executable. try shell_exec(echo "$PATH") – Lety Oct 06 '14 at 16:29
  • echo $path returns /bin:/usr/bin. php -f... same results as before , the php script is not runnnig – lior r Oct 06 '14 at 18:56

1 Answers1

1

Well ok then

Seems the answer was pretty easy (frustrating as it can be :-) ) I just added the complete path to PHP. Dont really know why i didnt get any errors before and why it is working (if anyone can explain)

shell_exec('/usr/local/bin/php -q /websockets/timedactions.php /dev/null 2>&1 &');

Thank you for trying...

lior r
  • 121