1、下载tar包 下载地址https://www.php.net/downloads
2.安装依赖
yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel epel-release curl-devel postgresql-devel aspell-devel net-snmp-devel unixODBC-devel libicu-devel libc-client-devel libXpm-devel libvpx-devel enchant-devel openldap openldap-devel db4-devel gmp-devel sqlite-devel oniguruma oniguruma-devel autoconf automake libtool
如果有报错,看报错的具体原因,最好是什么也没安装过的一次性安装肯定没问题
依赖安装成功
3.解压 tar xvf php-7.4.22.tar.gz
cd php-7.4.22
预编译
./configure --prefix=/usr/local/php --with-mysql-sock=/usr/local/mysql/mysql.sock --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip --enable-fpm
报错 需单独安装一下 oniguruma oniguruma-devel 这是centos7的
yum -y install oniguruma oniguruma-devel
出现 Thank you for using PHP 说明编译成功
4.安装 make && make install
[root@147 php-7.4.22]# echo $?
0
0表示上一步执行成功
安装成功开心不
配置文件
[root@147 php-7.4.22]# cp php.ini-production /usr/local/php/etc/php.ini
[root@147 php-7.4.22]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@147 php-7.4.22]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@147 php-7.4.22]# chmod +x /etc/init.d/php-fpm
[root@147 php-7.4.22]# chkconfig --add php-fpm
[root@147 php-7.4.22]# chkconfig php-fpm on
如果报错是因为配置的问题 把/usr/local/php/etc/php-fpm.d/www.conf.default 改为 www.conf 就可以了
[root@147 php-7.4.22] mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
然后在启动 service php-fpm start
添加环境变量
vi /etc/profile export PATH=/usr/local/php/sbin:$PATH source /etc/profile
完了