CentOS 环境编译安装php8.0

如果是新服务器,建议先看下这篇文章:CentOS服务器初始化配置

php8 编译安装和其他低版本基本一致

准备

#编译工具
yum -y install gcc gcc-c++ make
#依赖
yum -y install zlib-devel libxml2-devel openssl openssl-devel gd-devel libmcrypt-devel libcurl-devel libicu-devel oniguruma-devel

编译

cd php-8.0.3

./configure --prefix=/data/apps/php --with-config-file-path=/data/apps/php/etc --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir --enable-xml --with-xpm-dir --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-pear --with-zlib --enable-fpm --enable-intl

make && make install

cp php.ini-production /data/apps/php/etc/php.ini
#简单编辑一下
vi php.ini
    971 [Date]
    972 ; Defines the default timezone used by the date functions
    973 ; http://php.net/date.timezone
    974 date.timezone = PRC

php-fpm

cd /data/apps/php/etc/
mv php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
mv www.conf.default www.conf
vi www.conf
     20 ; Unix user/group of processes
     21 ; Note: The user is mandatory. If the group is not set, the default user's group
     22 ;       will be used.
     23 user = vagrant
     24 group = vagrant

#设置php-fpm开机自启
#复制启动脚本
cp /vagrant/tgz/php-8.0.3/sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
#给可执行权限
chmod +x /etc/init.d/php-fpm
#开机自启
chkconfig --level 345 php-fpm on

#常用命令
service php-fpm start ⬅️启动
service php-fpm reload ⬅️重载
service php-fpm restart ⬅️重启
service php-fpm stop ⬅️关闭

为了方便使用php相关命令,做个软链

ln -s /data/apps/php/bin/* /usr/bin/

感谢阅读这篇文章,如果你喜欢,或者遇到了问题,可以关注我的公众号