CentOS8安装PHP7.3


一、依赖包安装

1、gcc

yum install gcc gcc-c++ ncurses-devel perl
yum -y install openssl openssl-devel

2、安装cmake

注:cmake版本要大于3.0,如果已经安装了低版本cmake,先卸载

rpm -qa | grep cmake
cmake -version yum remove
-y cmake
wget https://cmake.org/files/v3.20/cmake-3.20.2.tar.gz
tar -xzvf cmake-3.20.2.tar.gz
cd cmake-3.20.2
./bootstrap; make; make install

3、其它,PHP的安装是最费劲的,每个人的系统不一样,所以只能根据错误提示进行修正。

(1)configure: error: libxml2 not found. Please check your libxml2 installation.

yum install libxml2
yum install libxml2-devel -y

(2)checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support

yum install curl-devel -y

(3)configure: error: jpeglib.h not found.

yum install libjpeg-devel -y
yum install libpng
yum install libpng-devel

 (4)configure: error: freetype-config not found.

yum install freetype-devel

(5)configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum install -y libxslt-devel*

(6)configure: error: Please reinstall the BZip2 distribution

yum install -y  bzip2-devel

 注意:libzip的版本不能太高

wget https://libzip.org/download/libzip-1.2.0.tar.gz

tar -xvzf libzip-1.2.0.tar.gz
cd libzip-1.2.0
mkdir build
cd build/
cmake ..
make
make install

如cmake时遇到错误:zstd library not found; zstandard support disabled

yum install epel-release
yum install libzstd-devel

二、安装PHP7.3

1、软件下载

https://www.php.net/downloads.php

7.3.30版本

2、安装

#编译

./configure --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php7.3/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-openssl --with-pcre-regex --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-openssl --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-mbstring --enable-mysqlnd --with-pdo-mysql=mysqlnd

参数说明:

#指定php安装目录
–prefix=/usr/local/php7.3

#指定php.ini位置
–with-config-file-path=/usr/local/php7.3/etc

#打开curl浏览工具的支持
–with-curl

#打开对freetype字体库的支持
–with-freetype-dir

#打开gd库的支持
–with-gd

#打开gnu 的gettext 支持,编码库用到
–with-gettext

#选项指令 --with-iconv-dir 用于 PHP 编译时指定 iconv 在系统里的路径,否则会扫描默认路径。
–with-iconv-dir

#打开libxml2库的支持
–with-libxml-dir
#object code libraries [EPREFIX/lib]
–with-libdir=lib64

#openssl的支持,加密传输https时用到的
–with-openssl
#OPENSSL: Include Kerberos support
–with-kerberos

#fpm
–enable-fpm

#Include Perl Compatible Regular Expressions support.
–with-pcre-regex

#PDO: MySQL支持
–with-pdo-mysql
–with-pdo-sqlite

#打开pear命令的支持,PHP扩展用的
–with-pear

#打开对png图片的支持
–with-png-dir

#打开对jpeg图片的支持
–with-jpeg-dir

#打开对XMLRPC-EP支持
–with-xmlrpc

#打开对XSL的支持. DIR is the libxslt base install directory (libxslt >= 1.1.0 required)
–with-xsl

#打开对ZLIB的支持 (requires zlib >= 1.2.0.4)
–with-zlib

#打开bc精确数学函数
–enable-bcmath

#打开LIBXML支持
–enable-libxml

#优化线程
–enable-inline-optimization
–enable-mbregex

#多字节,字符串的支持
–enable-mbstring

#开启Zend OPcache支持
–enable-opcache

#freeTDS需要用到的,可能是链接mssql 才用到
–enable-pcntl

#可以处理相关的IPC函数
–enable-shmop
–enable-sysvsem

#开启SOAP支持
–enable-soap

#打开 sockets 支持
–enable-sockets
–enable-xml

#打开对zip的支持
–enable-zip

当你看到这个截图,说明编译成功了

#安装

make && make install

#查看php版本

php -v

#显示如下
PHP 7.3.30 (cli) (built: May 19 2022 17:20:22) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.30, Copyright (c) 1998-2018 Zend Technologies

3、配置文件

#拷贝文件

cp /usr/local/php7.3/etc/php-fpm.conf.default /usr/local/php7.3/etc/php-fpm.conf
cp /usr/local/php7.3/etc/php-fpm.d/www.conf.default /usr/local/php7.3/etc/php-fpm.d/www.conf
cp php.ini-development /usr/local/php7.3/etc/php.ini

#新增用户组和用户

groupadd www
useradd -g www www

#配置 www.conf

cd /usr/local/php/etc/php-fpm.d
vim www.conf

具体内容

[www]

listen = 127.0.0.1:9080
listen.mode = 0666

user = www
group = www

pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000

rlimit_files = 1024
slowlog = log/$pool.log.slow

4、配置fpm命令

cd php-7.3.30/sapi/fpm
cp init.d.php-fpm /etc/init.d/php-fpm

#增加权限
chmod +x /etc/init.d/php-fpm

5、添加环境变量

vim /etc/profile

#在文件底部加入
#PHP7.3
export PATH=$PATH:/usr/local/php7.3/bin

#保存,使环境变量生效
source  /etc/profile

6、fpm命令

service php-fpm reload
service php-fpm start
service php-fpm stop

7、查看进程状态

service php-fpm status

结果:php-fpm (pid 1072864) is running...

相关