YII2 Day 8 Configuring multiple versions of PHP

Source: Internet
Author: User

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 and install a higher 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 the default is 9000, so many nginx configuration will have a Fastcgi-pass 127.0.0.1:9000 browser sent to the Nginx application Server nginx PHP request, forwarded to 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:

 
  ./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 the Yii2 used to MCrypt, so add 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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.