设置环境变量:
export USER=www
export PHP_VERSION=7.2.26
export CPUS=$(grep 'cores' /proc/cpuinfo |wc -l)
创建系统账号:
id ${USER}||useradd ${USER} -M -s /sbin/nologin
安装依赖:
yum install epel-release -y
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel \
libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype \
freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel \
libxslt libxslt-devel gcc-c++ libicu-devel -y
下载编译安装:
wget https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz
tar xf php-${PHP_VERSION}.tar.gz
cd php-${PHP_VERSION}/
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-fpm-user=${USER} \
--with-fpm-group=${USER} \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-curl \
--with-gd \
--with-openssl \
--with-mhash \
--with-xmlrpc \
--with-gettext \
--with-libxml-dir=/usr \
--without-pear \
--disable-rpath \
--enable-fpm \
--enable-ftp \
--enable-xml \
--with-xsl \
--enable-intl \
--enable-zip \
--enable-soap \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-pcntl \
--enable-sockets \
--enable-maintainer-zts \
--enable-mbregex \
--enable-mbstring \
--enable-opcache
make -j${CPUS} && make install
拷贝相关配置并启动:
cp php.ini-production /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
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
配置PHP环境变量:
cat > /etc/profile.d/PHP-BIN.sh <<EOF
export PHP_BIN=/usr/local/php/bin
export PATH=\${PATH}:\${PHP_BIN}
EOF
source /etc/profile.d/PHP-BIN.sh
清除环境变量:
unset USER PHP_VERSION CPUS
注: 从7.2版本开始 已经不再mcrypt加密算法可以有openssl 替换。 gd-native-ttf 已经移除:支持TrueType字符串函数库