Apache multi-virtual host multi-version PHP (5.3+5.6+N) coexistence operation configuration whole process

Abstract: In order to run multiple different versions of PHP programs on the same Linux server at the same time, we will use FastCGI to load in this article, and record the process in detail for your reference.

There are many conventional PHP configuration methods, such as CGI, fast-cgi, apache module handle, cli, isapi, etc.

  • CGI (Common Gateway Interface/Common Gateway Interface)
  • Fast CGI (Resident CGI / Long-Live CGI)
  • CLI (Command Line Run/Command Line Interface)
  • Module handle (the mode in which web servers such as Apache run, php5_module)
  • ISAPI (Internet Server Application Program Interface, a way to load PHP dlls on IIS)

Due to the different configuration methods, there will be different advantages and disadvantages. The methods of loading modules such as FastCGI and Module handle are often used in web development. There are also other configuration methods that are not mentioned in this article. Please find relevant articles at the end of the article for reference.

In order to run multiple different versions of PHP programs on the same Linux server at the same time, in this article, we will use FastCGI to load, and record the process in detail for your reference. In addition, please refer to the previous configuration of the same version on Window. The published article  Apache multi-virtual host and multi-version PHP (5.2+5.3+5.4) coexist and configure the whole process .

Prepare

Centos7.1 (other versions are similar), mod_fcgid2.3.6, httpd-2.2.31

Note: The toolkit software involved in this article will be provided at the end of the article.

Install service base components

1. Install and compile related dependencies

yum install httpd-devel apr apr-devel libtool

2.pr:

tar xf apr-1.5.2.tar.bz2
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install

3.apr-util :

tar xf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-apr=/usr/local/apr/ make && make install

4. Install pcre-devel

yum -y install pcre-devel

checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ ——Resolve errors during httpd compilation, no installation required pre-installed.

5. Install SSL

yum install openssl-devel
yum update openssl

checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures ——Resolve errors during httpd compilation. Those that are not installed need to be pre-installed.

Compile and install httpd

./configure --prefix=/usr/local/apache \
 --sysconfdir=/etc/httpd \
--enable-so \
--enable-ssl \ --enable-cgi \ --enable-rewrite \ --with-zlib \ --with-pcre \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --enable-modules=all \ --enable-mpms-shared=all \ --with-mpm=event make && make install

 

Compile and install mod_fcgid.so-2.3.6

[root@localhost mod_fcgid-2.3.6]# APXS=/usr/local/apache/bin/apxs ./configure.apxs
[root@localhost mod_fcgid-2.3.6]# make && make install

APXS="The path assigned is the location of the apxs file in your httpd directory"

After the compilation and installation is completed, it will be automatically compiled into the modules in the httpd directory.

It needs to be explained here that if you use apxs -i -a -c mod_fcgid.so to install, there will be some problems, which will cause httpd to terminate when loading conf.

Using mod_fcgid higher than version 2.3.6 or above, such as 2.3.9 (the version provided by the official website) has been tested, and an undefined symbol error will appear in httpd2.4.23 and httpd2.2.31. The content is as follows:

undefined symbol: set_access_info

Also the error states:

