程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> Linux編譯升級php的詳細方法

Linux編譯升級php的詳細方法

編輯:PHP綜合
服務器環境:CentOS – 5.4
php升級:5.4.14 - 5.5.0
升級心得:比較順利,但是有一點需要說明:eaccelerator無法兼容php5.5.0,好在php在5.5.0默認提供了Zend OPcache,所以一直習慣eaccelerator的朋友如果要升級到php5.5.0的話,可能要暫時和eaccelerator說bye bye了。
1、安裝php5.5.0
下載php安裝包:http://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

# 編譯安裝
./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

這裡有幾個地方需要說明一下:
安裝時,請根據自己的情況添加、刪除附加組建,修改對應的目錄路徑
安裝的時候別忘記了搭配opcache:–enable-opcache
php-5.3.10編譯時加了–enable-safe-mode選項,但是php-5.4.0已經去掉了該選項,編譯時可以 ./configure –help | grep “safe-mode” 查看一下,沒有信息輸出,表示已經不支持!
同樣去處的還有:'–enable-discard-path','–enable-fastcgi','–enable-force-cgi-redirect','–with-curlwrappers'
2.編譯安裝php5.5.0擴展模塊:
安裝imagick
安裝這個模塊需要服務器支持ImageMagick,這裡和升級php無關,這部分省略,需要的請自行搜索
下載地址:http://pecl.php.net/package/imagick
復制代碼 代碼如下:
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

注意:
避免兼容問題,請使用最新版本,請不要使用3.0.1之前的版本
如果安裝的時候報錯make: *** [imagick_file.lo] 錯誤 1,請調用pkgconfig
以上目錄路徑請根據個人情況進行修改
安裝memcache:
安裝這個模塊需要服務器支持memcached,這裡和升級php無關,這部分省略,需要的請自行搜索
下載地址:http://pecl.php.net/package/memcache
復制代碼 代碼如下:
tar xvzf memcache-3.0.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

注:請不要使用2.2.6及以下版本,不兼容
安裝phpredis-master
安裝這個模塊需要服務器支持redis,這裡和升級php無關,這部分省略,需要的請自行搜索
下載地址:https://github.com/nicolasff/phpredis
復制代碼 代碼如下:
unzip master
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

至此,所有需要的模塊都安裝完畢。
3.配置php.ini
復制代碼 代碼如下:
vi /usr/local/webserver/php-d/php-5.5.0/etc/php.ini

# 找到extension_dir
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
date.timezone = Asia/Shanghai

# 找到session.save_handler
session.save_handler = redis

# 找到session.save_path
session.save_path = "tcp://127.0.0.1:6379?weight=1"

配置Zend OPcache
一直以來都習慣用eAccelerator為php提供加速,但是目前有兩個問題:
eAccelerator暫時不兼容php5.5.0
eAccelerator和Zend Opcache沖突
好在php5.5.0默認提供了Zend Opcache為php加速,配置方法如下:
復制代碼 代碼如下:
zend_extension = /usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
; 上面zend_extension路徑為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擴展模塊找不到opcache.so說明沒有安裝成功,請重新安裝
4.配置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.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 = 0
request_terminate_timeout = 0
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 [email protected]
php_flag[display_errors] = on

備注:請根據自己的情況修改配置文件
5.修改啟動項:
復制代碼 代碼如下:
cp /usr/local/webserver/php-d/php-5.5.0/bin/php /etc/init.d/php
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved