Linux(CentOS7)部署PHP-7.2.17源码包
#!/bin/bash
# 安装 PHP 7.2.17 的脚本
# 定义 PHP 版本和依赖包
PHP_VERSION=7.2.17
DEVTOOLSET_VERSION=4
# 安装 EPEL 和 Remi 仓库
yum install -y epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 安装编译 PHP 所需的依赖包
yum install -y \
gcc \
gcc-c++ \
make \
zlib-devel \
libxml2-devel \
libjpeg-devel \
libpng-devel \
freetype-devel \
giflib-devel \
libmcrypt-devel \
libicu-devel \
libzip-devel \
bzip2-devel \
curl-devel \
openssl-devel \
sqlite-devel \
systemd-devel \
libxslt-devel \
oniguruma-devel \
libwebp-devel \
libxpm-devel \
libgd-devel \
libxslt-devel \
pcre-devel \
recode-devel \
krb5-devel \
libldap2-devel \
libjpeg-turbo-devel
# 安装 devtoolset,用于更高版本的 GCC 编译
yum install -y "centos-release-scl"
yum install -y "devtoolset-${DEVTOOLSET_VERSION}"
scl enable devtoolset-"${DEVTOOLSET_VERSION}" bash
# 下载 PHP 源码并解压
curl -LO https://www.php.net/distributions/php-"${PHP_VERSION}".tar.gz
tar xzf php-"${PHP_VERSION}".tar.gz
cd php-"${PHP_VERSION}"
# 配置 PHP 编译选项
./configure \
--prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--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-xmlrpc \
--with-xsl \
--with-zlib \
--enable-bcmath \
--enable-fpm \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
# 编译和安装 PHP
make -j$(nproc)
make install
# 配置 PHP-FPM
cp 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
# 创建 systemd service 文件
tee /etc/systemd/system/php-fpm.service <<EOF
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --noda
评论已关闭