将nginx、php-cgi注册为windows服务,开机自启动

将nginx、php-cgi注册为windows服务,开机自启动

一、windows服务包装器

Windows 服务包装器(Windows service wrapper),用于把.exe文件注册为windows服务。比如把nginx.exe注册为windows服务,这样做的好处是,每次启动nginx时不用在命令行中输入命令,而且可以随windows系统启动而启动。不用担心服务器意外重启,服务挂掉。
下载地址:repo.jenkins-ci.org/releases/com/sun/winsw/winsw/1.18/winsw-1.18-bin.exe

二、nginx

将下载到的winsw-1.18-bin.exe更名为service.exe,放到nginx根目录下,
在该目录下新增文件 service.xml,修改service.xml配置如下:
 
    
	nginx
    
	Nginx Service
    
	Nginx Service
      
	D:\nginx\logs  
    
       
        
	10240
        
	8
    
    
      
	D:\nginx\nginx.exe  
    
	-p D:\nginx
    
	D:\nginx\nginx.exe
    
	-p D:\nginx -s stop


以管理员身份打开cmd命令行,进入nginx根目录,
在D:\nginx\下执行 service.exe install,即可生成windows服务,卸载命令:service.exe uninstall

三、PHP

把php-cgi.exe注册成windows服务除了需要用到WinSW以外,还需要用到xxfpm,用来开启 PHP-CGI 多进程,
下载地址:https://github.com/78/xxfpm
将下载的xxfpm.exe 和 pthreadGC2.dll 放到php-cgi.exe所在的目录,
将下载到的winsw-1.18-bin.exe更名为phpservice.exe,放到php-cgi.exe所在的目录下,
在该目录下新增文件 phpservice.xml,修改phpservice.xml配置如下:


phpservice
phpservice
phpservice
xxfpm.exe
"D:/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/php/php.ini"
-n
1
-i
127.0.0.1
-p
9000
taskkill
/F
/IM
xxfpm.exe
D:/php/logs

以管理员身份打开cmd命令行,进入php根目录,
在D:\php\下执行 phpservice.exe install,即可生成windows服务,卸载命令:phpservice.exe uninstall

你可能感兴趣的:(将nginx、php-cgi注册为windows服务,开机自启动)