1、检查是否安装php
yum search php
yum info php // 查看php版本信息
下载
wget https://www.php.net/distributions/php-7.1.31.tar.gz
2、安装epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
3、安装php7的rpm源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
4、安装php7
// 安装依赖
yum install libxml2 libxml2-devel openssl openssl-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel
mv php7.1.31 /usr/local
cd /usr/local/php7.1.31
// 开始进行配置-配置参数详解
./configure --prefix=/usr/local/php7 --with-config-file-path=/etc/ --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-simplexml --enable-xml --disable-rpath --enable-bcmath --enable-soap --enable-zip --with-curl --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody --enable-mbstring --enable-sockets --with-gd --with-openssl --with-mhash --enable-opcache --disable-fileinfo
--with-config-file-path 用于存放php.ini的目录
// 编译安装
make
make install
// 添加php命令到环境变量里
vim /etc/profile
// 在文件末尾加入:
PATH=$PATH:/usr/local/php7/bin
export PATH
// 使改动立即生效执行
source /etc/profile
// 查看php版本
php -v
PHP 7.1.31 (cli) (built: Sep 16 2020 17:27:27) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
5、配置
cp /usr/local/php-7.1.31/php.ini-pro