php:用systemctl管理php-fpm服务(PHP 8.2.5)
一,生成启动文件:
复制源码中的init.d.php-fpm作为启动文件
[root@img sapi]# mkdir /usr/local/soft/php8.2.5/daemon
[root@img sapi]# cd /usr/local/source/php/php-8.2.5/
[root@img php-8.2.5]# cp sapi/fpm/init.d.php-fpm /usr/local/soft/php8.2.5/daemon/php-fpm
[root@img php-8.2.5]# chmod 740 /usr/local/soft/php8.2.5/daemon/php-fpm
说明:可以直接使用这个程序启动和停止php-fpm,例如:
启动
[root@img php-8.2.5]# /usr/local/soft/php8.2.5/daemon/php-fpm start
Starting php-fpm done
停止
[root@img php-8.2.5]# /usr/local/soft/php8.2.5/daemon/php-fpm stop
Gracefully shutting down php-fpm . done
二,用systemctl管理php-fpm服务:第一种方法:自定义service文件
编辑配置文件
[root@img php-8.2.5]# vi /usr/lib/systemd/system/php-fpm.service
内容:
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/soft/php8.2.5/daemon/php-fpm start
ExecStop=/usr/local/soft/php8.2.5/daemon/php-fpm stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载service文件
[root@img php-8.2.5]# systemctl daemon-reload
启动服务
[root@img php-8.2.5]# systemctl start php-fpm.service
停止服务
[root@img php-8.2.5]# systemctl stop php-fpm.service
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/06/php-yong-systemctl-guan-li-phpfpm-fu-wu-php-8-2-5/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
三,用systemctl管理php-fpm服务:第二种方法:用源码中的service文件:
从源码中复制
root@lhdpc:/usr/local/source/php8/php-8.2.5/sapi/fpm# cp php-fpm.service /etc/systemd/system/
重新加载servcie文件:
root@lhdpc:/usr/local/source/php8/php-8.2.5/sapi/fpm# systemctl daemon-reload
启动:
[root@img php-8.2.5]# systemctl start php-fpm.service
说明:请先在php-fpm.conf中指定日志路径,
否则会报错:
[root@img fpm]# systemctl status php-fpm.service
× php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (;;file://img/usr/lib/systemd/system/php-fpm.service/usr/lib/systemd/system/php-fpm.service;;; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2023-05-11 14:21:53 CST; 18s ago
Duration: 57ms
Process: 353560 ExecStart=/usr/local/soft/php8.2.5/sbin/php-fpm --nodaemonize --fpm-config /usr/local/soft/php8.2.5/etc/php-fpm.conf (code=exited, status=78)
Main PID: 353560 (code=exited, status=78)
CPU: 56ms
May 11 14:21:53 img systemd[1]: Started The PHP FastCGI Process Manager.
May 11 14:21:53 img php-fpm[353560]: [11-May-2023 14:21:53] ERROR: failed to open error_log (/usr/local/soft/php8.2.5/var/log/php-fpm.log): Read-only file system (30)
May 11 14:21:53 img php-fpm[353560]: [11-May-2023 14:21:53] ERROR: failed to post process the configuration
May 11 14:21:53 img php-fpm[353560]: [11-May-2023 14:21:53] ERROR: FPM initialization failed
May 11 14:21:53 img systemd[1]: php-fpm.service: Main process exited, code=exited, status=78/CONFIG
May 11 14:21:53 img systemd[1]: php-fpm.service: Failed with result 'exit-code'.
设置例如:
;error_log = log/php-fpm.log
error_log = /web/logs/phplogs/php-fpm.log
四,查看php的版本:
[root@img daemon]# /usr/local/soft/php8.2.5/bin/php --version
PHP 8.2.5 (cli) (built: May 10 2023 14:51:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies