系统已经安装过php7了所以很多依赖不在重新安装了
cd /usr/local/src
wget https://www.php.net/distributions/php-8.0.1.tar.gz
tar -zxvf php-8.0.1.tar.gz
cd php-8.0.1
配置(注意和默认的PHP版本以目录区隔)
./configure \
--prefix=/usr/local/php8 \
--exec-prefix=/usr/local/php8 \
--bindir=/usr/local/php8/bin \
--sbindir=/usr/local/php8/sbin \
--includedir=/usr/local/php8/include \
--libdir=/usr/local/php8/lib/php \
--mandir=/usr/local/php8/php/man \
--with-config-file-path=/usr/local/php8/etc \
--with-openssl \
--enable-mbstring \
--enable-fpm
报错了PHP8 默认要求sqlite3和oniguruma
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
No package 'sqlite3' found
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
yum install sqlite3 sqlite3-devel
yum install oniguruma oniguruma-devel
依赖检查完毕之后 make && make install 编译完毕以后执行下版本验证命令
/usr/local/php8/bin/php -v
PHP 8.0.1 (cli) (built: Jan 28 2021 17:29:05) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
在之前编译的源码包中,找到 php.ini-production,复制到/usr/local/php/etc下,并改名为php.ini:
cp php.ini-production /usr/local/php8/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php8-fpm
chmod +x /etc/init.d/php8-fpm
添加php-fpm
cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
添加 www.conf 配置文件
[root@zhaoyinfan001 php-8.0.1]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
PHP多版本环境变量,添加以后php8 -v
vim /etc/profile
PATH=/usr/local/php/bin:$PATH
alias php7.3.3='/usr/local/php7.3.3/bin/php'
alias php8='/usr/local/php8/bin/php'
source /etc/profile