我正在尝试在 Windows 10 上创建一个 bat 文件以在后台启动 nginx 和 php-fpm。目前我可以这样做,但命令窗口(黑色窗口)保持打开状态。如果我关闭窗口,php-fpm 也会终止。
这是我在 start.bat 中添加的内容
@ECHO OFF
cd D:\servers\nginx-1.10.1\
echo Starting Nginx...
start /B cmd /K "D:\servers\nginx-1.10.1\nginx.exe"
echo Start Php-cgi...
start /B cmd /K "D:\servers\php-5.6.26\php-cgi.exe -b 127.0.0.1:9000 -c D:\servers\php-5.6.26\php.ini"
EXIT
这是黑色窗户上印刷的内容:
Starting Nginx...
Start Php-cgi...
我希望窗口自动关闭,但保持进程(nginx 和 php-fpm)运行。
答案1
php-cgi 锁定了窗口。请尝试 nginx 人员在其页面上提供的解决方案。 Windows 上的 PHP-FastCGI
答案2
隐藏控制台窗口是解决此问题的方法之一。使用 CLI 实用程序可以轻松实现此目的,例如希德康。对于我的项目,我使用这个脚本:启动服务器.cmd
@Echo Off
:: Portable nginx+php5+mysql for Windows
:: Inquisitor, 2016-2018
CD /D "%~dp0"
:: Settings
Set LogFile=.\%~n0.log
Set TimestampFormat=[%%Date%% %%Time:~,8%%]
Set WatcherTimeout=10
If "%~1"=="" (
Start "" "%~dp0tools\hidcon" %~nx0 restart_hidden
Call Echo.>>"%LogFile%"
Call :Log Loader started
Exit
)
Set Path=%~dp0tools;%~dp0nginx;%~dp0php-fpm;%~dp0mysql\bin;%Path%
:: ImageMagick 6.9.3-3
rem Set Path=%Path%;%~dp0modules\imagick6
:: ImageMagick 7.0.5.10
rem Set Path=%Path%;%~dp0modules\imagick7
:: FFMpeg 3.3.1
Set Path=%Path%;%~dp0modules\ffmpeg
Set Temp=%~dp0\tmp
:: MySQL
Call :Log Starting MySQL...
:start-mysql
PushD .\mysql\bin
Start mysqld --defaults-file=my.ini --standalone
PopD
If "%1"=="restart" (
Call :Log MySQL crashed, restarting
Exit /B
)
:: PHP
Call :Log Starting PHP-FPM...
:start-php
PushD .\php-fpm
Start hidcon php-cgi -b 127.0.0.1:9123 -c ".\php.ini"
PopD
If "%1"=="restart" (
Call :Log PHP-FPM crashed, restarting
Exit /B
)
:: nginx
Call :Log Starting NginX...
:start-nginx
PushD .\nginx
Start nginx
PopD
If "%1"=="restart" (
Call :Log NginX crashed, restarting
Exit /B
)
TaskKill /F /IM "hidcon.exe"
For %%A In ("mysqld.exe", "php-cgi.exe", "nginx.exe") Do (
wmic process where name="%%~A" CALL setpriority "high priority"
)
Set LockFile=.\.%~n0.lock
Echo.>"%LockFile%"
:Watcher
Ping -n %WatcherTimeout% 127.0.0.1>nul 2>nul
TaskList /FI "imagename EQ php-cgi.exe" /FO:CSV|FindStr /I /C:"php-cgi.exe">nul||Call :start-php restart
If Not Exist "%LockFile%" (
Call :Log Lockfile not found, starting shutdown process
PushD .\nginx
nginx -s stop
PopD
mysqladmin -u root -pPCIIctvYUijcfNLR shutdown
TaskKill /F /T /IM php-cgi.exe
Call :Log Loader stopped
Exit
)
GoTo :Watcher
:Log
Call Echo %TimestampFormat% %*>>"%LogFile%"
Exit /B
简单停止服务器.cmd:
@Echo Off
Del "%~dp0.loader.lock" 2>nul
答案3
RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9001