Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to programmatically restart WAMP or Apache?

Tags:

wamp

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
like image 650
Frank Schwieterman Avatar asked Oct 05 '11 18:10

Frank Schwieterman


People also ask

How do I start and stop WAMP server?

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.

Does WAMP have Apache?

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.

How do I know if WAMP server is running?

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.


4 Answers

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.

like image 106
Nikunj K. Avatar answered Oct 11 '22 20:10

Nikunj K.


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
like image 23
user956584 Avatar answered Oct 11 '22 19:10

user956584


  1. CTRL+R -> Type (Command) -> Right Mouse -> Run Administrator
  2. Go to your wamp aptech bin folder eg : D:\wamp\bin\apache\apache2.4.9\bin>
  3. Type httpd.exe -d (Show All apache parameter command )
  4. httpd.exe -k start -n wampapache64
  5. httpd.exe -k stop -n wampapache64
  6. httpd.exe -k restart -n wampapache64

Graphical Instruction :

Step First:

enter image description here

Step Second:

enter image description here

like image 45
Ram Pukar Avatar answered Oct 11 '22 18:10

Ram Pukar


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.");
    }
}
like image 26
Frank Schwieterman Avatar answered Oct 11 '22 18:10

Frank Schwieterman