PHP 7.1.5编译安装
1. 安装基础组件
yum install -y libxml2 libxml2-devel bzip2 bzip2-devel curl-devel libjpeg libjpeg-devel libmcrypt libmcrypt-devel libpng libpng-devel
2. 下载并解压
wget http://mirrors.sohu.com/php/php-7.1.5.tar.gz
tar xzvf php-7.1.5.tar.gz
cd php-7.1.5
3. 编译安装
wget http://mirrors.sohu.com/php/php-7.1.5.tar.gz
tar xzvf php-7.1.5.tar.gz
cd php-7.1.5
编译参数
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-soap \
--with-openssl \
--with-openssl-dir \
--with-mcrypt \
--with-pcre-regex \
--with-zlib \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-mbstring \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-pdo-mysql \
--with-zlib-dir \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd \
--with-mysqli \
--without-pear
~# make && make install
4. 配置文件修改(去掉文件中的注释、空行,[:g/^;/d] 和 [:g/^$/d])
a) 拷贝一份php.ini(默认不配置)
cp /usr/local/php/php-ini.production /usr/local/php/etc/php.ini
php.ini是php运行核心配置文件:
######避免PHP信息暴露在http头中
expose_php = Off
######常用配置
error_reporting = E_ALL & ~E_NOTICE
display_errors = Off
log_errors = On
html_errors = Off
error_log = /var/log/php/php-error.log
ignore_repeated_errors = On
ignore_repeated_source = On
post_max_size = 32M
memory_limit = 512M
max_execution_time = 300
file_uploads = On
upload_tmp_dir = /tmp/www
upload_max_filesize = 8M
session.gc_maxlifetime = 14400
######设置PHP的扩展
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303"
extension=mysqli.so
extension=pdo_mysql.so
extension=opcache.so
extension=redis.so
extension=swoole.so
######设置PHP的时区
date.timezone = PRC
######开启opcache
[opcache]
opcache.enable=1
######设置PHP脚本允许访问的目录(需要根据实际情况配置)
;open_basedir = /usr/share/nginx/html;
b) php-fpm配置文件修改
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
添加如下内容:
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
c) www.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
添加如下内容:
###设置用户和用户组####
[www]
user = www
group = www
### 使用静态进程数max_children=内存/512 ###
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests =0
### 根据nginx.conf中的配置fastcgi_pass unix 设置PHP监听 ###
listen = /tmp/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0777
listen.allowed_clients = 127.0.0.1
listen = 9000
5. 测试php-fpm配置,设置开机自启动
cp /usr/local/src/php-7.1.5/sapi/fpm/php-fpm.service /etc/init.d/php-fpm.service
### 测试配置 ###
/usr/local/php7/sbin/php-fpm -t
### 修改文件权限 ###
chmod 745 /lib/systemd/system/php-fpm.service
### 设置为开机启动 ###
systemctl enable php-fpm.service
### 启动php-fpm ###启动
systemctl start php-fpm.service
参考链接 : http://www.cnblogs.com/doseoer/p/5350944.html