php8.3.0安装及扩展安装

时间:2024-10-26 22:12:15

php8.3.0安装及扩展安装

部署环境及版本

系统版本:CentOS Linux release 7.9.2009
php版本:8.3.0

部署前准备

1、关闭自带防火墙,安装iptables

# 关闭SELinux
setenforce 0 
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 关闭Firewalld并禁止自启动
systemctl stop firewalld
systemctl disable firewalld

# 安装iptables
yum install -y iptables-services

# 启动iptables服务,并设置开机自启动(修改规则在/etc/sysconfig/iptables)
systemctl start iptables
systemctl enable iptables.service

2、时间同步

yum -y install ntp
systemctl enable ntpd
systemctl start ntpd
timedatectl set-timezone Asia/Shanghai
ntpdate -u time.nist.gov
date

一、安装php8.3.0

1、安装依赖

#安装epel源
yum -y install epel-release
#更新yum源
yum -y update
#安装依赖包
yum install -y gcc gcc-c++ freetype-devel bzip2-devel curl-devel autoconf libxml2-devel libjpeg-devel libpng-devel libxslt-devel libzip-devel libmcrypt mhash wget sqlite-devel oniguruma oniguruma-devel
#安装work用户
useradd work

2、创建安装目录并解压

#创建存放安装包目录
mkdir -pv /server/tools
#下载安装包
cd /server/tools
wget https://www.php.net/distributions/php-8.3.0.tar.gz
#解压安装包
tar xvf php-8.3.0.tar.gz

3、升级openssl

#卸载centos自带1.0.2版本的openssl
yum remove openssl-1.0.2k-26.el7_9.x86_64
#下载新版openssl包 (如果下载不下来,windows下载,上传到服务器)
cd /server/tools
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
#解压缩包
tar xvf openssl-1.1.1i.tar.gz
#检验系统环境及依赖
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl --shared zlib
#编译、安装
make && make install
#测试新安装openssl
cd /usr/local/openssl/bin && ./openssl version
#如果报错提示error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory,则执行下面命令
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/
#测试新安装openssl正常

3、编译安装php8.3.0

#进入安装目录
cd /server/tools/php-8.3.0
#检验当前系统环境,是否满足安装软件所必需的条件
./configure --prefix=/data/php --with-fpm-user=work --with-fpm-group=work --with-curl  --with-gettext --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl=/usr/local/openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm --enable-ctype
#执行后,可能会遇到下面问题
#configure: error: Package requirements (krb5-gssapi krb5) were not met:
#No package 'krb5-gssapi' found No package 'krb5' found
yum install krb5-devel krb5-libs krb5-workstation -y
#安装完后再进行编译
#configure: error: Package requirements (openssl >= 1.0.2) were not met:
#No package 'openssl' found
升级openssl,重新检测还是不行的话
mkdir -pv /usr/local/lib/pkgconfig
ln -s /usr/local/openssl/lib/pkgconfig/openssl.pc /usr/local/lib/pkgconfig
ln -s /usr/local/openssl/lib/pkgconfig/libcrypto.pc /usr/local/lib/pkgconfig
ln -s /usr/local/openssl/lib/pkgconfig/libssl.pc /usr/local/lib/pkgconfig
vim ~/.bash_profile
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source ~/.bash_profile
pkg-config --list-all #查看有openssl后,算是成功
#重新检测系统环境
./configure --prefix=/data/php --with-fpm-user=work --with-fpm-group=work --with-curl  --with-gettext --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl=/usr/local/openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm --enable-ctype
#编译安装
make && make install

4、配置环境变量

sed -i 's/PATH=.*/&:\/data\/php\/bin/g' ~/.bash_profile
source ~/.bash_profile

5、修改配置文件

cp /server/tools/php-8.3.0/php.ini-production /data/php/lib/php.ini
cp /data/php/etc/php-fpm.conf.default /data/php/etc/php-fpm.conf
ln -s /data/php/sbin/php-fpm /usr/local/bin/php
cp /data/php/etc/php-fpm.d/www.conf.default /data/php/etc/php-fpm.d/www.conf
sed -i 's/;listen.mode = 0660/listen.mode = 0660/g' /data/php/etc/php-fpm.d/www.conf
sed -i '/^pm.max_children/s/5/25/' /data/php/etc/php-fpm.d/www.conf
sed -i '/^pm.start_servers/s/2/5/' /data/php/etc/php-fpm.d/www.conf
sed -i '/^pm.min_spare_servers/s/1/2/' /data/php/etc/php-fpm.d/www.conf
sed -i '/^pm.max_spare_servers/s/3/10/' /data/php/etc/php-fpm.d/www.conf
sed -i '/pm.max_requests/s/;pm.max_requests = 500/pm.max_requests = 10000/' /data/php/etc/php-fpm.d/www.conf
sed -i 's/;rlimit_files = 1024/rlimit_files = 1024/g' /data/php/etc/php-fpm.d/www.conf
sed -i 's/;slowlog = log\/$pool.log.slow/slowlog = log\/$pool.log.slow/g' /data/php/etc/php-fpm.d/www.conf

6、配置systemctl启动php

cd /usr/lib/systemd/system/
cat>php-fpm.service<<EOF
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=forking
#PIDFile=/var/run/php-fpm.pid
ExecStart=/data/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start php-fpm
systemctl enable php-fpm

二、安装amqp扩展

1、安装rabbitmq-c

