分享知识 传递快乐
以下是本人搭建PHP运行环境,用于启动 Ngin + PHP +MariaDB 服务所用,仅供参考。
如有需要了解更多bat命令,请点击查看《BAT命令常用API》。
代码如下:
@ECHO OFF
TITLE WNMP管理程序
COLOR 0A
set WNMP_HOME=D:/WnmpServer/wnmp/bin
::nginx 所在目录
set NGINX_HOME=%WNMP_HOME%/nginx/1.16.1
::php 所在目录
set PHP_HOME=%WNMP_HOME%/php/5.5.12
::set PHP_HOME=%WNMP_HOME%/php/7.2.25
::mariadb 所在目录
set MARIADB_HOME=%WNMP_HOME%/mariadb/10.4.10/bin
::验证文件是否存在
if not exist "%WNMP_HOME%/RunHiddenConsole.exe" (
echo 缺少WNMP运行必要文件!
pause
exit
)
echo ****** WNMP管理程序 ******
echo.
:MENU
:: 判断程序是否存在
ECHO *******************************************************************
ECHO *
ECHO * Wnmp程序管理
ECHO *
ECHO *******************************************************************
echo.
echo. [1] 启动Wnmp
echo. [2] 关闭Wnmp
echo. [3] 重启Wnmp
echo. [4] 查看进程
echo. [5] 查看版本
echo. [6] 刷新
echo. [0] 退出
echo.
echo.请输入选择的序号:
set /p ID=
if "%id%"=="1" goto start
if "%id%"=="2" goto stop
if "%id%"=="3" goto restart
if "%id%"=="4" goto process
if "%id%"=="5" goto version
if "%id%"=="6" goto refresh
if "%id%"=="0" exit
PAUSE
::*************************************************************************************
::
:: 创建执行服务
::
::*************************************************************************************
::
::启动
:start
call :StartNginx
call :StartPHP
call :StartMariaDB
call :ShowLine
goto MENU
::停止
:stop
call :StopNginx
call :StopPHP
call :StopMariaDB
call :ShowLine
goto MENU
::重启
:restart
call :StopNginx
call :StopPHP
call :StopMariaDB
call :StartNginx
call :StartPHP
call :StartMariaDB
call :ShowLine
goto MENU
::查看版本
:version
call :NginxVer
call :PHPVer
call :MariaDBVer
call :ShowLine
goto MENU
::查看进程
:process
call :NginxProcess
call :PHPProcess
call :MariaDBProcess
call :ShowLine
goto MENU
::刷新
:refresh
echo.
cls
goto MENU
::*************************************************************************************
::
:: 创建执行过程
::
::*************************************************************************************
::*************************************************************************************
::
:: nginx
::
::*************************************************************************************
::
:StartNginx
echo.
::tasklist查找所有进程列表,让find找出nginx.exe进程
tasklist|find /i "nginx.exe">nul
::errorlevel:0成功,1失败
::echo nginx启动状态:%errorlevel%
::errorlevel==1找不到进程(说明程序未启动,则开始启动程序)
if %errorlevel% EQU 1 (
::判断文件是否存在,存在则执行,否则就提示找不到路径
if exist "%NGINX_HOME%/nginx.exe" (
%WNMP_HOME%/RunHiddenConsole %NGINX_HOME%/nginx.exe -p %NGINX_HOME%>nul
::启动完成后,验证启动状态(查看线程)
tasklist|find /i "nginx.exe"
echo nginx start successfully!
) else (
echo unknown Nginx path!
)
) else (
echo nginx service is running!
)
goto :eof
:StopNginx
echo.
::tasklist查找所有进程列表,让find找出nginx.exe进程
tasklist|find /i "nginx.exe">nul
::errorlevel:0成功,1失败
::echo nginx关闭状态:%errorlevel%
::errorlevel==0已找到进程(说明程序已启动,则结束程序)
if %errorlevel% EQU 0 (
taskkill /F /IM nginx.exe>nul
::关闭完成后验证关闭状态(查看线程)
tasklist|find /i "nginx.exe"
echo nginx stop successfully!
) else (
echo nginx service is stopped!
)
goto :eof
::显示nginx版本
:NginxVer
echo.
%NGINX_HOME%/nginx -v
goto :eof
::
:NginxProcess
echo.
tasklist|find /i "nginx.exe"
goto :eof
::*************************************************************************************
::
:: PHP
::
::*************************************************************************************
::
:StartPHP
tasklist|find /i "php-cgi.exe">nul
if %errorlevel% EQU 1 (
if exist "%PHP_HOME%/php-cgi.exe" (
%WNMP_HOME%/RunHiddenConsole %PHP_HOME%/php-cgi.exe -b 127.0.0.1:9000 -c %PHP_HOME%/php.ini>nul
tasklist|find /i "php-cgi.exe"
echo php start successfully!
) else (
echo unknown PHP path!
)
) else (
echo php service is running!
)
goto :eof
::
:StopPHP
tasklist|find /i "php-cgi.exe">nul
if %errorlevel% EQU 0 (
taskkill /F /IM php-cgi.exe > nul
tasklist|find /i "php-cgi.exe"
echo php stop successfully!
) else (
echo php service is stopped!
)
goto :eof
::
:PHPVer
echo.
%PHP_HOME%/php-cgi -v
goto :eof
::
:PHPProcess
echo.
tasklist|find /i "php-cgi.exe"
goto :eof
::*************************************************************************************
::
:: MariaDB
::
::*************************************************************************************
::
:StartMariaDB
tasklist|find /i "mysqld.exe">nul
if %errorlevel% EQU 1 (
if exist "%MARIADB_HOME%/mysqld.exe" (
%WNMP_HOME%/RunHiddenConsole %MARIADB_HOME%/mysqld.exe --defaults-file=%WNMP_HOME%/mariadb/database/my.ini --standalone>nul
tasklist|find /i "mysqld.exe"
echo mariadb start successfully!
) else (
echo unknown MariaDB path!
)
) else (
echo mariadb service is running!
)
goto :eof
::
:StopMariaDB
tasklist|find /i "mysqld.exe">nul
if %errorlevel% EQU 0 (
taskkill /F /IM mysqld.exe > nul
tasklist|find /i "mysqld.exe"
echo mariadb stop successfully!
) else (
echo mariadb service is stopped!
)
goto :eof
::
:MariaDBVer
echo.
%MARIADB_HOME%/mysqld -v
goto :eof
::
:MariaDBProcess
echo.
tasklist|find /i "mysqld.exe"
goto :eof
:ShowLine
echo ###################################################################
echo.
echo.
echo.
——————————
如有不足请留言指正
相互学习,共同进步