- 创建windows服务用到一个小工具WinSW:https://github.com/kohsuke/winsw/releases(下载 .exe 文件即可,根据系统选择,Win 10 选择 .NET4 版本,以下选择 .NET2 版本)
- 把php-cgi.exe注册成windows服务除了需要用到WinSW以外,还需要用到xxfpm,用来开启 PHP-CGI 多进程,下载地址:https://github.com/78/xxfpm
- 将下载到的WinSW.NET4.exe更名为nginxservice.exe,放到nginx.exe所在的目录下,在该目录下新增文件 nginxservice.xml,修改nginxservice.xml配置如下:
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>E:\nginx-1.12.2\</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>E:\nginx-1.12.2\nginx.exe</executable>
<stopexecutable>E:\nginx-1.12.2\nginx.exe -s quit</stopexecutable>
</service>
- 在E:\nginx-1.12.2\下执行 nginxservice.exe install,即可生成windows服务,卸载命令:nginxservice.exe uninstall
- php的服务注册需要先下载xxfpm,将下载的xxfpm.exe 和 pthreadGC2.dll 扔进php-cgi.exe所在的目录
- 将下载到的WinSW.NET4.exe更名为phpservice.exe,放到php-cgi.exe所在的目录下,在该目录下新增文件 phpservice.xml,修改phpservice.xml配置如下
<service>
<id>phpservice</id>
<name>phpservice</name>
<description>phpservice</description>
<executable>xxfpm.exe</executable>
<startargument>"D:/apps/php-5.6.40x64/php-cgi.exe -c D:/apps/php-5.6.40x64/php.ini"</startargument>
<startargument>-n</startargument>
<startargument>1</startargument>
<startargument>-i</startargument>
<startargument>127.0.0.1</startargument>
<startargument>-p</startargument>
<startargument>9000</startargument>
<stopexecutable>taskkill</stopexecutable>
<stopargument>/F</stopargument>
<stopargument>/IM</stopargument>
<stopargument>xxfpm.exe</stopargument>
<logpath>logs</logpath>
</service>
- 在 D:\apps\php-5.6.40x64下执行 phpservice.exe install,即可生成windows服务
D:\apps\php-5.6.40x64>phpservice.exe install
2019-01-21 09:49:25,245 INFO - Installing the service with id 'phpservice'