Results 1 to 4 of 4
Sorry for my English.
When I try to reload httpd service through commandline interface directly, it works. But when I tried to reload service of named and httpd using php ...
- 04-04-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 1
php exec(); can't reload httpd
Sorry for my English. 
When I try to reload httpd service through commandline interface directly, it works. But when I tried to reload service of named and httpd using php exec(), it doesn't works.
service named reload
service httpd reload
The service named is OK but httpd got problem.
My OS is CentOS 5.4 .
My script:
echo exec("service named reload"); result is " Reloading named: [OK] "
but
echo exec("service httpd reload"); result is " Reloading httpd: [FAILED] "
I tried to echo exec("whoami"); . I got "apache".
Then I edited /etc/sudoers.
root ALL=(ALL) NOPASSWD: ALL
apache ALL=(ALL) NOPASSWD: ALL
daemon ALL=(ALL) NOPASSWD: ALL
nobody ALL=(ALL) NOPASSWD: ALL
And I tried again.
echo exec("sudo service httpd reload"); ==> Not works.
echo exec("sudo /etc/init.d/httpd reload"); ==> Still not works.
echo exec("sudo -u root /etc/init.d/httpd reload"); ==> Not works.
Notice!
If "service httpd reload" without sudo, it doesn't works with message " Reloading httpd: [FAILED] " returned.
If I try "sudo service httpd reload", it doesn't works , no message returned.
How can I reload httpd through php exec() properly?
Thanks you.
- 04-10-2010 #2Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
It seems that SELinux does not allow you to perform it as 'apache' user even if /etc/sudoers allows it. Try to do 'setenforce 0' as root first, and then try to exec your php script again. If it helps, then you will have to do some "dark magic" with SELinux - just edit it policy
- 04-11-2010 #3Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
of course, you can't edit SELinux policy from php script. It must be done directly in linux terminal, and you must have a root access to the system. Anyway, I think it could be a big security hole, if terminating processes are permitted from web-scripts, isn't it?...
And there is another idea came to me.. I suppose that you use php as apache module, it means that all scripts are performed inside of apache process. And just imagine - can a script be performed if it tries to kill the interpreter itself?...
are you know that it MUST work as you want, or you just find variants how to do something?.. Have you already seen that thing working on other machines?
- 04-12-2010 #4Just Joined!
- Join Date
- Apr 2010
- Location
- San Diego, CA
- Posts
- 10
You should be able to make this work, as webmin has this capability. You might just look at their code to see how they do it.
I agree that giving elevating permission for the apache user is a huge security liability. Instead, try programming your web application so that admin users can authenticate to your web app, and use their credentials to reload the servers. (This is also probably how webmin works)
If you think selinux is blocking access, verify it is running in enforcing mode with:
If it is running, you will see it as "enabled" and "enforcing". If it says disabled or permissive, selinux is not your problem.Code:sestatus
If it is enabled and enforcing, you can check to see if it is causing your problem by generating a report:
Code:sealert -a /var/log/audit/audit.log > ~/sealert_report


Reply With Quote
