Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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*
share|improve this question
    
Are you using SELinux (sestatus | grep enforcing)? If so, does ls -lZR /websockets/ show the right SELinux contexts (system_u:object_r:httpd_sys_script_exec_t:s0, most likely)? –  Christopher Oct 6 at 13:38
    
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 6 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 6 at 13:48
    
Im pretty sure that apache runs as "nobody" –  lior r Oct 6 at 13:51
    
Which user runs the Apache Web server on CentOS? ps aux | grep httpd | awk '{print $1}' (ignore "root"). Is SELinux on? sestatus|grep enforcing. What are the file system permissions? ls -l /websockets/timedactions.php What is the SELinux context? ls -lZ /websockets/timedactions.php Knowing those things helps to sort it out. –  Christopher Oct 6 at 14:00

1 Answer 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...

share|improve this answer
    
You could change $PATH variable in /etc/init.d/apache2. Take a look at Setting $PATH for weberver user it is relative to ubuntu, but I think that works for CentOS too. –  Letizia Oct 6 at 21:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.