PHP XAMPP Restart Apache Through Browser

866 Views Asked by At

I'm trying to create a WHM / Plesk Type Control Panel for my Clients to use. I am running XAMPP on a VPS and want users to be able to, for example, ban IP's however for the change to take effect Apache needs to be restarted.

Is there a way using PHP the user can click a button and the Apache Service will restart?

I have tried using the following PHP code but all this does is Stop the Apache Server, it doesn't bring it back up?

<?php shell_exec("apache_stop.bat"); ?>
<?php shell_exec("apache_start.bat"); ?>

Both bat files are in the same directory as the php file and I have amended them so that the files are relative to them by adding this ..\..\ to the file paths.

Is there one file that I can run that will do both tasks automatically or is there a better way to do this?

2

There are 2 best solutions below

0
On

After you stop apache, it exit and do not start second job. You may use script that get this two jobs

0
On

You cannot restart Apache from a script. When the first shell_exec is called, the server process ends, and so the second call will never be made.

As an alternative, I suggest you ban devices/IPs using PHP - perhaps save them in a text-file or database and check from there.

Or, you can refer to the answers given for this question.