Yii2Day8 multi-version PHP configuration

Source: Internet
Author: User
Reason for configuring multi-version PHP in Yii2Day8

Yii2 has the minimum requirements for PHP5.4, but currently many space or hosts and PHP versions remain below 5.3. At this time, there are two options:

Upgrade PHP and install a later version of PHP.

If a site is already running on this server, it is likely that the PHP version will trigger a bunch of warnings or errors for PHP programs that use outdated functions and are not properly used, that is irretrievable. For security reasons, installing a later version of PHP is more conservative. So what if I want Nginx or Apchce to use different versions of PHP? That is PHP-FPM.

PHP-FPM

FastCGI Process Manager, that is, FastCGI Process Manager. Using the PHP-FPM mode to configure the PHP site, a request flow is like this (take Nginx + PHP-FPM as an example ):

PHP-FPM boot listening, 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 the PHP FastCGI process, after the FastCGI process finishes processing the PHP script, it is returned to the application server, and the server is then returned to the browser.

So, let different sites use different PHP versions, you can by forwarding requests to different PHP-FPM processes.

Compile PHP

Download the PHP code of the corresponding version, compile and install it in different paths, and add all 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

Why does Yii2 use mcrypt? With-mcrypt, but if it has not been installed, the configure will report that mcrypt cannot be found. an error such as h indicates that the system has installed the library first. use yum install libmcrypt mcrypt mhash. if you use configure again, no error is reported.

Configure PHP-FPM

After the installation is complete, open the php-fpm.conf, modify the listening port, or modify the sock file name to prevent conflicts with older PHP-FPM processes. Then start the php-fpm process.

Modify site configuration

It is mainly to modify FASTCGI_PASS to 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.