联系QQ 284710375
首页 > 技术分享 > LNMP|WAMP
收藏

CentOS7将编译安装的php添加到systemctl2018-08-15 11:14:57

大潇博客 原创文章,转载请标明出处

编译安装的php默认不会添加到服务中,所以需要手动添加


假设php安装在/usr/local/php中

在/usr/lib/systemd/system/目录下生成php-fpm.service文件

vi /usr/lib/systemd/system/php-fpm.service


修改php-fpm.service文件

[Unit]

Description=The PHP FastCGI Process Manager

After=syslog.target network.target


[Service]

Type=simple

PIDFile=/run/php-fpm.pid

ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf

ExecReload=/bin/kill -USR2 $MAINPID

ExecStop=/bin/kill -SIGINT $MAINPID


[Install]

WantedBy=multi-user.target


赋予754权限

chmod 754 /usr/lib/systemd/system/php-fpm.service


执行如下命令生效 

systemctl daemon-reload


现在systemctl可以使用php了

/bin/systemctl start php-fpm.service        启动

/bin/systemctl reload php-fpm.service     重载

/bin/systemctl stop php-fpm.service        停止


若发生报错,可执行systemctl status php-fpm.service查看报错原因,排查。

可重启系统后再用systemctl使用php


添加到开机启动

systemctl enable php-fpm.service


systemctl指令

systemctl enable *.service #开机运行服务

systemctl disable *.service #取消开机运行

systemctl start *.service #启动服务

systemctl stop *.service #停止服务

systemctl restart *.service #重启服务

systemctl reload *.service #重新加载服务配置文件

systemctl status *.service #查询服务运行状态

systemctl --failed #显示启动失败的服务


修改 php.ini 文件 设置 expose_php = Off

vim /usr/local/php7/etc/php.ini

找到 expose_php = On

改为 expose_php = Off

这样在浏览器的header信息中就不会看到PHP的版本信息,防止有人恶意攻击

1.png

打赏

阅读排行

大家都在搜

博客维护不易,感谢你的肯定
扫码打赏,建议金额1-10元
  • 15601023311