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