Nâng cấp PHP 5.4 cho Kloxo

Nếu bạn đang vận hành webserver chi phí thấp với hệ quản lý hosting Kloxo chắc hẳn bạn biết rằng phiên bản mới nhất hiện tại (Kloxo 6.1.12 phát hành 12/06/2011) được cài đặt sẵn gói PHP 5.2.17. Nhiều mã nguồn CMS, framework hay portal mới hiện nay yêu cầu PHP 5.3.4 trở lên để có thể vận hành tốt. Vậy bạn sẽ làm thế nào để nâng cấp PHP?
Nâng cấp PHP 5.3 cho Kloxo

Nâng cấp PHP 5.4 cho Kloxo

Bài viết này sẽ hướng dẫn các bạn từng bước nâng cấp PHP và các thành phần mở rộng. Các lệnh sau được thực hiện với quyền root và các gói cài đặt dành cho phiên bản CentOS 5.x 32bit.
1. Kiểm tra phiên bản hiện tại của PHP
root@tenten ~]#php -v
PHP 5.2.17 (cli) (built: Dec 18 2013 16:48:28)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd., and
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
2. Tạo file mẫu phù hợp với php 5.4
- Sao lưu file htaccess template: /usr/local/lxlabs/kloxo/file/phpini/htaccesstemp 
root@tenten ~]#mv /usr/local/lxlabs/kloxo/file/phpini/htaccesstemp /usr/local/lxlabs/kloxo/file/phpini/htaccesstemp.bak
- Tạo file htaccess mẫu mới: 
root@tenten ~]#vi /usr/local/lxlabs/kloxo/file/phpini/htaccesstemp
Với nội dung sau: 
php_value upload_max_filesize 128M
php_value max_execution_time  120
php_value max_input_time  -1
php_value memory_limit  128M
php_value post_max_size  128M
php_flag display_errors  __lx__display_error_flag
php_flag file_uploads  __lx__file_uploads_flag
php_flag log_errors  __lx__log_errors_flag
php_flag output_buffering  __lx__output_buffering_flag
php_flag register_argc_argv  __lx__register_argc_argv_flag
php_flag mysql.allow_persistent  __lx__mysql_allow_persistent_flag
php_flag register_long_arrays  __lx__register_long_arrays_flag
php_flag allow_url_fopen  __lx__allow_url_fopen_flag
php_flag cgi.force_redirect  __lx__cgi_force_redirect_flag
php_flag enable_dl  __lx__enable_dl_flag
Lưu file và bảo vệ file tránh bị thay thế khi update kloxo.
root@tenten ~]#chattr +i /usr/local/lxlabs/kloxo/file/phpini/htaccesstemp
3. Tạo file mặc định của php.ini 
root@tenten ~]#mv /usr/local/lxlabs/kloxo/file/phpini/php.ini.temp /usr/local/lxlabs/kloxo/file/phpini/php.ini.temp.bak
root@tenten ~]#vi /usr/local/lxlabs/kloxo/file/phpini/php.ini.temp
Với nội dung sau:
[PHP]
engine =On
asp_tags =Off
precision =14
output_buffering = __lx__output_buffering_flag
zlib.output_compression = __lx__output_compression_flag
implicit_flush =Off
unserialize_callback_func =
serialize_precision =17
disable_functions = shell_exec
disable_classes =
zend.enable_gc =On
expose_php =Off
max_execution_time =180
max_input_time =-1
memory_limit =512M
error_reporting = E_ALL &~E_NOTICE &~E_DEPRECATED &~E_STRICT
display_errors = __lx__display_error_flag
display_startup_errors =Off
log_errors = __lx__log_errors_flag
log_errors_max_len =1024
ignore_repeated_errors =Off
ignore_repeated_source =Off
report_memleaks =On
track_errors =Off
html_errors =On
variables_order ="GPCS"
request_order ="GP"
register_argc_argv = __lx__register_argc_argv_flag
auto_globals_jit =On
post_max_size =128M
auto_prepend_file =
auto_append_file =
default_mimetype ="text/html"
doc_root =
user_dir =
enable_dl = __lx__enable_dl_flag
file_uploads = __lx__file_uploads_flag
upload_max_filesize =128M
max_file_uploads =20
allow_url_fopen = __lx__allow_url_fopen_flag
allow_url_include = __lx__allow_url_include_flag
default_socket_timeout =60[CLI Server]
cli_server.color =On

[Date]

[filter]

[iconv]

[intl]

[sqlite]

[sqlite3]

[Pcre]

[Pdo]

[Pdo_mysql]
pdo_mysql.cache_size =2000
pdo_mysql.default_socket=

[Phar]

[mail function]
SMTP = localhost
smtp_port =25
sendmail_path =/usr/sbin/sendmail -t -i
mail.add_x_header =On

