本文主要是介绍LNMP 之 PHP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载 PHP最新稳定版本
[root@localhost software]# wget https://www.php.net/distributions/php-7.3.11.tar.gz
--2019-11-09 18:34:50-- https://www.php.net/distributions/php-7.3.11.tar.gz
正在解析主机 www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
正在连接 www.php.net (www.php.net)|185.85.0.29|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [application/x-gzip]
正在保存至: “php-7.3.11.tar.gz”[ <=> ] 19,606,654 66.4KB/s 用时 4m 4s
2019-11-09 18:38:55 (78.4 KB/s) - “php-7.3.11.tar.gz” 已保存 [19606654][root@localhost software]#
验证校验码(sha256):
[root@localhost software]# sha256sum php-7.3.11.tar.gz
8f385f5bdf9193791f6c0f6303f518f3c324b6655ac108fdb3c426da7f3cf4d4 php-7.3.11.tar.gz
[root@localhost software]#
解压后进行编译检测:
[root@localhost software]# tar -zxf php-7.3.11.tar.gz
[root@localhost software]#
[root@localhost software]# yum install -y libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel autoconf
[root@localhost software]# cd php-7.3.11
[root@localhost php-7.3.11]# ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/tmp/mysql.sock --with-freetype-dir --with-jpeg-dir --with-mhash --with-openssl --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=www --with-fpm-group=www
.
.
.
checking for libzip... not found
configure: error: Please reinstall the libzip distribution
[root@localhost php-7.3.11]#
[root@localhost php-7.3.11]# yum reinstall libzip
已加载插件:fastestmirror
参数 libzip 没有匹配
Loading mirror speeds from cached hostfile* centos-sclo-rh: mirrors.huaweicloud.com* centos-sclo-sclo: mirrors.huaweicloud.com
软件包 libzip 可用,但尚未安装。
错误:无须任何处理
[root@localhost php-7.3.11]#
yum 安装 libzip 提示未找到,所以直接进行源码安装
[root@localhost php-7.3.11]#
[root@localhost php-7.3.11]# cd ../
[root@localhost software]#
[root@localhost software]# wget https://libzip.org/download/libzip-1.5.2.tar.gz
--2019-11-11 22:36:12-- https://libzip.org/download/libzip-1.5.2.tar.gz
正在解析主机 libzip.org (libzip.org)... 5.2.73.210, 2a04:52c0:101:2e6::de6c
正在连接 libzip.org (libzip.org)|5.2.73.210|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1203524 (1.1M) [application/x-gzip]
正在保存至: “libzip-1.5.2.tar.gz”100%[======================================================================================>] 1,203,524 4.89KB/s 用时 3m 48s2019-11-11 22:40:04 (5.15 KB/s) - 已保存 “libzip-1.5.2.tar.gz” [1203524/1203524])[root@localhost software]#
[root@localhost software]#
[root@localhost software]# tar -zxf libzip-1.5.2.tar.gz
[root@localhost software]#
[root@localhost software]# cd libzip-1.5.2
[root@localhost libzip-1.5.2]# mkdir build
[root@localhost libzip-1.5.2]# cd build/
[root@localhost build]#
[root@localhost build]# cmake ..
[root@localhost build]#
[root@localhost build]# make && make install
[root@localhost build]#
重新进行编译检测
[root@localhost build]# cd ../../php-7.3.11
[root@localhost php-7.3.11]#
[root@localhost php-7.3.11]# ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/tmp/mysql.sock --with-mcrypt=/usr/include --with-freetype-dir --with-jpeg-dir --with-mhash --with-openssl --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=www --with-fpm-group=www
.
.
.
checking size of off_t... 0
configure: error: off_t undefined; check your library configuration
[root@localhost php-7.3.11]#
[root@localhost php-7.3.11]#
[root@localhost php-7.3.11]# vi /etc/ld.so.conf
# 添加以下四行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
[root@localhost php-7.3.11]# ldconfig -v
ldconfig -v 使配置生效
再次编译检测:
[root@localhost php-7.3.11]# ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/tmp/mysql.sock --with-mcrypt=/usr/include --with-freetype-dir --with-jpeg-dir --with-mhash --with-openssl --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=www --with-fpm-group=www[root@localhost php-7.3.11]#
检测通过,进行编译安装:
[root@vlocalhost php-7.3.11]# make && make install
复制PHP的配置文件 php.ini-production 到 /usr/local/php/etc 目录
[root@localhost php-7.3.11]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-7.3.11]#
复制 php-fpm.conf 配置文件
[root@localhost php-7.3.11]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.3.11]#
复制 www.conf 配置文件
[root@localhost php-7.3.11]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost php-7.3.11]#
php-fpm.conf 是 php-fpm(PHP FastCGI) 的配置文件
php-fpm 启动后,会先读取 php.ini,然后再读取相应的 conf 配置文件,conf 配置可以覆盖 php.ini 的配置
启动 php-fpm 后,创建一个 master 进程,监听9000端口,master 进程再根据 php-fpm.d 下的 www.conf 去创建若干子进程,子进程用于处理实际业务
有PHP请求时,nginx 向后转发给9000端口,空闲的子进程进行处理,如果此时所有的子进程都处于忙碌状态,新的请求就会被 master 放进队列中,等待php-fpm 的子进程空闲时进行处理
将生成的启动文件复制到 /lib/systemd/system/
目录下
[root@localhost php-7.3.11]# cp sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service
[root@localhost php-7.3.11]#
使用 systemctl status|start|stop|restart php-fpm
进行管理
[root@localhost php-7.3.11]# systemctl start php-fpm
[root@localhost php-7.3.11]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process ManagerLoaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)Active: active (running) since 一 2019-11-11 23:36:02 CST; 2s agoMain PID: 14110 (php-fpm)CGroup: /system.slice/php-fpm.service├─14110 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)├─14111 php-fpm: pool www└─14112 php-fpm: pool www11月 11 23:36:02 localhost systemd[1]: Started The PHP FastCGI Process Manager.
[root@localhost php-7.3.11]#
[root@localhost php-7.3.11]#
最后将 PHP 服务加入开机自启动
[root@localhost php-7.3.11]# systemctl enable php-fpm
这篇关于LNMP 之 PHP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!