编译安装php7


1、准备php安装环境

1.1、彻底卸载旧版php

rpm -qa | grep php rpm -e php-fpm-5.3.3-22.el6.x86_64 rpm-e php-pdo-5.3.3-22.el6.x86_64 rpm -e php-pear-1.9.4-4.el6.noarch rpm-e php-cli-5.3.3-22.el6.x86_64 rpm -e php-5.3.3-22.el6.x86_64 rpm-e php-xml-5.3.3-22.el6.x86_64 rpm -e php-gd-5.3.3-22.el6.x86_64 rpm-e php-common-5.3.3-22.el6.x86_64


1.2、编译安装pcre、zlib、openssl、curl、libmcrypt、bzip2、openldap、icu等依赖的最新版本

其中ldap需要依赖openssl-devel

pcre:

 

./configure \
--prefix=/opt/pcre-8.39 \
--enable-utf \
--enable-unicode-properties

 

在最新的版本里,编译pcre时不要在使用--enable-utf8,应该使用--enable-utf

curl:

./configure --prefix=/opt/curl-7.50.1 \ --with-nghttp2 \ --with-ssl=/opt/openssl-1.0.2h/ \ --enable-imap \ --enable-stmp \ --enable-pop3 \ --enable-http \ --enable-ftp \ --enable-file \ --enable-ldap \ --enable-ldaps \ --enable-ipv6 \ --enable-libgcc make
make install

bzip2:

make -f  Makefile-libbz2_so make
make install

icu4c:

./configure \ --enable-strict \ --enable-64bit-libs \ --enable-shared \ --enable-static \ --enable-auto-cleanup \ --enable-draft \ --enable-renaming \ --enable-tracing \ --enable-plugins \ --disable-dyload \ --enable-rpath \ --enable-weak-threads \ --enable-extras \ --enable-icuio \ --enable-layout \ --enable-layoutex make
make install


2、安装php

2.1、配置php

./configure --prefix=/opt/php7/ \ --with-pcre-regex=/opt/pcre-8.39/ \ --with-pcre-dir=/opt/pcre-8.39/ \ --with-openssl-dir=/opt/openssl-1.0.2h/ \ --with-openssl=/opt/openssl-1.0.2h/ \ --with-zlib-dir=/opt/zlib-1.2.8/ \ --with-zlib=/opt/zlib-1.2.8/ \ --with-curl=/opt/curl-7.50.1/ \ --with-mcrypt=/opt/libmcrypt-2.5.7/ \ --with-bz2 \ --with-ldap=/opt/openldap-2.4.30/ \ --with-gd \ --with-pdo-mysql=shared,mysqlnd \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libxml-dir \ --with-mhash \ --with-zlib-dir \ --without-pdo-sqlite \ --with-pear \ --with-xmlrpc \ --with-xsl \ --enable-opcache \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-mbregex \ --enable-zip \ --enable-ftp \ --enable-fpm \ --enable-mbstring \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --enable-calendar \ --enable-fpm \ --enable-pcntl \ --enable-shmop \ --enable-exif \ --enable-pcntl \ --enable-wddx \ --enable-intl \ --enable-libgcc

部分配置参数说明:http://php.net/manual/zh/configure.about.php

由于自5.3版本以来的大量特征修改,增删许多核心配置,具体内容可通过configure --help查阅

配置完成后,可见


2.2、安装

make
make test make install

编译完成后,可见

测试完成后,可见

在不同系统环境中,bug数量不相同,failed也不可避免。随着版本逐渐完善,理论上failed会越来越少,但是核心组更原意在新特性和补丁中制造bug


3、配置运行环境

3.1、配置文件位置

cp /opt/php7/etc/php-fpm.d/www.conf.default /opt/php7/etc/php-fpm.d/www.conf cp /opt/php7/etc/php-fpm.conf.default /opt/php7/etc/php-fpm.conf cp /root/php-7.0.10/php.ini-development /opt/php7/lib/php.ini cp /root/php-7.0.10/php.ini-development /opt/php7/lib/php.ini-development cp /root/php-7.0.10/php.ini-production /opt/php7/lib/php.ini-production


3.2、配置php.ini,开启pdo和opcache

在php.ini中加入

extension=/opt/php7/lib/php/extensions/no-debug-non-zts-20151012/pdo_mysql.so zend_extension=/opt/php7/lib/php/extensions/no-debug-non-zts-20151012/opcache.so opcache.enable=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.max_wasted_percentage=10 opcache.use_cwd=0 opcache.validate_timestamps=1 opcache.revalidate_freq=60 opcache.save_comments=0 opcache.load_comments=0 opcache.fast_shutdown=1 opcache.optimization_level=0xffffffff opcache.inherited_hack=1 opcache.force_restart_timeout=300 opcache.error_log=opcache_error_log opcache.log_verbosity_level=1

opcache配置说明:http://php.net/manual/zh/book.opcache.php


3.3、配置php-fpm.conf,开启status查询

echo "[www]">>/opt/php7/etc/php-fpm.conf echo "pm.status_path = /phpfpm_status">>/opt/php7/etc/php-fpm.conf


3.4、配置nginx

在/opt/nginx-1.10.1/conf/nginx.conf中location /{}代码块下方加入

location ~* \.php$ { root /www; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } location /phpfpm_status { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; }


3.5、将php-fpm加入开机启动项

echo "/opt/php7/sbin/php-fpm">> /etc/rc.local


3.5、启动php-fpm,重启nginx

/opt/php7/sbin/php-fpm /opt/nginx-1.10.1/sbin/nginx -s reload


3.6、测试

在/www目录下加入phpinfo.php文件

phpinfo.php:

<?php echo phpinfo(); ?>

status详解:

pool:php-fpm池的名称,一般都是应该是www
process manage:进程的管理方法,php-fpm支持三种管理方法,分别是static,dynamic和ondemand,一般情况下都是dynamic
start time:php-fpm启动时候的时间,不管是restart或者reload都会更新这里的时间
start since:php-fpm自启动起来经过的时间,默认为秒
accepted conn:当前接收的连接数
listen queue:在队列中等待连接的请求个数,如果这个数字为非0,那么最好增加进程的fpm个数
max listen queue:从fpm启动以来,在队列中等待连接请求的最大值
listen queue len:等待连接的套接字队列大小
idle processes:空闲的进程个数
active processes:活动的进程个数
total processes:总共的进程个数
max active processes:从fpm启动以来,活动进程的最大个数,如果这个值小于当前的max_children,可以调小此值
max children reached:当pm尝试启动更多的进程,却因为max_children的限制,没有启动更多进程的次数。如果这个值非0,那么可以适当增加fpm的进程数
slow requests:慢请求的次数,一般如果这个值未非0,那么可能会有慢的php进程,一般一个不好的mysql查询是最大的祸首。
pid:进程PID,可以单独kill这个进程.
state:当前进程的状态 (Idle, Running, …)
start time:进程启动的日期
start since:当前进程运行时长
requests:当前进程处理了多少个请求
request duration:请求时长(微妙)
request method:请求方法 (GET, POST, …)
request URI:请求URI
content length:请求内容长度 (仅用于 POST)
user:用户 (PHP_AUTH_USER) (or ‘-’ 如果没设置)
script:PHP脚本 (or ‘-’ if not set)
last request cpu:最后一个请求CPU使用率。
last request memorythe:上一个请求使用的内存

 

 

 

参考资料:

http://php.net/manual/zh/install.php

https://typecodes.com/web/centos7compilephp7.html

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM