Results 1 to 15 of 15
-
12-25-2009, 04:42 PM #1Junior Guru
- Join Date
- Apr 2008
- Location
- India
- Posts
- 227
Restart httpd and mysql service through php code ?
Hi,
I want to create a php program to restart httpd and mysql services....
<?php
$output=shell_exec('/etc/init.d/httpd restart');
echo $output;
exit;
?>
when i run this program i m getting below 3 errors :-
/etc/init.d/httpd: line 15: ulimit: open files: cannot modify limit: Operation not permitted
/etc/init.d/httpd: line 16: ulimit: open files: cannot modify limit: Operation not permitted
httpd: Could not open configuration file /usr/local/apache/conf/httpd.conf: Permission denied
================================================
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
/etc/init.d/httpd: line 13: ulimit: open files: cannot modify limit: Operation not permitted
================================================
Syntax error on line 884 of /usr/local/apache/conf/httpd.conf:
SSLCertificateKeyFile: file '/etc/ssl/private/domain.com.key' does not exist or is empty
================================================
Can any one guide me how to solve this problem ?
Thank you.
-
12-25-2009, 06:10 PM #2WHT Addict
- Join Date
- Apr 2009
- Posts
- 107
Homer knows about his website downtime, what about you?
site-uptime.net site uptime monitor
-
12-25-2009, 06:55 PM #3WHT Addict
- Join Date
- Apr 2009
- Location
- Islamabad , pakistan
- Posts
- 128
You can also try by granting apache the root previliges. You can do so by adding it in /etc/sudoers file.
-
12-27-2009, 03:00 AM #4Junior Guru
- Join Date
- Apr 2008
- Location
- India
- Posts
- 227
Hi,
Which user i have to add under sudoers file, Please guide me..
I have already tried with nobody and apache users.
Thank you.
-
12-27-2009, 04:42 AM #5Web Hosting Master
- Join Date
- Jul 2009
- Posts
- 1,568
| LinuxHostingSupport.net
| Server Setup | Security | Optimization | Troubleshooting | Server Migration
| Monthly and Task basis services.
| MSN : madaboutlinux[at]hotmail.com | Skype : madaboutlinux
-
12-27-2009, 04:43 AM #6Web Hosting Master
- Join Date
- Apr 2003
- Location
- San Jose, CA.
- Posts
- 1,624
I'll put $2 on his "I got rooted, what do I do now" post appearing in less than 4 weeks of implementation
In otherwords, this is a rather dumb idea.
-
12-27-2009, 04:51 AM #7Web Hosting Master
- Join Date
- Jul 2009
- Posts
- 1,568
Right, the function "shell_exec" should be turned off server wide for security reasons and only use it when it is utmost needed.
| LinuxHostingSupport.net
| Server Setup | Security | Optimization | Troubleshooting | Server Migration
| Monthly and Task basis services.
| MSN : madaboutlinux[at]hotmail.com | Skype : madaboutlinux
-
12-27-2009, 06:02 AM #8Junior Guru
- Join Date
- Apr 2008
- Location
- India
- Posts
- 227
Hi,
Yes i know this is dumb idea. But i m trying to do this task through php for my local R & D network. I have already created shell script for that and its working perfectly.
So if any body knows how to do through php please guide me....
Thanks to all.... -
-
12-27-2009, 06:45 AM #9Web Hosting Master
- Join Date
- Apr 2003
- Location
- San Jose, CA.
- Posts
- 1,624
How are you trying to run the php program?
CLI as in:
php ./this_is_retarded.php
or via accessing a URL:
https://gonnagethackedsoon.com/this_is_retarded.php
-
12-27-2009, 07:20 AM #10Death is Sex
- Join Date
- Jun 2006
- Location
- Ahh' UnderPants
- Posts
- 1,013
I believe he is trying to access via httpd, if it was on CLI, he could have just written the command without using a script.
-
12-27-2009, 07:30 AM #11Disabled
- Join Date
- Apr 2009
- Posts
- 3,262
You could just run a .sh file by using shell_exec.
-
12-27-2009, 08:01 AM #12Junior Guru
- Join Date
- Apr 2008
- Location
- India
- Posts
- 227
Hi,
Yes Woooo you are right. I am giving you all the details.
[root@linuxboy R&D]# php test.php
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@linuxboy R&D]# cat test.php
<?php
$output=shell_exec('service httpd restart');
echo $output;
exit;
?>
[root@linuxboy R&D]# cat php.php
<?php
$out= exec('/opt/test.sh');
echo $out;
exit;
?>
[root@linuxboy R&D]# ./test.sh
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@linuxboy R&D]# cat test.sh
/etc/init.d/httpd restart
Thanks to all..... -
-
12-27-2009, 09:04 AM #13Web Hosting Master
- Join Date
- Jul 2009
- Posts
- 1,568
so finally a shell script (test.sh) is restarting the httpd service
| LinuxHostingSupport.net
| Server Setup | Security | Optimization | Troubleshooting | Server Migration
| Monthly and Task basis services.
| MSN : madaboutlinux[at]hotmail.com | Skype : madaboutlinux
-
12-27-2009, 09:25 AM #14Junior Guru
- Join Date
- Apr 2008
- Location
- India
- Posts
- 227
Hi,
Not from web...
http://127.0.0.1/php.php
=======================
<?php
$out= exec('/opt/test.sh');
echo $out;
exit;
?>
=======================
<?php
$out= shell_exec('/opt/test.sh');
echo $out;
exit;
?>
=======================
Thanks to all....
-
12-27-2009, 11:04 AM #15Web Hosting Master
- Join Date
- Oct 2006
- Location
- /usr/src/linux/
- Posts
- 700
OK there is rather semi-clean way of doing this, however I'm probably missing something (security wise) but nothing that's on top of my head.
Use a binary as a wrapper to restart apache and mysql rather than directly from the init scripts such as for example this
Code:int main() { system("/etc/init.d/mysqld restart;/etc/init.d/httpd restart"); return 1; }
Compile the binary using gcc -o test test.c
Then use visudo to edit /etc/sudoers, make sure to remove
Code:Defaults requiretty
Code:sudo: sorry, you must have a tty to run sudo
Check under which user apache runs, nobody, apache, www-data etc. In my case it was apache, add the following line in /etc/sudoers
Code:apache ALL=NOPASSWD: /var/www/html/test
Then you may use a php script such as this to execute the binary and restart mysql and httpd
Code:<?php passthru("/usr/bin/sudo /var/www/html/test"); ?>
█ VPSnoc.com offers high quality Xen® OpenVZ & Windows® Virtual Private Servers at affordable prices.
█ 99.95% Uptime | 24/7/365 Support | Unmetered bandwidth.
█ Follow us: twitter.com/VPSnoc
Similar Threads
-
shutdown -r now OR service httpd restart? Difference?
By kohkindachi in forum Hosting Security and TechnologyReplies: 4Last Post: 09-22-2009, 11:40 AM -
failed to restart mysql service
By kotlt in forum Hosting Security and TechnologyReplies: 4Last Post: 04-13-2009, 09:21 AM -
Cannot restart MySQL, HTTPD and server
By DelPierro in forum Hosting Security and TechnologyReplies: 16Last Post: 11-22-2007, 11:24 PM -
How to install service httpd restart ?
By mouseattack in forum Hosting Security and TechnologyReplies: 2Last Post: 07-21-2006, 07:02 PM -
error when restart MYSQL service
By AndyJ in forum Hosting Security and TechnologyReplies: 4Last Post: 03-02-2005, 05:06 PM