How can I run this from PHP?
sudo /etc/init.d/apache2 restart
How can I run this from PHP?
sudo /etc/init.d/apache2 restart
I don't think that's a good idea.
Also, have a look to the following discussions:
http://stackoverflow.com/questions/425717/can-php-restart-apache
http://www.linuxforums.org/forum/linux-security/3068-using-php-restart-apache.html
Just use the system() or exec() function without the sudo in the command, and run the php script as root.
You can use the exec command. http://ch.php.net/manual/en/function.exec.php
If you want to use sudo, just add the user Apache is running under (usually www) in the /etc/sudoers file.