我的博客:https://blog.justlovesmile.top
文章目录
当我买了阿里云轻量应用服务器wordpress镜像后,发现很多主题需要升级php…
1.首先更新依赖包。
yum -y update
2.安装依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++
3.转到 /usr/local/src 目录,下载php7.3.5
cd /usr/local/src
wget https://www.php.net/distributions/php-7.3.5.tar.gz
4.解压安装包,并进入目录
tar -zxvf php-7.3.5.tar.gz
cd php-7.3.5
5.添加用户和组
groupadd www
useradd -g www www
6.开始编译
./configure --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm
这里会提示 configure: error: Please reinstall the libzip distribution
,我们需要移除libzip,手动安装最新版本
7.安装libzip
(1)先安装cmake
cd /usr/local/src
wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz
tar -zxvf cmake-3.14.3.tar.gz
cd cmake-3.14.3
./bootstrap
make && make install
(2)再编译安装libzip
yum remove libzip -y
cd /usr/local/src
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install
(3)执行以下命令
vi /etc/ld.so.conf
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
#保存退出
ldconfig -v
# 使之生效
8.再次编译PHP7.3
make && make install
9.编译完成后,添加环境变量
vi /etc/profile
#添加以下内容到最后
PATH=$PATH:/usr/local/php/bin
export PATH
#刷新环境变量
source /etc/profile
10.配置文件
# 将启动脚本复制到init.d中。
cp /usr/local/src/php-7.3.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm73
# 给启动脚本加上执行权限
chmod +x /etc/init.d/php-fpm73
# 将默认配置文件复制为.conf文件
cp /usr/local/php/etc/php-fpm.conf.default ${PHP73_DIR}/etc/php-fpm.conf
# 添加pool的配置
cat << EOF > /usr/local/php/etc/php-fpm.d/www.conf
[www]
listen = /home/www/logs/php73-fpm.sock
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 128
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 300
rlimit_files = 1024
slowlog = /home/www/logs/php73-fpm-slow.log
EOF
11.修改apache
镜像中默认是用的php-fpm,使用的是socket方式的监听,Apache对应配置文件/usr/local/apache/conf/httpd.conf
,其中配置如下:
需要修改其中socket的文件路径指向到新版本的PHP就可以了,在/usr/local/php73/etc/php-fpm.d/www.conf
有指定,新的配置到/home/www/logs/php73-fpm.sock
即可,如图:
12.重启服务
# 停止旧版本的PHP(实际不停止也不影响,停止可以减少一些系统资源占用)
/etc/init.d/php-fpm stop
# 启动新版PHP-FPM
/etc/init.d/php-fpm73 start
#启动报错请修改文件名
修改/usr/local/php/etc/php-fpm.conf.default为php-fpm.conf
# 重启apache
/etc/init.d/apachectl restart