# PHP as FastCGI on Windows: Simple how-to setup PHP as a service

**URL:** <https://www.ruby-forum.com/t/php-as-fastcgi-on-windows-simple-how-to-setup-php-as-a-service/226757>\
**Category:** NGINX\
**Created:** [February 20, 2013, 3:00pm UTC](https://www.ruby-forum.com/t/php-as-fastcgi-on-windows-simple-how-to-setup-php-as-a-service/226757 "2013-02-20T15:00:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrentNewland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f17d59/32.png) [@BrentNewland](https://www.ruby-forum.com/u/BrentNewland)\
**Post date:** [February 20, 2013, 3:00pm UTC](https://www.ruby-forum.com/t/php-as-fastcgi-on-windows-simple-how-to-setup-php-as-a-service/226757/1 "2013-02-20T15:00:06Z")

</div>

The official guide on setting up PHP as FastCGI on Windows  
[PHP-FastCGI on Windows | NGINX](http://wiki.nginx.org/PHPFastCGIOnWindows) makes use of batch files.

After extensive research and some new information, I’ve managed to make  
a  
fairly simple guide on setting up PHP as a service on Windows, with full  
start/stop/restart/status support.

The first thing that’s needed is the WinSW binary from  
[http://maven.jenkins-ci.org/content/repositories/releases/com/sun/winsw/winsw/](http://maven.jenkins-ci.org/content/repositories/releases/com/sun/winsw/winsw/)  
The “winsw-{VERSION}-bin.exe” needs to be saved to the folder containing  
php-cgi.exe, and needs to be renamed “winsw.exe”

In the same folder as php-cgi.exe and winsw.exe, create an xml file  
“winsw.xml” with the following content:

 PHP PHP PHP C:\PATH\TO\php\php-cgi.exe C:\PATH\TO\php\php-stop.cmd C:\PATH\FOR\WINSW\LOGFILES roll -bPORT -cc:\PATH\TO\php.ini

As an example, I keep PHP in C:\SERVER\php, the PHP ini file in  
C:\SERVER\config, and the logs in C:\SERVER\logs\php. PHP runs on port  
9123.

 PHP PHP PHP C:\SERVER\php\php-cgi.exe C:\SERVER\php\php-stop.cmd C:\SERVER\logs\php roll -b9123 -cc:\server\config\php.ini

In your PHP folder, alongside your php-cgi.exe, you need to make a file  
called “php-stop.cmd” with the following contents:

taskkill /f /IM php-cgi.exe

Once this has all been accomplished, open the command prompt, switch to  
the  
folder containing php-cgi.exe, and execute the following command:

winsw install

At this point, you can open the Services (win+run\>services.msc) and  
start  
PHP, or type “net start PHP”.  
You can also type “winsw start”, “winsw stop”, “winsw status”, and  
“winsw  
restart”

If having issues starting the service, verify it starts on its own by  
opening the command prompt to the folder containing php-cgi.exe and  
running:  
php-cgi -b(PORT) -cc:\PATH\TO\php.ini

Also, make sure the log folders referenced in the xml file exist.

Posted at Nginx Forum:

> **[PHP as FastCGI on Windows: Simple how-to setup PHP as a service](https://forum.nginx.org/read.php?2,236376,236376#msg-236376)**
>
> The official guide on setting up PHP as FastCGI on Windows http://wiki.nginx.org/PHPFastCGIOnWindows makes use of batch files. After extensive research and some new information, I've managed to make a fairly simple guide on setting up PHP as a...
