一、Linux系统中服务启动方式
- 启动php为例,常见的启动方式为/etc/init.d/php-fpm start,linux系统中/etc/init.d/包含很多服务的启动和停止脚本,上述方式为调用脚本启动
- 用systemd来启动:systemctl start php-fpm,systemd 取代了initd,成为系统的第一个进程(PID
等于 1),其他进程都是它的子进程。
二、设置php启动方式
01_脚本启动
- 复制启动脚本到/etc.init.d,并添加执行权限。

- 复制php-fpm服务的配置文件模板,创建新的配置文件并根据需求做相应修改
 vim /usr/local/php/etc/php-fpm.conf
打开global中下面一行的注释:
pid=run/php-fpm.pid %指定pid的存放目录

02_systemd启动
- 复制脚本到/usr/lib/systemd/system
 - 编辑配置文件
vim /usr/lib/systemd/system/php-fpm.service
注释

- 查看服务 ps -aux  netstat -antlp 
三、设置Nginx启动方式
编辑主配置文件 vim /usr/local/nginx/conf/nginx.conf 
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
 
- 编辑配置文件
vim /usr/lib/systemd/system/nginx.service systemd 默认从目录/etc/systemd/system/读取配置文件。但是,里面存放的大部分文件都是符号链接,指向目录/usr/lib/systemd/system/,真正的配置文件存放在/usr/lib/systemd/system/目录。 systemctl enable 命令用于在上面两个目录之间,建立符号链接关系。
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- ststemd启动nginx

四、nginx与php结合测试
- 编辑nginx默认发布目录中的php测试页
vim /usr/local/nginx/html/index.php
<?php
phpinfo()
?>

- 编辑php的配置文件做访问测试
vim /usr/local/php/etc/php.ini  - 重载php服务
systemctl reload php-fpm.service - 再次访问172.25.2.1

|