centos7.6从零开始编译nginx+mysql+php(四) 安装PHP
in 云服务器 with 0 comment

centos7.6从零开始编译nginx+mysql+php(四) 安装PHP

in 云服务器 with 0 comment

php镜像地址:http://mirrors.sohu.com/php/php-7.2.8.tar.gz

安装步骤

# 回到软件下载目录
[root@localhost ~]# cd /software/

# 下载php包
[root@localhost ~]# wget http://mirrors.sohu.com/php/php-7.2.8.tar.gz

# 解压
[root@localhost ~]# tar zxvf php-7.2.8.tar.gz
[root@localhost ~]# cd php-7.2.8/

# 安装必要的拓展命令
[root@localhost php-7.2.8]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel

# 配置PHP
[root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip

# 编译PHP
[root@localhost php-7.2.8]# make && make install

# 编辑php.ini的一些设置 也可以通过Wcp之类的工具去改php.ini
[root@localhost php-7.2.8]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.2.8]# grep mysqli.default_socket  /usr/local/php/lib/php.ini
[root@localhost php-7.2.8]# sed -i 's#mysqli.default_socket =#mysqli.default_socket =
[root@localhost php-7.2.8]# grep date.timezone /usr/local/php/lib/php.ini 
[root@localhost php-7.2.8]# sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /usr/local/php/lib/php.ini 

# 复制 php-fpm 的配置文档
[root@localhost php-7.2.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.8]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

# 修改 /usr/local/php/etc/php-fpm.d/www.conf,把启动用户改为和nginx服务同一个启动用户(前面Nginx使用的是www账户,这里改成和Nginx使用一样的账户;一般都是使用www用户)

[root@localhost php-7.2.8]# grep -E 'user =|group =' /usr/local/php/etc/php-fpm.d/www.conf
user = nginx
group = nginx
[root@localhost php-7.2.8]# sed -i 's#user = nginx#user = www#' /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost php-7.1.4]# sed -i 's#group = nginx#group = www#' /usr/local/php/etc/php-fpm.d/www.conf 
[root@localhost php-7.1.4]# grep -E 'user =|group =' /usr/local/php/etc/php-fpm.d/www.conf
user = www
group = www
;listen.group = www

# 其中 www.conf 中要留意这个值 listen = 127.0.0.1:9000
[root@localhost php-7.2.8]# grep 'listen = 127.0.0.1' /usr/local/php/etc/php-fpm.d/www.conf

# 配置 php-fpm 启动服务脚本
[root@localhost php-7.2.8]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

# 查看启动脚本中指定的程序目录和pid文件(默认已经修改过了,如果没有修改过则修改)
[root@localhost php-7.1.4]# grep -E 'PIDFile|ExecStart' /usr/lib/systemd/system/php-fpm.service
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf

# 重新载入 systemd
[root@localhost php-7.2.8]# systemctl daemon-reload

# 设置开机启动
[root@localhost php-7.2.8]# systemctl enable php-fpm

# 重启PHP
[root@localhost php-7.2.8]# systemctl restart php-fpm

# 查看状态
[root@localhost php-7.2.8]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2019-05-07 20:26:25 CST; 35s ago
 Main PID: 7435 (php-fpm)
   CGroup: /system.slice/php-fpm.service
           ├─7435 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
           ├─7437 php-fpm: pool www
           └─7438 php-fpm: pool www

5月 07 20:26:25 centos7 systemd[1]: Started The PHP FastCGI Process Manager.

到此PHP服务安装完成。

参考网站

CentOS 7下编译安装Nginx+MySQL+PHP

Comments are closed.