php-7.0.18版本(编译安装)-自定义安装路径
php-7.0.18版本(编译安装)-自定义安装路径
安装路径:/application/php-7.0.18
1.前期准备
安装编译需要的gcc和gcc-c++
yum install -y gcc gcc-c++
php依赖
libxml2-devel、openssl-devel、curl-devel、libjpeg-devel、libpng-devel、freetype-devel、openldap-devel
yum -y install libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel openldap-devel
扩展:
yum install -y bzip2-devel freetype-devel gd-devel gmp-devel libcurl-devel libpng-devel libjpeg-turbo-devel libxml2-devel libxslt-devel openssl-devel openldap-devel pcre-devel readline-devel xmlrpc-c xmlrpc-c-client zlib-devel
libiconv(可选)
编译安装:
cd /tools
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxf /tools/libiconv-1.14.tar.gz -C .
cd libiconv-1.14
./configure --prefix=/usr/local/iconv
make && make install
make报错:
In file included from progname.c:26:0:
./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
^
解决办法:
make clean
sed -i 698i'#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)' srclib/stdio.in.h
sed -i 700i'#endif' srclib/stdio.in.h
make && make install
rpm安装:
cd /tools
wget https://forensics.cert.org/centos/cert/7/x86_64//libiconv-1.14-3.el7.x86_64.rpm
wget https://forensics.cert.org/centos/cert/7/x86_64/libiconv-devel-1.14-3.el7.x86_64.rpm
rpm -ivh libiconv*.rpm
1.15版本:
wget https://forensics.cert.org/centos/cert/7/x86_64/libiconv-1.15-1.el7.x86_64.rpm
wget https://forensics.cert.org/centos/cert/7/x86_64/libiconv-devel-1.15-1.el7.x86_64.rpm
libmcrypt(可选)
编译安装:
cd /tools
wget https://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/mcrypt
make && make install
rpm安装:
cd /tools
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/l/libmcrypt-2.5.8-13.el7.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/l/libmcrypt-devel-2.5.8-13.el7.x86_64.rpm
rpm -ivh libmcrypt*.rpm
mhash(可选)
编译安装:
cd /tools
wget https://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar -zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr/local/mhash
make && make install
rpm安装:
cd /tools
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/m/mhash-0.9.9.9-10.el7.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/m/mhash-devel-0.9.9.9-10.el7.x86_64.rpm
rpm -ivh mhash*.rpm
下载php源码包并解压
cd /tools
wget http://cn2.php.net/distributions/php-7.0.18.tar.gz
tar -zxf php-7.0.18.tar.gz
2.php编译安装
生成Makefile文件
cd php-7.0.18
./configure \
--prefix=/application/php-7.0.18 \
--with-mysqli \
--enable-mbstring \
--enable-fpm
扩展:
iconv、mcrypt、mhash是用rpm或yum(epel)安装则需要把标红部分给删除
./configure \
--prefix=/application/php-7.0.18 \
--with-config-file-path=/application/php-7.0.18/etc \
--with-gd \
--with-iconv=/usr/local/iconv/ \
--with-mcrypt=/usr/local/mcrypt \
--with-mhash=/usr/local/mhash \
--with-jpeg-dir \
--with-freetype-dir \
--with-zlib \
--with-xmlrpc \
--with-gettext \
--with-curl \
--with-openssl \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--enable-mysqlnd \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soap
编译源代码并安装
make && make install
3.后期结尾
给php-7.0.18创建软链接去掉末尾的版本号
ln -s /application/php-7.0.18/ /application/php
添加环境变量
创建php命令软链接到环境变量
ln -s /application/php/sbin/* /usr/local/sbin/
ln -s /application/php/bin/* /usr/local/bin/
配置php
拷贝配置文件
#引擎配置文件:php.ini
cp /tools/php-7.0.18/php.ini-development /application/php/etc/php.ini
#服务配置文件:php-fpm.conf
cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
cp /application/php/etc/php-fpm.d/www.conf.default /application/php/etc/php-fpm.d/www.conf
修改服务配置文件
以nginx身份运行php
sed -i 's#nobody#nginx#g' /application/php/etc/php-fpm.d/www.conf
开启慢查询日志
sed -i 's#;slowlog#slowlog#g' /application/php/etc/php-fpm.d/www.conf
开启邮件设置
sed -i 's#;php_admin_value\[sendmail_path\]#php_admin_value\[sendmail_path\]#g' /application/php/etc/php-fpm.d/www.conf
修改收件人
sed -i 's#www@my.domain#244819336@qq#g' /application/php/etc/php-fpm.d/www.conf
开启pid文件
sed -i 's#;pid#pid#g' /application/php/etc/php-fpm.conf
开启错误日志
sed -i 's#;error_log#error_log#g' /application/php/etc/php-fpm.conf
修改错误级别
sed -i 's#;log_level = notice#log_level = error#g' /application/php/etc/php-fpm.conf
修改文件描述符数量
sed -i 's#;rlimit_files = 1024#rlimit_files = 32768#g' /application/php/etc/php-fpm.conf
修改为异步模型
sed -i 's#;events#events#g' /application/php/etc/php-fpm.conf
5.常用命令
启动php-fpm
php-fpm
-c使用指定的引擎配置文件运行,而非默认
php-fpm -c /application/php/etc/php.ini
停止php-fpm
kill -SIGQUIT $(cat /application/php/var/run/php-fpm.pid) #平滑终止
kill -SIGINT $(cat /application/php/var/run/php-fpm.pid) #立刻终止
重启php-fpm
kill -SIGUSR2 $(cat /application/php/var/run/php-fpm.pid) #平滑重启
信号解释:
SIGINT, SIGTERM 立刻终止
SIGQUIT 平滑终止
SIGUSR1 重新打开日志文件
SIGUSR2 平滑重载所有worker进程并重新载入配置和二进制模块