Hi, I'm trying to restart bind using php: shell_exec("service named restart"), but for some reason, it keeps saying "stopping named...[failed] named already running" So I tried to make a sh file and executing it test.sh-------------- #!/bin/sh service named restart --------------- Gives error: Usage: /etc/init.d/named {start|stop|status|restart|condrestart|reload|configtest|probe} : command not foundamed.sh: line 3: What am I missing here? Is there a different way to run this command in a sh file? Thanks
I also tried: (in php script) <?php echo shell_exec("/etc/init.d/named restart"); ?> Givse me this: Stopping named: ..................................................[FAILED] Starting named: named: already running[FAILED] When I use that command with putty, it works... What am I missing here? Thanks
Hi, Both these commands are working correctly in putty: service named restart /etc/init.d/named restart (Just "stop" and "start" work as well ) However, when used inside a php script, they both return the same output: stopping named....[failed] starting named: named: already running [failed] The php script is: <?php echo shell_exec("/etc/init.d/named restart"); ?> or <?php echo shell_exec("service named restart"); ?> Both give same output as above. I also made a sh script to see if I can get that to work, but this is my first, and I can't get the sh script to work directly with putty, let alone with php. The sh script is as: #!/bin/bash F= "/etc/init.d/named stop" says: cannot find stop command I also tried: #!/bin/sh `service named restart` gives: Usage: service|stop|restart or something similar. I have spent the last 2 days doing nothing but searching the web with google, and still haven't found a sh script that would work, or a solution so I can directly get those commands working with php. I don't even know what I'm doing wrong with these. If I can get the service to restart automatically after 20-30 minutes anyway possible, even that would work. Like if there's a linux file I can edit and put the command in there. If you know a way to do this, please give me the command to paste in that file as well... Thanks
Aha! You were right. The sh script worked properly when I changed it's permissions to root:root But when I try to execute the script in shell_exec of php, it gives me a blank page for some reason. php code: <?php echo shell_exec("sh first.sh"); ?> I also changed the permission of this script like: chown root:root /home/site/test.php but still gives a blank page.
You can't execute this script via browser , Because your web server user won't we root ( apache or nobody )
oh. How do I restart this service using php then? On the shell_exec page of php.net I read someone using service restart command with php. How is this done? Thanks
well, webmin use Perl and CGI script, if you want to use only PHP you must do this step: - create a new user - configure a vhost with suEXEC and assign php execution using the new user - give permission that allow your user to restart named service - be sure shell_exec are enable in php.ini - try, will be work So when you run the shell command you will run with a user that can access to the file/command. If you give full permission for nobody or www-apache.. you security will be compromise because also other vhost can run command.
Hi, Thanks. Just 1 more thing. How can I do it with a CGI script then? I'm not very familiar with CGI, so if you could please post a code, or a link, that would be awesome. Thanks