Transferred from: http://www.jb51.net/article/58796.htm
Both Nginx and PHP on the server are compiled and installed by source code, and do not have a service startup script like Ubuntu, so it is not supported like the previous nginx (Start|restart|stop|reload). Get your hands on your own. The following script should be available under Rhel, Fedora, and CentOS.
First, Nginx startup script/etc/init.d/nginx
Copy the Code code as follows:
#!/bin/bash
#
# Startup script for Nginx-this script starts and stops the Nginx daemon
#
# Chkconfig:-85 15
# Description:nginx is an HTTP (s) server, HTTP (s) reverse proxy and IMAP/POP3 proxy server
# Processname:nginx
# config:/usr/local/nginx/conf/nginx.conf
# Pidfile:/usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source Networking configuration.
. /etc/sysconfig/network
# Check that networking are up.
["$NETWORKING" = "no"] && exit 0
nginx= "/usr/local/nginx/sbin/nginx"
prog=$ (basename $nginx)
Nginx_c/usr/local/nginx/conf/nginx.conf "
[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx
Lockfile=/var/lock/subsys/nginx
Start () {
[-X $nginx] | | Exit 5
[-F $NGINX _conf_file] | | Exit 6
Echo-n $ "Starting $prog:"
Daemon $nginx-C $NGINX _conf_file
Retval=$?
Echo
[$retval-eq 0] && Touch $lockfile
Return $retval
}
Stop () {
Echo-n $ "Stopping $prog:"
Killproc $prog-quit
Retval=$?
Echo
[$retval-eq 0] && rm-f $lockfile
Return $retval
}
Restart () {
Configtest | | Return $?
Stop
Sleep 1
Start
}
Reload () {
Configtest | | Return $?
Echo-n $ "Reloading $prog:"
Killproc $nginx-hup
Retval=$?
Echo
}
Force_reload () {
Restart
}
Configtest () {
$nginx-T-C $NGINX _conf_file
}
Rh_status () {
Status $prog
}
Rh_status_q () {
Rh_status >/dev/null 2>&1
}
Case "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart|configtest)
$
;;
Reload
Rh_status_q | | Exit 7
$
;;
Force-reload)
Force_reload
;;
Status
Rh_status
;;
Condrestart|try-restart)
Rh_status_q | | Exit 0
;;
*)
echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
Exit 2
Esac
save after editing, execute the following command
Copy the Code code as follows:
sudo chmod +x/etc/init.d/nginx
Sudo/sbin/chkconfig Nginx on
# Check it out.
Sudo/sbin/chkconfig--list Nginx
Nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
done! You can use the following command to manage Nginx.
Copy the Code code as follows:
Service Nginx Start
Service Nginx Stop
Service Nginx Restart
Service Nginx Reload
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx Reload
Second, php-fpm startup script/etc/init.d/php-fpm
Copy the Code code as follows:
#!/bin/bash
#
# Startup script for the PHP-FPM server.
#
# chkconfig:345 85 15
# description:php is an html-embedded scripting language
# PROCESSNAME:PHP-FPM
# config:/usr/local/php/etc/php.ini
# Source function library.
. /etc/rc.d/init.d/functions
Php_path=/usr/local
desc= "PHP-FPM Daemon"
name=php-fpm
# PHP-FPM Path
daemon= $PHP _path/php/sbin/$NAME
# Configuration file path
C/php/etc/php-fpm.conf
# PID file path (in php-fpm.conf settings)
pidfile= $PHP _path/php/var/run/$NAME. pid
Scriptname=/etc/init.d/$NAME
# Gracefully Exit If the package has been removed.
Test-x $DAEMON | | Exit 0
Rh_start () {
$DAEMON-y $CONFIGFILE | | Echo-n "Already Running"
}
Rh_stop () {
Kill-quit ' Cat $PIDFILE ' | | Echo-n "Not Running"
}
Rh_reload () {
Kill-hup ' Cat $PIDFILE ' | | Echo-n "can ' t reload"
}
Case "$" in
Start
Echo-n "Starting $DESC: $NAME"
Rh_start
echo "."
;;
Stop
Echo-n "Stopping $DESC: $NAME"
Rh_stop
echo "."
;;
Reload
Echo-n "Reloading $DESC configuration ..."
Rh_reload
echo "Reloaded."
;;
Restart
Echo-n "Restarting $DESC: $NAME"
Rh_stop
Sleep 1
Rh_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
Exit 3
;;
Esac
Exit 0
save after editing, execute the following command
Copy the Code code as follows:
sudo chmod +x/etc/init.d/php-fpm
Sudo/sbin/chkconfig PHP-FPM on
# Check it out.
Sudo/sbin/chkconfig--list PHP-FPM
PHP-FPM 0:off 1:off 2:on 3:on 4:on 5:on 6:off
done! You can use the following command to manage PHP-FPM.
Copy the Code code as follows:
Service PHP-FPM Start
Service PHP-FPM Stop
Service PHP-FPM Restart
Service PHP-FPM Reload
/ETC/INIT.D/PHP-FPM start
/ETC/INIT.D/PHP-FPM stop
/ETC/INIT.D/PHP-FPM restart
/ETC/INIT.D/PHP-FPM Reload
The above describes the Nginx and PHP-FPM start, restart, stop script, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.