Alien的博客

CentOS7中编译PHP7.1.2


#首先安装必要的库
yum install  epel-release  wget -y && \
yum install gcc*  -y && \
yum install  libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel gmp-devel aspell-devel net-snmp-devel libmcrypt-devel  -y 

#下载php7的源码
wget http://cn2.php.net/get/php-7.1.2.tar.gz/from/this/mirror -O php-7.1.2.tar.gz && \
tar xvf php-7.1.2.tar.gz && \
cd php-7.1.2

#设置变量,指定编译时候的线程数,以及php7安装路径
phpdir="/var/local/php7.1.2"
cpunum=4

#编译并安装
./configure --prefix=$phpdir  \
--enable-fpm  \
--enable-mbstring \
--enable-soap   \
--enable-mbstring  \
--enable-sockets  \
--enable-gd-native-ttf  \
--with-gd  \
--with-xmlrpc  \
--with-libxml-dir  \
--with-snmp \
--with-pspell  \
--with-mcrypt  \
--with-gmp  \
--with-curl  \
--with-mysqli \
--with-pdo-mysql  \
--with-openssl  \
--with-zlib  \
--with-freetype-dir  \
--with-jpeg-dir  \
&& make clean \
&& make -j $cpunum \
&& make install \
&& echo alien

#拷贝默认的php.ini
cp php.ini-production  $phpdir/lib/php.ini

#拷贝centos7下的php7启动脚本
cp sapi/fpm/php-fpm.service  $phpdir/


#使用默认的php-fpm.con和www.conf配置文件
mv $phpdir/etc/php-fpm.conf.default  $phpdir/etc/php-fpm.conf
mv $phpdir/etc/php-fpm.d/www.conf.default $phpdir/etc/php-fpm.d/www.conf


#按照自己的需求设置相关配置
sed -i 's/^user = nobody$/user = nginx/g' $phpdir/etc/php-fpm.d/www.conf
sed -i 's/^group = nobody$/group = nginx/g' $phpdir/etc/php-fpm.d/www.conf
sed -i 's/^pm.max_children = 5$/pm.max_children = 100/g' $phpdir/etc/php-fpm.d/www.conf
sed -i 's/^pm.start_servers = 2$/pm.start_servers = 5/g' $phpdir/etc/php-fpm.d/www.conf
sed -i 's/^pm.min_spare_servers = 1$/pm.min_spare_servers = 5/g' $phpdir/etc/php-fpm.d/www.conf
sed -i 's/^pm.max_spare_servers = 3$/pm.max_spare_servers = 30/g' $phpdir/etc/php-fpm.d/www.conf
diff sapi/fpm/www.conf $phpdir/etc/php-fpm.d/www.conf

#设置php的pid存放目录
sed -i 's/^;pid = run\/php-fpm.pid$/pid = run\/php-fpm.pid/g' $phpdir/etc/php-fpm.conf
diff sapi/fpm/php-fpm.conf $phpdir/etc/php-fpm.conf


#根据需求设置php.ini的相关配置
sed -i 's/^zlib.output_compression = Off$/zlib.output_compression = On/g' $phpdir/lib/php.ini
sed -i 's/^upload_max_filesize = 2M$/upload_max_filesize = 100M/g' $phpdir/lib/php.ini
sed -i 's/^post_max_size = 8M$/post_max_size = 200M/g' $phpdir/lib/php.ini
sed -i 's/^;date.timezone =$/date.timezone = Asia\/Chongqing/g' $phpdir/lib/php.ini
diff php.ini-production  $phpdir/lib/php.ini


#把php启动脚本添加到systemctl中
#如果存在之前版本的php环境会提示文件存在,改个名字就行了
ln $phpdir/php-fpm.service  /usr/lib/systemd/system/php-fpm.service

#运行
systemctl start php-fpm

#设置开机启动
systemctl enable php-fpm