Centos 8 编译php 8.0.12

步骤一:安装依赖

yum config-manager --set-enabled powertools
或
yum config-manager --set-enabled PowerTools

yum install -y wget gcc gcc-c++ gd-devel zlib-devel libjpeg-devel libpng-devel libiconv-devel freetype-devel libxml2-devel openssl-devel curl-devel libxslt-devel libmcrypt-devel mhash mcrypt epel-release oniguruma-devel sqlite-devel

Centos 8 必装:centos >= 7 不用装

wget https://github.com/kkos/oniguruma/releases/download/v6.9.7.1/onig-6.9.7.1.tar.gz
tar xvf onig-6.9.7.1.tar.gz
./configure --bindir=/usr/sbin/ \
            --sbindir=/usr/sbin/ \
            --libexecdir=/usr/libexec \
            --sysconfdir=/etc/ \
            --localstatedir=/var \
            --libdir=/usr/lib64/  \
            --includedir=/usr/include/ \
            --datarootdir=/usr/share \
            --infodir=/usr/share/info \
            --localedir=/usr/share/locale \
            --mandir=/usr/share/man/ \
            --docdir=/usr/share/doc/onig
make && make install

步骤二:下载php安装包

wget https://www.php.net/distributions/php-8.0.12.tar.gz

步骤三:编译源代码

tar xvf php*
cd php*
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc/ --enable-mbstring --with-curl --enable-fpm --with-mysqli --with-zlib make
make install

步骤四:复制文件

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp php.ini-development /usr/local/php/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

步骤五:启动php-fpm

service php-fpm start
chkconfig --add php-fpm

步骤六:添加环境变量

echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/profile
source /etc/profile

可选步骤:隐藏PHP版本

sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/php/etc/php.ini
service php-fpm restart

可选步骤:显示PHP版本

sed -i 's/expose_php = Off/expose_php = On/g' /usr/local/php/etc/php.ini
service php-fpm restart

可选步骤:小于或等于512M内存编译PHP提示内存不足,使用虚拟内存。

1.创建swap分区
dd if=/dev/zero of=/swap bs=1024 count=1024000
2.创建Linux交换文件
mkswap /swap
3.激活/swap交换文件
swapon /swap
4.查看创建虚拟内存是否成功
free -h
5.设置成永久生效
echo "/swap none swap sw 0 0" >> /etc/fstab

可选步骤:删除虚拟内存

1.停止swap分区
swapoff /swap
2.删除swap分区文件
rm -rf /swap
3.删除"/etc/swap"指定条目
sed -i 's/\/swap none swap sw 0 0//g' /etc/fstab

Tags:

Add a Comment

您的电子邮箱地址不会被公开。 必填项已用 * 标注