Windows – php-cgi.exe as a windows service

PHPwindowswindows 8windows-services

I am trying to start PHP as a service, I run this command:

C:\Windows\system32>sc create PHPSERVER binpath= "C:\php\php-cgi.exe -b 127.0.0.1:9000" start= auto
[SC] CreateService SUCCESS

But the problem I am having, is when I open the services manager, and try to start the service I get this error:

Windows could not start the PHPSERVER service on Local Computer.

Error 1053: The service did not respond to the start or control request in a timely fashion.

Is there any way I can fix this, so it does work?

Best Answer

Download the service wrapper

Copy service.exe to your windows directory.

Location: C:\windows\

Open command prompt

Enter the following command

sc create PHP binPath= "service.exe \"C:\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\php\php.ini"" type= own start= auto error= ignore DisplayName= PHP

Note: Adjust paths for both "php-cgi.exe" and "php.ini" according to yours.

Once you have installed the service, you can start it via:

Command line:

sc start PHP    // to start PHP service.

sc delete PHP   // to delete PHP service

sc stop PHP // to stop PHP service

OR

GUI:

type "services.msc" at run then find "PHP" from the list and right click on it and select Start.

Related Question