Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Title says it all; I cannot run shell commands properly from PHP (CGI). Most commands (pwd and my own program) end with an exit code of 1 (permission denied). The command ls ends with an exit code of 2.

System Note:

  • Apache is running as apache:apache (user/group)
  • PHP is not chrooted (AFAIK) if you know a definitive way to find out, please reply
  • PHP is not in SAFE_MODE
  • selinux is DISABLED (sestatus says so)
  • suexec is enabled (not sure what to do with it though)
  • Functions are not disabled from PHP (otherwise I'd get scripting errors instead of exit codes)

Things I tried:

  • Disabled selinux (it was enabled)
  • Made apache to run as root (it crashed - a well known issue)
  • Changed file permissions of my entire DOCROOT to 0755 and 0777 (and back)
  • Changed file owner of my entire DOCROOT to root and nobody, both caused apache to show "access denied" errors
  • To use strace to get a clue of what's going on, but it failed as well
  • Run PHP code through CLI (php -r "echo exec('pwd');") - and it works
  • Ensure error logging is at it's max (and displayed), both for PHP and Apache (E_ALL / Debug) - no errors showed up

More notes


Dump of $_SERVER

[HTTP_HOST] => localhost
[HTTP_USER_AGENT] => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110622 CentOS/3.6-1.el5.centos Firefox/3.6.18
[HTTP_ACCEPT] => yaddayaddayaddayaddayadda
[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] => 115
[HTTP_CONNECTION] => keep-alive
[HTTP_REFERER] => http://localhost/K2F/?test=system-check
[HTTP_CACHE_CONTROL] => max-age=0
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] => <address>Apache/2.2.3 (CentOS) Server at localhost Port 80</address>

[SERVER_SOFTWARE] => Apache/2.2.3 (CentOS)
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => root@localhost
[SCRIPT_FILENAME] => /var/www/html/K2F/index.php
[REMOTE_PORT] => 49341
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => test=wkhtmltox
[REQUEST_URI] => /K2F/?test=wkhtmltox
[SCRIPT_NAME] => /K2F/index.php
[PHP_SELF] => /K2F/index.php
[REQUEST_TIME] => 1315908875

Misc. PHP functions

[GID] => 48   ---------------.___ both are correct
[UID] => 48   ---------------'
[PID] => 4152
[USR] => apache   -----------.___ fine as well
[CWD] => /var/www/html/K2F --'
share|improve this question
1  
Show us an example of the command you are trying to run. Is there anything in your error_log that is relevant? –  Iain Sep 13 '11 at 10:23
    
The command is as simple as echo exec('pwd'); (should show /root). No, there's nothing related in the error log (both PHP's and Apache's). –  Christian Sep 13 '11 at 10:27
    
Well, my last remaining option is Linux's equivalent to Windows' restart :- a reinstall :D –  Christian Sep 13 '11 at 10:39
    
Reinstall is not a solution. Please give us the exactly error you get when accessing via browser? Also post your error logging configuration section? –  quanta Sep 13 '11 at 11:06
    
@quanta - What error do you expect from the browser? It writes what I told it to write, namely the exit code which as I said above, is sometimes a 1 or a 2. What do you mean by "logging configuration section"? As to reinstall, it's the only sane option that works with linux when all else fails... –  Christian Sep 13 '11 at 11:14
show 4 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.