CentOS 环境编译安装 PHP8

编译安装 PHP7

准备工作

  • 安装 epel
yum install -y yum-utils
package-cleanup --cleandupes
yum update -y
yum install -y epel-release
# 如果找不到epel-release包,则进行下面两步操作
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -ivh epel-release-latest-7.noarch.rpm
  • 安装必备的依赖
yum install -y gcc-c++ autoconf make \
libjpeg libjpeg-devel  \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel unzip \
zip libzip-devel \
glibc glibc-devel \
glib2 glib2-devel \
bzip2 bzip2-devel \
curl curl-devel libcurl-devel \
ncurses openssl-devel \
gdbm-devel db4-devel libXpm-devel \
libX11-devel gd-devel gmp-devel \
readline-devel libxslt-devel \
expat-devel xmlrpc-c xmlrpc-c-devel \
libicu-devel libmcrypt-devel \
libmemcached-devel \
oniguruma oniguruma-devel \
sqlite-devel \
wget
  • 下载 PHP8 安装包

官方下载地址:PHP Downloads

cd /usr/src/
wget https://www.php.net/distributions/php-8.0.0.tar.bz2 -O php.bz2
tar -xjf php.bz2
mv php-* php
cd /usr/src/php

编译 PHP8

  • 查看可配置的编译参数
./configure --help
  • 编译安装
./configure --prefix=/usr/local/php \
--enable-gd \
--enable-dba \
--enable-fpm \
--enable-dom \
--enable-pdo \
--enable-exif \
--enable-intl \
--enable-soap \
--enable-pcntl \
--enable-shmop \
--enable-bcmath \
--enable-filter \
--enable-session \
--enable-sockets \
--enable-calendar \
--enable-mbstring \
--enable-simplexml \
--disable-fileinfo \
--with-bz2 \
--with-cdb \
--with-curl \
--with-pear \
--with-zlib \
--with-mhash \
--with-iconv \
--with-mysqli \
--with-openssl \
--with-pcre-jit \
--with-pdo-mysql \
--with-mysql-sock \
--with-openssl-dir

make
make install

后续工作

  • 测试是否安装成功
/usr/local/php/bin/php -v
  • 做软链,以便直接用 php 命令运行
ln -sf /usr/local/php/bin/php /usr/local/bin/php
ln -sf /usr/local/php/bin/php-config /usr/bin/php-config
ln -sf /usr/local/php/bin/phpize /usr/local/bin/phpize
ln -sf /usr/local/php/bin/pecl /usr/local/bin/pecl
  • 验证
php -v
  • 复制配置文件
cp /usr/src/php/php.ini-development /usr/local/php/lib/php.ini
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 /usr/src/php/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
  • 启动 php-fpm
service php-fpm start
  • 配置开机启动 php-fpm
chkconfig php-fpm on
添加新评论