公司最近有一个需求,需要在同一服务器安装php不同版本,我使用的方式是systemctl的管理方式。
为了减少systemctl的数量,使用的方法是systemctl模板的解决办法!具体方式如下

vim /lib/systemd/system/[email protected]

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
Before=nginx.service

[Service]
Type=forking
#Type=notify
PIDFile=/run/%i.pid
ExecStart=/usr/local/%i/sbin/php-fpm --fpm-config /etc/%i.conf 
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

上面的定义好后执行下面命令加载配置文件

systemctl daemon-reload

systemctl模板使用方式
需要了解占位符%i的意思,意思就是
%i: This references the instance name, which is the identifier following the @ in the instance unit. This is one of the most commonly used specifiers because it will be guaranteed to be dynamic. The use of this identifier encourages the use of configuration significant identifiers. For example, the port that the service will be run at can be used as the instance identifier and the template can use this specifier to set up the port specification.
中文意思就是@之后的字符,.service之前的字符

比如我启动php5.6的环境。执行下面命令就启动了php5.6但是要确保你的配置文件和安装路径,
这点非常重要不然启动服务会报错

systemctl start [email protected]

启动php7的命令同理

systemctl start [email protected]

需要特别注意配置问题!

PIDFile=/run/%i.pid   # 需要与你的phpxx.fpm的配置文件配置一致

安装路径也一样需要根据情况更改!

/usr/local/%i/sbin/php-fpm --fpm-config /etc/%i.conf 

systemctl模板的基本使用方法就是这样!

Last modification:September 6, 2019
如果觉得我的文章对你有用,请随意赞赏