我的系统版本:
cat /etc/redhat-release
1. 下载PHP安装文件
网址:https://downloads.php.net/~pollita/
wget https://downloads.php.net/~pollita/php-8.0.13RC1.tar.gz
解压:
tar -zxvf php-8.0.13RC1.tar.gz
cd php-8.0.13RC1
安装php的依赖库和安装编译的工具,无论有没有装都可以执行一下,否则你就有可能会像我下面那样遇到很多依赖问题。
yum -y install gcc gcc-c++
yum -y install libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libicu-devel freetype-devel openldap-devel openldap openldap-devel
2. 根据自己的需求配置安装需要的扩展:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-static --enable-sockets --with-zip --enable-calendar --enable-bcmath --enable-mbstring --with-zlib --with-iconv=/usr/local/libiconv --enable-gd --enable-mbstring --with-curl --with-freetype --disable-ipv6 --disable-debug --with-openssl --enable-intl --enable-opcache
配置过程中可能会遇到很多报错信息
注意:如果你提前安装了我上面说的那些依赖,下面这些报错就会少很多。
- 提示缺少依赖 libxml-2.0:
安装:
yum install libxml2-devel
- 报错:configure: error: Package requirements (openssl >= 1.0.1) were not met。
yum install openssl openssl-devel
- 继续configure,又有新错误:
configure: error: Package requirements (sqlite3 > 3.7.4) were not met
yum install sqlite-devel
- 继续,新错误:
configure: error: Package requirements (libcurl >= 7.29.0) were not met
yum install -y libcurl-devel.x86_64
- 新错误:
configure: error: Package requirements (libpng) were not met:
Package ‘libpng’, required by ‘virtual:world’, not found
用yum search libpng 搜索,发现要安装两个包:
yum install -y libpng.x86_64 libpng-devel.x86_64
如果提示libpng已安装,就用yum remove 依赖名 这个命令把旧的依赖删掉,重新安装。
- 新错误:
configure: error: Package requirements (freetype2) were not met:
Package ‘freetype2’, required by ‘virtual:world’, not found
yum install freetype-devel
- 新错误:
please install iconv libary.
[root@hecs-276579 ]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
[root@hecs-276579 ]# tar zxvf libiconv-1.15.tar.gz
[root@hecs-276579 libiconv-1.15]# cd libiconv-1.15
[rroot@hecs-276579 libiconv-1.15]# ./configure --prefix=/usr/local/libiconv
[root@hecs-276579 libiconv-1.15]# make
[root@hecs-276579 libiconv-1.15]# make install
- 新错误:
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
Package ‘icu-uc’, required by ‘virtual:world’, not found
Package ‘icu-io’, required by ‘virtual:world’, not found
Package ‘icu-i18n’, required by ‘virtual:world’, not found
yum install -y libicu-devel.x86_64
- 新错误:
checking whether g++ accepts -g… no
checking how to run the C++ preprocessor… /lib/cpp
configure: error: in /usr/local/php8/php-8.0.13RC1': configure: error: C++ preprocessor "/lib/cpp" fails sanity check See
config.log’ for more details
解决:
yum install glibc-headers
yum install gcc-c++
-
新错误:
configure: error: Package requirements (oniguruma) were not met:
Package ‘oniguruma’, required by ‘virtual:world’, not found
解决:
参考文章:https://www.cnblogs.com/architectforest/p/12433640.html
-
新错误:
Package ‘libzip’, required by ‘virtual:world’, not found
解决:
yum install libzip-devel
终于、终于出现了成功界面:
然后:
make
make install
本以为高枕无忧了,谁知道在make的时候又报错:
cc: fatal error: Killed signal terminated program cc1
compilation terminated.
make: *** [Makefile:931: ext/fileinfo/libmagic/apprentice.lo] Error 1
解决办法:
报这个错误是因为服务器内存不足1G,只需要在配置命令中添加 --disable-fileinfo 即可。
所以在配置命令的最后加上,重新./configure一次:
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-static --enable-sockets --with-zip --enable-calendar --enable-bcmath --enable-mbstring --with-zlib --with-iconv=/usr/local/libiconv --enable-gd --enable-mbstring --with-curl --with-freetype --disable-ipv6 --disable-debug --with-openssl --enable-intl --enable-opcache --disable-fileinfo
这次终于make && make install 成功了。
此外,可以提前创建用户组和用户:
groupadd www
useradd -g www www
然后在配置命令里面加上:
--with-fpm-user=www \
--with-fpm-group=www \
这样安装好后直接和Apache或者Nginx的用户组对应上了。
3. 安装成功后设置一下PHP
- 生成php配置文件
[root@hecs-276579 php]# find / -name "*php.ini*"
/usr/local/php8/php-8.0.13RC1/php.ini-production #安装源文文件夹
/usr/local/php8/php-8.0.13RC1/php.ini-development
[root@hecs-276579 php]# cp /usr/local/php8/php-8.0.13RC1/php.ini-production /usr/local/php/etc/php.ini #复制一份到php/etc目录下
- 生成www配置文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
- 生成php-fpm配置文件
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
- 生成php-fpm服务启动文件
cd /usr/local/php8/php-8.0.13RC1/ #返回到安装源文件夹
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #复制
- 映射全局命令
不做这一步,输入 php -v 时会显示没有这个命令。
ln -s /usr/local/php/sbin/* /usr/local/sbin/
ln -s /usr/local/php/bin/* /usr/local/bin/
- 启动php-fpm服务
service php-fpm start
- 查看是否启动
ps auxfww | grep php | grep -v grep
- 查看版本号
php -v
大功告成!