草稿 · 2022年5月1日 0

草稿: Linux centos PHP5.6安装

配置环境变量:
export USER=www
export PHP_VERSION=5.6.37
export CPUS=$(grep 'cores' /proc/cpuinfo |wc -l)
创建系统账号:
id ${USER}||useradd ${USER}  -M -s /sbin/nologin
安装依赖:
yum install -y 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 
下载编译安装:
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}   \
--with-mysql=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-mcrypt  \
--with-gd  \
--with-openssl  \
--with-mhash    \
--with-xmlrpc   \
--with-gettext  \
--with-libxml-dir=/usr \
--without-pear  \
--disable-rpath \
--disable-fileinfo \
--enable-mysqlnd   \
--enable-fpm   \
--enable-ftp   \
--enable-xml   \
--with-xsl     \
--enable-intl  \
--enable-zip   \
--enable-soap  \
--enable-bcmath   \
--enable-shmop    \
--enable-sysvsem  \
--enable-inline-optimization  \
--enable-gd-native-ttf  \
--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 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
chmod +x /etc/profile.d/PHP-BIN.sh
清除环境变量:
unset USER PHP_VERSION CPUS

该文档仅用于存档老版本服务安装