NGINX + PHP + MySQL + Memcache 一键启动脚本(.bat + shell)

NGINX + PHP + MySQL + Memcache 一键启动脚本(.bat + shell)

Chris Yue No Comment
Posts

在开发的时候,往往需要单独开启 NGINX PHP MySQL Memcache等环境。我写了一个一键启动脚本方便使用。

假设 NGINX, PHP, MySQL, Memcache 在同一个目录 services 下面并且他们各自在单独的以他们的名字命名的目录,脚本位于 services 目录:

启动脚本

:: run.bat (for windows) 
@echo off

start /B /D nginx nginx.exe
echo nginx is running..

start /B /D mysql\bin mysqld.exe
echo mysqld is running..

start /B /D memcached memcached.exe
echo memcached is running..

:: 如果 PHP 使用了 memcached 做 session.save_handler
:: PHP 必须在 memcached 后面运行
start /B /D php php-cgi.exe -b 9000
:: 如果你想用更多的 php-cgi 进程可以在此继续添加
start /B /D php php-cgi.exe -b 9001
echo php-cgi is running..

关闭脚本

:: quit.bat (for windows) 
@echo off

echo killing nginx..
cd nginx
nginx.exe -s stop

echo killing mysqld..
cd ..\mysql\bin
::这里假设 mysql 用户 root 无密码
mysqladmin -u root shutdown

echo killing php-cgi..
taskkill /F /IM php-cgi.exe

echo killing memcached..
taskkill /F /IM memcached.exe

echo bye
cd ..\..

开启脚本(bash)

#!/bin/bash
# run (for cygwin) 开启脚本
./nginx &

cd ../mysql/bin
./mysqld &

cd ../../memcached
./memcached &

cd ../php
./php-cgi -b 9000 &
./php-cgi -b 9001 &

关闭脚本

#!/bin/bash
# quit (for cygwin)
cd nginx
./nginx -s stop

cd ../mysql/bin
./mysqladmin -u root shutdown

ps | grep memcache | awk '{print $1}' | xargs kill
ps | grep php-cgi | awk '{print $1}' | xargs kill</pre>

NGINX + PHP + MySQL + Memcache 一键启动脚本(.bat + shell) by Chris Yue is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

微信赞赏码

写作累,服务器还越来越贵
求分担,祝愿好人一生平安
天使打赏人

发表评论

4 + 2 =