Hey guys is they any way to restart Apache using /etc/init.d/apache2 restart through a PHP script, exec("/etc/init.d/apache2 restart) won't work because it needs root to restart and the script doesn't execute it under root.
You could always write a bash script that logs into root and then execute the bash script via exec(). If you don't have root you're screwed either way.
I do have root, I will do that, thanks.
1. Make a shell script that restarts Apache.
2. Either use SUID on the shell script or add that shell script to your sudoers file
3. Use either exec('sudo restart_apache.sh') or do the SUID magic
[editline]04:57PM[/editline]
Here's how I did it back in the days of me using Linux on my server:
[code]
<%@ Page Language="C#" %>
<%
System.Diagnostics.Process.Start("sudo /usr/bin/wwwcycle");
%>
Restarted.
[/code]
Sudo prompts for password, no?
[QUOTE=SGNinja101;24225761]Sudo prompts for password, no?[/QUOTE]
You can set it up not to ask for certain commands when executed by certain users.
Guys I got it working, I am writing this incase anyone around here wants to know, what I did was in Shell type visudo and add this line in there.
[code]www-data ALL=(ALL) NOPASSWD: /etc/init.d/lighttpd, /etc/init.d/mysql[/code] after you saved that you can run them commands through the script, I had a try with exec but that failed on me, so what I did to restart my lighttpd was.
[code]passthru("sudo /etc/init.d/lighttpd restart", $output_var);
echo $output_var[/code]
Now run the script and lighttpd will restart.
Coolio. Nice to know.
Nice security. I'll just leave this here.
[code]disable_functions = system, exec, passthru, shell_exec, proc_open, popen[/code]
[QUOTE=Maccabee;24243328]Nice security. I'll just leave this here.
[code]disable_functions = system, exec, passthru, shell_exec, proc_open, popen[/code][/QUOTE]
Only important within shared hosting/similar.
Why would apache even [i]need[/i] to be restarted, anyways?
Applying new settings.
[QUOTE=andersonmat;24255989]Applying new settings.[/QUOTE]
In that case it'd probably be better to send a SIGHUP instead of restarting.
Sorry, you need to Log In to post a reply to this thread.