一,下载php7.4
1,官方网站:
https://www.php.net/
2,下载
[[email protected] source]# wget https://www.php.net/distributions/php-7.4.2.tar.gz
说明:在linux上以编译方式安装软件时,多数人都习惯把软件安装到 /usr/local目录下,
我们在生产环境中的习惯使用两个目录:
/usr/local/source 保存源码/rpm安装包
/usr/local/soft 保存安装的软件
之所以这样区分,是为了把当时下载的源码或安装包也保存一份,
一来以后用到时能了解到当时的版本
二来如果需要重新编译时也无需去各软件的官网上去找历史版本
说明:架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: [email protected]
二,查看本地的centos的版本
[[email protected] lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)
三,解压和配置
1,解压命令和configure命令
[[email protected] source]# tar -zxvf php-7.4.2.tar.gz [[email protected] source]# cd php-7.4.2/ [[email protected] php-7.4.2]# ./configure --prefix=/usr/local/soft/php7 --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-iconv-dir=/usr/local --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --with-zip --with-config-file-path=/usr/local/soft/php7/etc -with-bz2 --enable-inline-optimization --enable-sysvsem
说明:上面的configure命令的参数是php-7.4.2可用的参数,
一些旧的不可用的参数会在configure时给出提示,
大家不要使用已经废弃的参数,避免安装完成后不能正常使用
2,安装命令:
[[email protected] php-7.4.2]# make && make install
四,配置过程中遇到各种报错信息的处理
1,报错:Package ‘libxml-2.0‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install libxml2-devel
2,报错:Package ‘krb5‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install krb5-devel
3,报错:Package ‘openssl‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install openssl-devel
4,报错:Package ‘sqlite3‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install sqlite-devel
5,报错:Package ‘libcurl‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install libcurl-devel
6,报错:Package ‘oniguruma‘, required by ‘virtual:world‘, not found
解决:
参见:CentOS 8 安装 oniguruma 和 oniguruma-devel 一文地址:https://www.cnblogs.com/architectforest/p/12433640.html
7,报错:Package ‘libxslt‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install libxslt-devel
8,报错:Package ‘libjpeg‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install libjpeg-devel
9,报错:Package ‘libzip‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install libzip-devel
10,报错:configure: error: Please reinstall the BZip2 distribution
解决:
[[email protected] php-7.4.2]# yum -y install bzip2-devel
11,报错:Package ‘libpng‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install libpng-devel
12,报错:Package ‘freetype2‘, required by ‘virtual:world‘, not found
解决:
[[email protected] php-7.4.2]# yum install freetype-devel
五,生成php配置文件
[[email protected] php-7.4.2]# cp php.ini-production /usr/local/soft/php7/etc/php.ini
六,生成www配置文件
[[email protected] etc]# cd /usr/local/soft/php7/etc/php-fpm.d/ [[email protected] php-fpm.d]# cp www.conf.default www.conf
七,生成php-fpm配置文件
[[email protected] etc]# cd /usr/local/soft/php7/etc [[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
八,生成php-fpm服务启动文件
[[email protected] etc]# mkdir /usr/local/soft/php7/daemon [[email protected] etc]# cp /usr/local/source/php-7.4.2/sapi/fpm/init.d.php-fpm /usr/local/soft/php7/daemon/php-fpm [[email protected] etc]# chmod 740 /usr/local/soft/php7/daemon/php-fpm
九,测试启动php-fpm
[[email protected] etc]# /usr/local/soft/php7/daemon/php-fpm start Starting php-fpm done [[email protected] etc]# ps auxfww | grep php | grep -v grep root 30476 0.0 0.0 141260 10948 ? Ss 11:40 0:00 php-fpm: master process (/usr/local/soft/php7/etc/php-fpm.conf) nobody 30477 0.0 0.0 167012 10404 ? S 11:40 0:00 \_ php-fpm: pool www nobody 30478 0.0 0.0 167012 10404 ? S 11:40 0:00 \_ php-fpm: pool www
十,如何查看当前已安装的php的版本?
[[email protected] etc]# /usr/local/soft/php7/bin/php -v PHP 7.4.2 (cli) (built: Mar 5 2020 11:16:38) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies
十一,查看本地centos的版本
[[email protected] ~]$ cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)
原文地址:https://www.cnblogs.com/architectforest/p/12433541.html