1)安装cmake
1、安装必备依赖库
yum install -y gcc gcc-c++ make automake wget
2、下载安装包
cd /server/tools
wget https://cmake.org/files/v3.26/cmake-3.26.3.tar.gz
3、解压并安装
tar xvf cmake-3.26.3.tar.gz
cd cmake-3.26.3
./bootstrap
gmake
gmake install
4、检测是否安装成功
cmake --version
2)安装rabbitmq-c
#下载安装包 (如果下载不下来,windows下载,上传到服务器)
wget https://github.com/alanxz/rabbitmq-c/archive/v0.14.0.tar.gz
#解压安装包
tar zxvf v0.14.0.tar.gz
#创建build子目录并进入子目录
cd rabbitmq-c-0.14.0
mkdir build && cd build
#创建Makefile文件到build目录中
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c ..
#安装rabbitmq-c库
cmake --build .  --target install
3)安装amqp
#下载安装包
wget https://pecl.php.net/get/amqp-2.1.2.tgz
#解压安装包
tar zxvf amqp-2.1.2.tgz
#phpize编译,生成configure文件
cd /server/tools/amqp-2.1.2
/data/php/bin/phpize
#检查系统环境
./configure --with-php-config=/data/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c
#编译安装
make && make install
#编译安装报错:
#/usr/bin/ld: cannot find -lrabbitmq
#collect2: error: ld returned 1 exit status
#make: *** [amqp.la] Error 1
yum install -y librabbitmq-devel
#重新编译安装
make && make install
#修改php.ini文件配置amqp扩展
vim /data/php/lib/php.ini
extension=amqp.so
#重启php-fpm
systemctl restart php-fpm
#查看扩展
php -m

2、安装gd扩展

1)安装zlib
#下载安装包
cd /server/tools
wget https://www.zlib.net/fossils/zlib-1.2.11.tar.gz
#解压安装包
tar xzvf zlib-1.2.11.tar.gz
#检测系统环境
cd zlib-1.2.11
./configure
#编译安装
make && make install
2)安装freetype
#下载安装包
cd /server/tools
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz
#解压安装包
tar -xzvf freetype-2.9.tar.gz
#检测系统环境
cd freetype-2.9
./configure --prefix=/usr/local/lib/freetype
#编译安装
make && make install
3)安装libpng
#下载安装包
cd /server/tools
wget https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.43/libpng-1.6.43.tar.gz
#解压安装包
tar -xzvf  libpng-1.6.43.tar.gz
#检测系统环境
cd libpng-1.6.43
./configure --prefix=/usr/local/lib/libpng
#编译安装
make && make install
4)安装libjpeg
#下载安装包
cd /server/tools
wget https://www.ijg.org/files/jpegsrc.v9f.tar.gz
#解压安装包
tar -xzvf jpegsrc.v9f.tar.gz
#检测系统环境
cd jpeg-9f
./configure --prefix=/usr/local/lib/libjpeg --enable-shared
#编译安装
make && make install
5)安装GD
#进入php的ext文件,phpize编译,生成configure文件
cd /server/tools/php-8.3.0/ext/gd
/data/php/bin/phpize
#检查系统环境
./configure --with-php-config=/data/php/bin/php-config --with-jpeg --with-freetype
#编译安装
make && make install
#修改php.ini文件配置gd扩展
vim /data/php/lib/php.ini
extension=gd.so
#重启php-fpm
systemctl restart php-fpm
#查看扩展
php -m

3、安装redis扩展

#下载安装包
cd /server/tools
wget https://pecl.php.net/get/redis-5.3.4.tgz
#解压安装包
tar xvf redis-5.3.4.tgz
#phpize编译,生成configure文件
cd /server/tools/redis-5.3.4
/data/php/bin/phpize
#检查系统环境
./configure --with-php-config=/data/php/bin/php-config
#编译安装
make && make install
#修改php.ini文件配置gd扩展
vim /data/php/lib/php.ini
extension=redis
#重启php-fpm
systemctl restart php-fpm
#查看扩展
php -m

部署问题总结

./configure --prefix=/data/php --with-fpm-user=work --with-fpm-group=work --with-curl  --with-gettext --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm --enable-ctype
#执行后,可能会遇到下面问题
#configure: error: Package requirements (krb5-gssapi krb5) were not met:
#No package 'krb5-gssapi' found No package 'krb5' found
yum install krb5-devel krb5-libs krb5-workstation -y
#安装完后再进行编译
#configure: error: Package requirements (openssl >= 1.0.2) were not met:
#No package 'openssl' found
升级openssl,重新检测还是不行的话
mkdir -pv /usr/local/lib/pkgconfig
ln -s /usr/local/openssl/lib/pkgconfig/openssl.pc /usr/local/lib/pkgconfig
ln -s /usr/local/openssl/lib/pkgconfig/libcrypto.pc /usr/local/lib/pkgconfig
ln -s /usr/local/openssl/lib/pkgconfig/libssl.pc /usr/local/lib/pkgconfig
vim ~/.bash_profile
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source ~/.bash_profile
pkg-config --list-all #查看有openssl后,算是成功

#升级openssl后,执行./openssl version报错提示./openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/

#执行报错:cmake: command not found
安装cmake

#/usr/bin/ld: cannot find -lrabbitmq
#collect2: error: ld returned 1 exit status
#make: *** [amqp.la] Error 1
yum install -y librabbitmq-devel