[root@localhost mod_fcgid-2.3.6]# make && make install
Makefile:29: /rules.mk: No such file or directory
make: *** No rule to make target `/rules.mk'.  Stop.

If a similar error occurs, the quickest way is to delete the current folder, re-extract mod_fcgid or httpd and compile it.
 

Configure virtual hosts

1. Configure the main httpd.conf

vi /etc/httpd/httpd.conf
#在DSO下增加以下内容
LoadModule fcgid_module modules/mod_fcgid.so
#在文件尾部增加
Include "vhost/*.conf"

Such as:

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so # LoadModule fcgid_module modules/mod_fcgid.so AddHandler fcgid-script .fcgi .php #映射fcgi执行脚本 # 设置PHP_FCGI_MAX_REQUESTS大于或等于FcgidMaxRequestsPerProcess,防止php-cgi进程在处理完所有请求前退出 FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 #php-cgi每个进程的最大请求数 FcgidMaxRequestsPerProcess 1000 #php-cgi最大的进程数 FcgidMaxProcesses 3 #最大执行时间 FcgidIOTimeout 120 FcgidIdleTimeout 120 #限制最大请求字节 (单位b) FcgidMaxRequestLen 2097152 <IfModule !mpm_netware_module> <IfModule !mpm_winnt_module> ... 省略内容 .... NameVirtualHost *:80 Include "vhost/*.conf"

2. Configure virtual host conf

Create a virtual host configuration directory

mkdir /usr/local/apache/vhost/
vi /usr/local/apache/vhost/default.conf vi /usr/local/apache/vhost/php534.conf

~vhost/default.conf

<VirtualHost *:80>
    ServerName default
    DocumentRoot "/mnt/web/default/wwwroot"
    ServerAlias php5629.hk.explame.com
    ErrorLog "/mnt/web/default/log/error.log"
    CustomLog "/mnt/web/default/log/access.log" common FcgidInitialEnv PHPRC "/usr/local/php/php5.6.29/" FcgidWrapper "/usr/local/php/php5.6.29/bin/php-cgi" .php #采用fcgid将不再支持 php_admin_value open_basedir .:/tmp/ 设置方式。 #设置目录访问权限,如出现上传写入问题,请设置php.ini中 upload_tmp_dir = /tmp/ </VirtualHost>

 

~vhost/php534.conf

<VirtualHost *:80>
    ServerName php534
    DocumentRoot "/mnt/web/php534/wwwroot"
    ServerAlias php534.hk.explame.com
    ErrorLog "/mnt/web/php534/log/error.log"
    CustomLog "/mnt/web/php534/log/access.log" common
    FcgidInitialEnv PHPRC "/usr/local/php/php5.3.4/" FcgidWrapper "/usr/local/php/php5.3.4/bin/php-cgi" .php </VirtualHost>

 

Compile and install PHP

1. Prepare dependencies

# c和c++编译器
yum install -y gcc gcc-c++
# PHP扩展依赖
yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel

1. Install PHP5.6.29

wget -O php-5.6.29.tar.bz2 http://cn2.php.net/get/php-5.6.29.tar.bz2/from/this/mirror
tar -xvjf php-5.6.29.tar.bz2
cd php-5.6.29
./configure --prefix=/usr/local/php/php5.6.29/\
 --with-libdir=lib64\
 --enable-fpm\
 --with-fpm-user=php-fpm\ --with-fpm-group=www\ --enable-mysqlnd\ --with-mysql=mysqlnd\ --with-mysqli=mysqlnd\ --with-pdo-mysql=mysqlnd\ --enable-opcache\ --enable-pcntl\ --enable-mbstring\ --enable-soap\ --enable-zip\ --enable-calendar\ --enable-bcmath\ --enable-exif\ --enable-ftp\ --enable-intl\ --with-openssl\ --with-zlib\ --with-curl\ --with-gd\ --with-zlib-dir=/usr/lib\ --with-png-dir=/usr/lib\ --with-jpeg-dir=/usr/lib\ --with-gettext\ --with-mhash\ --with-ldap make && make install

2. Install PHP5.3.3

wget http://museum.php.net/php5/php-5.3.4.tar.bz2
tar -xvjf php-5.3.4.tar.bz2
cd php-5.3.4
#php5.3 额外安装
yum -y install libevent libevent-dev libevent-devel
./configure \
--prefix=/usr/local/php/php5.3.4/ \ --with-openssl \ --enable-mbstring \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir \ --enable-xml make && make install

The configuration and compilation methods of other versions are similar. At least two PHP versions are installed to configure multiple virtual hosts and multiple PHP versions.

The low version of PHP will encounter many problems during the installation process. This article ignores some common ones. Please refer to the network for solutions.

Subsequent expansion 5.3 Compilation parameters

./configure \
--prefix=/usr/local/php/php5.3.28/ \ --with-freetype-dir \ --with-png-dir \ --with-libxml-dir \ --with-iconv=/usr/local\ --enable-xml \ --enable-mysqlnd\ --with-mysql=mysqlnd\ --with-mysqli=mysqlnd\ --with-pdo-mysql=mysqlnd\ --enable-pcntl\ --enable-mbstring\ --enable-soap\ --enable-zip\ --enable-calendar\ --enable-bcmath\ --enable-exif\ --enable-ftp\ --enable-intl\ --with-openssl\ --with-zlib\ --with-curl\ --with-gd\ --with-zlib-dir=/usr/lib\ --with-png-dir=/usr/lib\ --with-jpeg-dir=/usr/lib\ --with-gettext\ --with-mhash\ --with-ldap

The solution to the error encountered when compiling:

undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'

 https://www.cnblogs.com/ttiandeng/p/7867226.html

 

Test Results

php5.6.29

Load the default phpinfo, the average speed is about 1s.

Output ordinary characters, the average speed is about 95ms.

php5.3.4

Loading the default phpinfo, the average speed is about 500ms, which is twice as fast as 5.6.

 

Output ordinary characters, the average speed is about 100ms.

PHP5.6 loads more modules than PHP5.3 in this process, and the overall speed is still improved a lot. For actual project testing, please study it yourself.

Knot

The final version available after testing is

Centos7.1 + mod_fcgid-2.3.6 + httpd-2.2.31 + PHP*

This article is measured content, only personal opinion, if you have any questions, please leave a message at the bottom of the article. Thanks!

related articles:

PHP operating mode   http://blog.csdn.net/hguisu/article/details/7386882

Apache mirror site   http://mirrors.cnnic.cn/apache/httpd/

PHP Historical Versions   http://php.net/releases/

mod_fcgid-2.3.6   ftp://ftp.ucsb.edu/pub/mirrors/apache/httpd/mod_fcgid/mod_fcgid-2.3.6.tar.bz2

https://my.oschina.net/u/2366984/blog/809833

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326352813&siteId=291194637