As part of some automated deploy + test scripts I use to verify programming done for a site, I have some scripts which update Apache's config files. I would like to programmatically restart WAMP so the changes take effect. Is there a good way to do this?
The scripts are powershell.
This is whats in my apache bin folder:
iconv
ab.exe
abs.exe
ApacheMonitor.exe
apr_dbd_odbc-1.dll
apr_ldap-1.dll
dbmmanage.pl
htcacheclean.exe
htdbm.exe
htdigest.exe
htpasswd.exe
httpd.exe
httxt2dbm.exe
libapr-1.dll
libapriconv-1.dll
libaprutil-1.dll
libeay32.dll
libhttpd.dll
logresolve.exe
openssl.exe
php.ini
php5isapi.dll
php5ts.dll
rotatelogs.exe
ssleay32.dll
wintty.exe
zlib1.dll
Shutting Down WampServer To shut down WampServer, click on the systray icon and select Stop All Services to shut down the Apache and MySQL services. The icon will turn red once all services have been shut down. Next you will right-click on the WampServer systray icon and click Exit to close the program.
WAMP is an acronym that stands for Windows, Apache, MySQL, and PHP. It's a software stack which means installing WAMP installs Apache, MySQL, and PHP on your operating system (Windows in the case of WAMP). Even though you can install them separately, they are usually bundled up, and for a good reason too.
Click on the wamp server icon in the taskbar and test "localhost". If that works, click the " phpinfo() " link on the page. If that works too, your wamp server is working and you should be able to execute php files.
You can use this command to restart Wamp, Apache, MySQL services:
To start services
NET START wampapache
NET START wampmysqld
To stop services
NET STOP wampapache
NET STOP wampmysqld
For mariaDB, replace wampmysqld
with wampmariadb
.
For 64 bits: append 64 to the service names.
Simple execute command:
httpd.exe -k restart
ps. this is my wathdog for windows
@echo off
:loop
timeout /t 30 /nobreak
REM .
tasklist /FI "IMAGENAME eq php-cgi.exe" 2>NUL | find /I /N "php-cgi.exe">NUL
if "%ERRORLEVEL%"=="1" goto Process_NotFound
tasklist /FI "IMAGENAME eq httpd.exe" 2>NUL | find /I /N "httpd.exe">NUL
if "%ERRORLEVEL%"=="1" goto Process_NotFound
goto loop
:Process_NotFound
TASKKILL /F /IM php-cgi.exe
TASKKILL /F /IM httpd.exe
ping 127.0.0.1 -n 2
Apache -k start
ping 127.0.0.1 -n 3
cls
php.exe -r "$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://server.name/'); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch);"
ping 127.0.0.1 -n 3
ab.exe -n 10 -c 3 http://server.name/
goto loop
- CTRL+R -> Type (Command) -> Right Mouse -> Run Administrator
- Go to your wamp aptech bin folder eg : D:\wamp\bin\apache\apache2.4.9\bin>
- Type httpd.exe -d (Show All apache parameter command )
- httpd.exe -k start -n wampapache64
- httpd.exe -k stop -n wampapache64
- httpd.exe -k restart -n wampapache64
Graphical Instruction :
Step First:
Step Second:
I ended up writing some code to find the "wampapache" service and restarting it.
public static void ResetApache()
{
ServiceUtil.RestartService("wampapache", 10000);
}
...
public class ServiceUtil
{
public static void RestartService(string serviceName, int msTimeout)
{
ServiceController service = new ServiceController(serviceName);
int startTicks = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(msTimeout);
if (service.Status != ServiceControllerStatus.Stopped
&& service.Status != ServiceControllerStatus.StopPending)
{
service.Stop();
}
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
int midTicks = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(msTimeout - (midTicks - startTicks));
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
//int finalTicks = Environment.TickCount;
//var totalTime = TimeSpan.FromTicks(finalTicks - startTicks);
//Console.WriteLine("Reseting process took " + (totalTime.TotalMilliseconds/1000.0) + " seconds.");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With