Linux shell脚本快速源码编译安装php-8.3.3以及扩展redis、zip、igbinary、memcached等
#!/bin/bash
# 快速编译安装 PHP 8.3.3 并配置常用扩展:redis、zip、igbinary、memcached
# 定义 PHP 版本和源代码目录变量
PHP_VERSION="php-8.3.3"
SRC_DIR="/usr/local/src"
# 安装依赖库
yum install -y epel-release \
&& yum install -y \
gcc \
gcc-c++ \
make \
zlib-devel \
openssl-devel \
libxml2-devel \
bzip2-devel \
curl-devel \
freetype-devel \
gmp-devel \
libmcrypt-devel \
libpng-devel \
libjpeg-turbo-devel \
libzip-devel \
recode-devel \
libicu-devel \
libxslt-devel \
systemd-devel \
pcre-devel \
sqlite-devel \
oniguruma-devel \
libwebp-devel \
libc-client-devel \
openldap-devel
# 下载 PHP 源代码
cd $SRC_DIR \
&& wget "https://www.php.net/distributions/$PHP_VERSION.tar.gz" \
&& tar -zxvf "$PHP_VERSION.tar.gz" \
&& cd "$PHP_VERSION"
# 配置编译选项
./configure \
--prefix=/usr/local/php8 \
--with-curl \
--with-freetype \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pear \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-bcmath \
--enable-fpm \
--enable-gd-jis-conv \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--disable-debug \
--disable-rpath \
--disable-fileinfo
# 编译并安装 PHP
make -j$(nproc) && make install
# 配置 PHP
cp php.ini-development /usr/local/php8/lib/php.ini
cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
# 下载并编译安装 PHP 扩展
for extension in redis zip igbinary memcached; do
cd $SRC_DIR \
&& git clone "https://github.com/php/$extension-ds.git" \
&& cd "$extension-ds" \
&& phpize \
&& ./configure --with-php-config=/usr/local/php8/bin/php-config \
&& make && make install
done
# 配置 PHP 加载扩展
extension_dir="/usr/local/php8/lib/php/extensions/no-debug-non-zts-20210902"
for extension in redis zip igbinary memcached; do
echo "extension=$
评论已关闭