Install multiple PHP engines using FastCGI

1. Giới thiệu:

Bài viết này sẽ hướng dẫn khách hàng cài đặt factcgi và nhiều phiên bản PHP trên cùng một VPS hoặc Server:

Update VPS: yum update
Cài thêm các dịch vụ gói dịch vụ cần thiết:
# yum install libtool httpd-devel apr-devel apr

2. Cài đặt Module Fastcgi:

Dowload mã nguồn fast-cgi về bằng lệnh:
# wget https://www.pccc.com/downloads/apache/current/mod_fastcgi-current.tar.gz
Sau đó tiến hành giải nén tập tin này:

# tar -xzf mod_fastcgi-current.tar.gz
Truy cập vào thư mục fastcgi: # cd mod _fastcgi-current
Thực hiện coppy file Makefile.AP2 thành Makefile: # cp Makefile.AP2 Makefile
Chạy lệnh sau để cài đặt mod-fastcgi:
32bit:
# make top_dir=/usr/lib/httpd
# make install top_dir=/usr/lib/httpd
64bit:
# make top_dir=/usr/lib64/httpd
# make install top_dir=/usr/lib64/httpd
Cấu hình trong file /etc/httpd/conf/httpd.conf
Thêm dòng: LoadModule fastcgi_module modules/mod_fastcgi.so

3. Cài đặt thêm các phiên bản PHP cần thiết:

Dowload mã nguồn các phiên bản PHP về:
php5.3: # wget http://am1.php.net/distributions/php-5.3.28.tar.gz

php5.4: # wget http://am1.php.net/distributions/php-5.4.34.tar.gz

Sau đó tiến hành giải nén các file này bằng lệnh:  # tar –xzvf php-5.xx (tên phiên bản PHP)

Truy cập vào thư mục PHP vừa giải nén: # cd php-5.xx
Tiến hành build PHP như sau:
./configure --prefix=/usr/php5x (đây là đường dẫn tương ứng cho phiên bản php)
Các tham số có thể tham khảo và thêm trong quá trình build PHP
--enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-mbstring --enable-pdo=shared --enable-soap --enable-sockets --enable-wddx --enable-zend-multibyte --enable-zip --with-bz2 --with-curl=/opt/curlssl/ --with-curlwrappers --with-freetype-dir=/usr --with-gd --with-gettext --with-imap=/opt/php_with_imap_client/ --with-imap-ssl=/usr --with-jpeg-dir=/usr --with-kerberos --with-libexpat-dir=/usr --with-libxml-dir=/opt/xml2 --with-libxml-dir=/opt/xml2/ --with-mcrypt=/opt/libmcrypt/ --with-mhash=/opt/mhash/ --with-mysql=/usr --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=/usr/bin/mysql_config --with-openssl=/usr --with-openssl-dir=/usr --with-pcre-regex=/opt/pcre --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-png-dir=/usr --with-pspell --with-sqlite=shared --with-tidy=/opt/tidy --with-xmlrpc --with-xpm-dir=/usr --with-xsl=/opt/xslt/ --with-zlib --with-zlib-dir=/usr
Sau khi build hoàn tất, khách hàng tiến hành chạy lệnh để hoàn tất quá trình build PHP:
# make & make install
Tiếp đến khách hàng copy file php.ini-recommended sang file php.ini tới thư mục vừa build tức là thư mục /usr/php5x bằng lệnh: # cp php.ini-recommended /usr/php5x/php.ini
Tiến hành tạo file wrapper_php5x.fcgi trong /usr/local/ bằng lệnh: vi /usr/local/wrapper_php5x.fcgi có nội dung:
#!/bin/bash
PHP_CGI=/usr/php5x/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI
Phân quyền thực thi cho file vừa tạo: # chmod +x /usr/local/wrapper_php5x.fcgi
Cấu hình trong Virtual Host của website cần chạy phiên bản php riêng biệt:

<VirtualHost *:80>
ServerAdmin liem.tm@vinahost.vn
DocumentRoot "/home/example/public_html"

ServerName example.com
ServerAlias www.example.com
<Directory "/home/example/public_html">

AllowOverride All
AddHandler fcgid-script .cgi .php
FcgidWrapper /usr/local/ wrapper_php5x.fcgi
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Sau đó tiến hành restart lại dịch vụ httpd và tạo file info.php để kiểm tra phiên bản PHP.

 

Powered by WHMCompleteSolution