Centos 编译安装 PHP8

1、安装依赖包

yum install gcc \
autoconf \
gcc-c++ \
libxml2 \
libxml2-devel \
openssl \
openssl-devel \
bzip2 \
bzip2-devel \
libcurl \
libcurl-devel \
libjpeg \
libjpeg-devel \
libpng \
libpng-devel \
freetype \
freetype-devel \
gmp \
gmp-devel \
readline \
readline-devel \
libxslt \
libxslt-devel \
systemd-devel \
openjpeg-devel \
oniguruma \
oniguruma-devel

2、(可选)如果需要zip扩展并且提示libzip 版本低于 0.11需要自己重装。不需要则跳过

如果没有Cmake,下载Cmake https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0.tar.gz
安装Cmake 
tar -xvzf cma...
cd cma...
./configure --prefix=/usr/local/cmake
./bootstrap
make 
make install

下载 https://libzip.org/download/libzip-1.9.2.tar.gz
yum remove libzip libzip-devel
升级libzip 
tar -xvzf libz...
cd libz...
mkdir build && cd build
cmake ..
make 
make install
whereis libzip
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig -v | grep libzip
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH

3、编译PHP8 (自行修改所需扩展,不需要zip扩展的请去掉--with-zip)

tar -xvzf php8...
cd php8...
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-curl \
--with-freetype \
--enable-gd \
--with-jpeg \
--with-gettext \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml \
--with-mysqli \
--with-openssl \
--with-pdo-mysql  \
--with-pdo-sqlite \
--with-pear \
--enable-sockets \
--with-mhash \
--with-ldap-sasl \
--with-xsl \
--with-zlib \
--with-zip \
-with-bz2 \
--with-iconv  \
--enable-fpm \
--enable-pdo  \
--enable-bcmath  \
--enable-mbregex \
--enable-mbstring \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-sysvsem \
--enable-opcache \
--enable-intl \
--enable-calendar \
--enable-static \
--enable-mysqlnd \
--with-fpm-user=www \
--with-fpm-group=www 

4、配置PHP

groupadd www
useradd -g www www

cp 源码解压包路径/php.ini-development /usr/local/php/etc/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

vim /usr/local/php/etc/php-fpm.conf
配置错误日志:
error_log = /usr/local/php/var/php-fpm.log
配置pid文件:    
pid = /usr/local/php/var/run/php-fpm.pid

增加环境变量usr/local/php/bin/到PATH
vim  /etc/profile
export PATH=$PATH:/usr/local/php/bin/
保存退出
source /etc/profile

php -v
PHP 8.0.22 (cli) (built: Aug  8 2022 15:26:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.22, Copyright (c) Zend Technologies

5、(可选)添加php-fpm自启动

vim /etc/rc.local
增加一行 
usr/local/php/sbin/php-fpm
保存退出

你可能感兴趣的:(Centos 编译安装 PHP8)