Cause
Yii2 to the minimum requirements PHP5.4, but currently a lot of space or host, PHP version still stay in 5.3 and below. This is the time to face two choices:
- Upgrade PHP Version
- Install a later version of PHP
If you already have a site running on this server, and hastily upgrade the PHP version, it is likely that those who use outdated functions, nonstandard usage of the PHP program to report a bunch of warnings or errors, it will not be undone. For security reasons, it is more conservative to install a later version of PHP. So what if you let Nginx or APCHCE use a different version of PHP? That's php-fpm.
php-fpm
FastCGI process Manager, which is the FastCGI processes manager. Using the PHP-FPM mode configuration PHP site, a request flow is like this (take nginx+php-fpm as an example):
- PHP-FPM start monitoring, usually by default is 9000, so a lot of nginx configuration will have a fastcgi-pass 127.0.0.1:9000
- Browser sent to Nginx application server
- Nginx to the PHP request, forwarded to the PHP fastcgi process,
- After the fastcgi process finishes processing the PHP script, it is returned to the application server and the server is returned to the browser.
So, to have different versions of PHP used by various sites, you can forward requests to different php-fpm processes.
Compiling PHP
Download the appropriate version of the PHP code, compile and install to a different path, add the required extensions as much as possible:
<!-- lang: shell -->./configure --prefix=/usr/local/php-5.5 --with-config-file-path=/usr/local/php-5.5/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-bz2 --with-curl=/usr/bin --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --with-mcrypt=/usr/bin --enable-zip --enable-soap --enable-mbstring --with-gd --with-openssl --enable-pcntl --with-xmlrpc --enable-opcache
Because Yii2 used to mcrypt, so added –with-mcrypt, but if not installed, configure will not find the mcrypt.h and other errors, stating that the system does this library, need to install, using yum install Libmcrypt MCrypt Mhash. Configure again can not be an error.
Configure PHP-FPM
When the installation is complete, open php-fpm.conf, modify the listening port, or modify the sock file name to prevent conflicts with older versions of the PHP-FPM process. Then start the PHP-FPM process.
Modify the Site Configuration
The main thing is to modify the Fastcgi_pass, point to the corresponding listening port or sock file.
YII2 Day 8 Configuring multiple versions of PHP