線上伺服器php5.3.8升級到php5.6.3

來源:互聯網
上載者:User
伺服器類型 CentOS 6.5

因為項目要用到php5.4以上的新功能 目前伺服器還是用php5.3.8版本 所以升級版本就非常需要了。


首先 連上伺服器 先把 php-fpm服務關閉 然後 先把 /usr/local/php 重新命名 以防止如果新版本更新失敗 復原


mv /usr/local/php  /usr/local/php5.3.8

然後 下載最新版本php5.6.3 並且解壓


wget  http://www.php.net/distributions/php-5.6.3.tar.gztar -zxvf  php-5.6.3.tar.gz

因為是升級 所以 php很多依賴包我都已經裝過了 先貼上我的 configure 配置參數

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www  --enable-fpm --enable-opcache --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-fileinfo   --with-iconv-dir=/usr/local  --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml   --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl   --enable-mbregex --enable-mbstring  --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash  --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --disable-ipv6  --disable-debug

其中 最為注意的是 開啟 opcache 可以換成opcode 提高php效能

還有 --disable-debug --disable-ipv6 關閉 debug ipv6 可以提升效能


第一次make 出錯了

ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':/home/king/php-5.2.13/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open'collect2: ld returned 1 exit statusmake: *** [sapi/cli/php] Error 1


網上找到解決辦法

在安? PHP 到系統中時要是發生「undefined reference to libiconv_open'」之類的錯誤資訊,那表示在「./configure 」?抓好一些環境變數值。錯誤發生點在建立「-o sapi/cli/php」是出錯,沒?到要 link 的 iconv 函式庫參數。 解決方案:編輯Makefile 大約77 行左右的地方: EXTRA_LIBS = ..... -lcrypt 在最後加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然後重新再次 make 即可。

然後 重新make 順利通過了


make clean  #清除上次編譯產生的 obj檔案make ZEND_EXTRA_LIBS='-liconv'make install

配置 最佳化下 php.ini 具體參數可以百度下 都是比較容易理解的

sed -i 's@^output_buffering =@output_buffering = On\noutput_buffering =@' /usr/local/php/etc/php.inised -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=0@' /usr/local/php/etc/php.inised -i 's@^short_open_tag = Off@short_open_tag = On@' /usr/local/php/etc/php.inised -i 's@^expose_php = On@expose_php = Off@' /usr/local/php/etc/php.inised -i 's@^request_order.*@request_order = "CGP"@' /usr/local/php/etc/php.inised -i 's@^;date.timezone.*@date.timezone = Asia/Shanghai@' /usr/local/php/etc/php.inised -i 's@^post_max_size.*@post_max_size = 50M@' /usr/local/php/etc/php.inised -i 's@^upload_max_filesize.*@upload_max_filesize = 50M@' /usr/local/php/etc/php.inised -i 's@^;upload_tmp_dir.*@upload_tmp_dir = /tmp@' /usr/local/php/etc/php.inised -i 's@^max_execution_time.*@max_execution_time = 5@' /usr/local/php/etc/php.inised -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' /usr/local/php/etc/php.inised -i 's@^session.cookie_httponly.*@session.cookie_httponly = 1@' /usr/local/php/etc/php.inised -i 's@^mysqlnd.collect_memory_statistics.*@mysqlnd.collect_memory_statistics = On@' /usr/local/php/etc/php.ini

剛才裝了 opcache 模組 這裡設定下

sed -i 's@^\[opcache\]@[opcache]\nzend_extension=opcache.so@' $php_install_dir/etc/php.inised -i 's@^;opcache.enable=.*@opcache.enable=1@' $php_install_dir/etc/php.inised -i "s@^;opcache.memory_consumption.*@opcache.memory_consumption=128" $php_install_dir/etc/php.inised -i 's@^;opcache.interned_strings_buffer.*@opcache.interned_strings_buffer=8@' $php_install_dir/etc/php.inised -i 's@^;opcache.max_accelerated_files.*@opcache.max_accelerated_files=4000@' $php_install_dir/etc/php.inised -i 's@^;opcache.revalidate_freq.*@opcache.revalidate_freq=60@' $php_install_dir/etc/php.inised -i 's@^;opcache.save_comments.*@opcache.save_comments=0@' $php_install_dir/etc/php.inised -i 's@^;opcache.fast_shutdown.*@opcache.fast_shutdown=1@' $php_install_dir/etc/php.inised -i 's@^;opcache.enable_cli.*@opcache.enable_cli=1@' $php_install_dir/etc/php.inised -i 's@^;opcache.optimization_level.*@;opcache.optimization_level=0@' $php_install_dir/etc/php.ini

產生下 php-fpm 檔案

vim /usr/local/php/etc/php-fpm.conf[global]pid = /usr/local/php/var/run/php-fpm.piderror_log = /usr/local/php/var/log/php-fpm.loglog_level = notice[www]listen = /tmp/php-cgi.socklisten.backlog = -1listen.allowed_clients = 127.0.0.1listen.owner = wwwlisten.group = wwwlisten.mode = 0666user = wwwgroup = wwwpm = dynamicpm.max_children = 10pm.start_servers = 2pm.min_spare_servers = 1pm.max_spare_servers = 6request_terminate_timeout = 100request_slowlog_timeout = 0slowlog = var/log/slow.log

添加到系統服務

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +x /etc/init.d/php-fpmchkconfig --add php-fpm chkconfig php-fpm on

搞定了啟動

 service  php-fpm start   


最後貼一張 phpinfo圖片





OK 完成 順利的 從 php5.3.8 升級到 php5.6.3

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.