[SQL]
sql.safe_mode =Off

[ODBC]
odbc.allow_persistent =On
odbc.check_persistent =On
odbc.max_persistent =-1
odbc.max_links =-1
odbc.defaultlrl =4096
odbc.defaultbinmode =1

[Interbase]
ibase.allow_persistent =1
ibase.max_persistent =-1
ibase.max_links =-1
ibase.timestampformat ="%Y-%m-%d %H:%M:%S"
ibase.dateformat ="%Y-%m-%d"
ibase.timeformat ="%H:%M:%S"

[MySQL]
mysql.allow_local_infile =On
mysql.allow_persistent = __lx__mysql_allow_persistent_flag
mysql.cache_size =2000
mysql.max_persistent =-1
mysql.max_links =-1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout =60
mysql.trace_mode =Off

[MySQLi]
mysqli.max_persistent =-1
mysqli.allow_persistent =On
mysqli.max_links =-1
mysqli.cache_size =2000
mysqli.default_port =3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect =Off

[mysqlnd]
mysqlnd.collect_statistics =On
mysqlnd.collect_memory_statistics =Off

[OCI8]

[PostgreSQL]
pgsql.allow_persistent =On
pgsql.auto_reset_persistent =Off
pgsql.max_persistent =-1
pgsql.max_links =-1
pgsql.ignore_notice =0
pgsql.log_notice =0

[Sybase-CT]
sybct.allow_persistent =On
sybct.max_persistent =-1
sybct.max_links =-1
sybct.min_server_severity =10
sybct.min_client_severity =10

[bcmath]
bcmath.scale =0

[browscap]

[Session]
session.save_handler = files
session.save_path = __lx__session_save_path_flag
session.use_cookies =1
session.use_only_cookies =1
session.name = PHPSESSID
session.auto_start =0
session.cookie_lifetime =0
session.cookie_path =/
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability =1
session.gc_divisor =1000
session.gc_maxlifetime =1440
session.bug_compat_42 =Off
session.bug_compat_warn =Off
session.referer_check =
session.cache_limiter = nocache
session.cache_expire =180
session.use_trans_sid =0
session.hash_function =0
session.hash_bits_per_character =5
url_rewriter.tags ="a=href,area=href,frame=src,input=src,form=fakeentry"

[MSSQL]
mssql.allow_persistent =On
mssql.max_persistent =-1
mssql.max_links =-1
mssql.min_error_severity =10
mssql.min_message_severity =10
mssql.compatability_mode =Off
mssql.secure_connection =Off

[Assertion]

[COM]

[mbstring]

[gd]

[exif]

[Tidy]
tidy.clean_output =Off

[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit =5

[sysvshm][ldap]
ldap.max_links =-1

[mcrypt]

[dba]

date.timezone ="Asia/Ho_Chi_Minh"

zend_extension=/usr/lib/kloxophp/ioncube/ioncube_loader_lin_5.4.so
zend_extension=/usr/lib/php/modules/opcache.so
extension=/usr/lib/php/modules/apc.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
opcache.save_comments=0
opcache.enable_file_override=1
Lưu lại và bảo vệ file không bị thay thế khi kloxo update.
root@tenten ~]#chattr +i /usr/local/lxlabs/kloxo/file/phpini/php.ini.temp
4. Cài đặt Remi repository cho PHP 5.4 
root@tenten ~]#rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
root@tenten ~]#rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
5. Nâng cấp phiên bản PHP từ Remi repository
root@tenten ~]#yum -y update php --enablerepo=remi
6. Cài đặt APC cache
root@tenten ~]#pecl install apc
7. Cài đặt Zend Optimizer và IonCube loaders cho PHP 5.4
root@tenten ~]#cd /usr/lib/kloxophp
root@tenten ~]#wget http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz 
root@tenten ~]#tar -xzvf ioncube_loaders_lin_*.tar.gz
root@tenten ~]#curl -Lok https://github.com/zendtech/ZendOptimizerPlus/archive/master.zip
root@tenten ~]#unzip master.zip
root@tenten ~]#cd ZendOptimizerPlus-master
root@tenten ~]#/usr/bin/phpize
root@tenten ~]#./configure --with-php-config=/usr/bin/php-config
root@tenten ~]#make && make install
root@tenten ~]#/script/fixphp
8. Khởi đọng lại dịch vụ web

root@tenten ~]service httpd restart


9. Đến đây thì quá trình nâng cấp PHP và các gói thành phần đã xong
Kiểm tra lại phiên bản php hiện tại: 

[root@tenten ~]# php -v

PHP 5.4.34 (cli) (built: Oct 16 2014 10:19:56) 

Copyright (c) 1997-2014 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

    with the ionCube PHP Loader v4.7.0, Copyright (c) 2002-2014, by ionCube Ltd., and

    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

    with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies