Categories
apache php

How to restart Apache with PHP

If you ever need to restart Apache via PHP, you’ll notice that the “passthru” command doesn’t quite work out like you thought it would. For those of you who have cpanel and WHM installed, this will be an easy solution.  cpanelmatt at the cpanel forums created an XML-API PHP class to be able to handle situations like this.

First download the XML-API PHP class.

Next, follow the code example below:

include("xmlapi.php");

$ip = "127.0.0.1";
$root_pass = "somepass";

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);

$xmlapi->set_debug(1);

print $xmlapi->restartsrv('httpd');

One reply on “How to restart Apache with PHP”

Leave a Reply