首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

Linux 手動編譯升級 PHP 5.5.0 完整實戰筆記(含擴充模組與 OPcache)

     編輯:PHP 相關知識

環境與升級背景

  • 作業系統:CentOS 5.4
  • PHP 版本:5.4.14 → 5.5.0
  • 關鍵變化:PHP 5.5 內建 Zend OPcache,eAccelerator 不再相容,需遷移至 OPcache。

一、PHP 5.5.0 編譯安裝

1.1 下載與解壓

wget https://www.php.net/get/php-5.5.0.tar.gz/from/a/mirror
tar zxvf php-5.5.0.tar.gz
cd php-5.5.0

1.2 編譯參數(依實際路徑調整)

./configure \
--prefix=/usr/local/webserver/php-d/php-5.5.0 \
--with-config-file-path=/usr/local/webserver/php-d/php-5.5.0/etc \
--with-config-file-scan-dir=/usr/local/webserver/php-d/php-5.5.0/etc/php.d \
--with-curl=/usr/local/lib \
--with-freetype-dir=/usr/lib64 \
--with-gd \
--with-gettext \
--with-iconv-dir=/usr/local/lib \
--with-jpeg-dir=/usr/lib64 \
--with-kerberos \
--with-ldap \
--with-ldap-sasl \
--with-libdir=lib64 \
--with-libxml-dir=/usr/lib64 \
--with-mcrypt \
--with-mhash \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex=/usr \
--with-pdo-mysql=shared \
--with-pdo-sqlite=shared \
--with-pear=/usr/local/lib/php \
--with-png-dir=/usr/lib64 \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--disable-rpath

make ZEND_EXTRA_LIBS='liconv'
make install
cp php.ini-production /usr/local/webserver/php-d/php-5.5.0/etc/php.ini

注意:

  • PHP 5.4 移除 --enable-safe-mode、--enable-discard-path、--enable-fastcgi、--enable-force-cgi-redirect、--with-curlwrappers 等選項。
  • 務必加上 --enable-opcache 取代 eAccelerator。

二、常用擴充模組編譯安裝

2.1 imagick

wget https://pecl.php.net/get/imagick-3.1.0RC2.tgz
tar xvzf imagick-3.1.0RC2.tgz
cd imagick-3.1.0RC2
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
./configure --with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make && make install

需先安裝 ImageMagick;建議使用 3.1.0+ 版本相容 PHP 5.5。

2.2 memcache

wget https://pecl.php.net/get/memcache-3.0.8.tgz
tar xvzf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make && make install

需先安裝 memcached;避免使用 2.2.6 以下版本。

2.3 phpredis

wget https://github.com/nicolasff/phpredis/archive/master.zip
unzip master.zip
cd phpredis-master
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
./configure --enable-redis --with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make && make install

三、php.ini 關鍵配置

extension_dir = "/usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/"
extension = "imagick.so"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "redis.so"

date.timezone = Asia/Shanghai

session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379?weight=1"

; Zend OPcache 配置
zend_extension = /usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

四、php-fpm.conf 生產環境範例

pid = /usr/local/webserver/php-d/php-5.5.0/var/run/php-fpm.pid
error_log = /usr/local/webserver/php-d/php-5.5.0/logs/php-fpm.log
log_level = notice

emergency_restart_threshold = 10
emergency_restart_interval = 60s
process_control_timeout = 5s
daemonize = yes

rlimit_files = 65535
rlimit_core = 0

user = www
group = www

listen = 127.0.0.1:9000
listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
listen.allowed_clients = 127.0.0.1

pm = static
pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 1024

ping.response = pong
slowlog = /usr/local/webserver/php-d/php-5.5.0/logs/$pool.log.slow
request_slowlog_timeout = 10s
request_terminate_timeout = 30s
catch_workers_output = yes

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f admin@example.com
php_flag[display_errors] = on

五、啟動腳本整合

cp /usr/local/webserver/php-d/php-5.5.0/bin/php /etc/init.d/php
# 建議撰寫對應的 init.d 腳本管理啟停

驗證升級

重啟 php-fpm 後,瀏覽 phpinfo() 確認版本為 5.5.0、OPcache 啟用、擴充模組載入正常。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved