YII2 Day 8 Configuring multiple versions of PHP

Source: Internet
Author: User
Tags configuration php mcrypt

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:

    1. Upgrade PHP Version
    2. 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):

    1. 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
    2. Browser sent to Nginx application server
    3. Nginx to the PHP request, forwarded to the PHP fastcgi process,
    4. 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

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.