在Linux系统中,PHP-FPM(FastCGI Process Manager)是一个用于管理PHP FastCGI进程的工具。要编写一个启动脚本,你需要遵循以下步骤:
/etc/init.d/php-fpm
#!/bin/bash
chmod +x /etc/init.d/php-fpm
#!/bin/bash
# PHP-FPM configuration file path
PHPRC="/etc/php-fpm.conf"
# PHP-FPM process manager user and group
PHP_FPM_USER="www-data"
PHP_FPM_GROUP="www-data"
# PHP-FPM pool configuration file path
PHP_POOL_CONF="/etc/php-fpm.d/www.conf"
# Start PHP-FPM
start() {
if [ -f $PHPRC ]; then
# Check if PHP-FPM is already running
if ps aux | grep '[p]hp-fpm: master process' > /dev/null; then
echo "PHP-FPM is already running."
else
# Start PHP-FPM with the specified user and group
start-stop-daemon --start --quiet --user $PHP_FPM_USER --group $PHP_FPM_GROUP --exec /usr/sbin/php-fpm -- --nodaemonize --fpm-config $PHPRC
echo "PHP-FPM started."
fi
else
echo "PHP-FPM configuration file not found: $PHPRC"
fi
}
# Stop PHP-FPM
stop() {
if ps aux | grep '[p]hp-fpm: master process' > /dev/null; then
# Stop PHP-FPM
start-stop-daemon --stop --quiet --exec /usr/sbin/php-fpm
echo "PHP-FPM stopped."
else
echo "PHP-FPM is not running."
fi
}
# Restart PHP-FPM
restart() {
stop
start
}
# Check PHP-FPM status
status() {
if ps aux | grep '[p]hp-fpm: master process' > /dev/null; then
echo "PHP-FPM is running."
else
echo "PHP-FPM is not running."
fi
}
# Parse command line arguments
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
根据你的系统和PHP-FPM安装路径,修改脚本中的配置文件路径、用户和组。
将脚本添加到系统服务:
chkconfig --add php-fpm
service php-fpm start
现在你已经创建了一个基本的PHP-FPM启动脚本。你可以使用service php-fpm start
、service php-fpm stop
、service php-fpm restart
和service php-fpm status
命令来控制PHP-FPM服务。