编译安装Nginx和PHP,安装目录: /application/nginx-1.10.3 和 /application/php-5.6.30
/application/nginx-1.10.3 软连接到 /application/nginx
/application/php-5.6.30 软连接到 /application/php
CentOS 7 启动脚本在/usr/lib/systemd/system/
新建nginx.service,内容如下:
nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking #后台运行
PIDFile=/application/nginx/logs/nginx.pid #PID文件位置
ExecStartPre=/application/nginx/sbin/nginx -t #启动前先干什么,这里是先测试配置文件是否正确
ExecStart=/application/nginx/sbin/nginx #启动命令
ExecReload=/usr/bin/kill -s HUP $MAINPID #重载reload
ExecStop=/usr/bin/kill -s QUIT $MAINPID #停止服务
PrivateTmp=true #为服务分配独立的临时空间
[Install]
WantedBy=multi-user.target
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
新建php-fpm.service,内容如下:
php-fpm.service
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
PIDFile=/application/php/var/php-fpm.pid
ExecStartPre=/application/php/sbin/php-fpm -t -c /application/php/etc/php-fpm.conf
ExecStart=/application/php/sbin/php-fpm
ExecStop=/usr/bin/kill -s QUIT $MAINPID
ExecReload=/usr/bin/kill -s HUP $MAINPID
[Install]
WantedBy=multi-user.target
注意:php-fpm默认是没有pid的,需要修改php-fpm.conf,大概25行左右。