Multiple PHP version on the same server using php-fpm on Ubuntu16.04
Run multiple PHP version on the same server using php-fpm on Ubuntu16.04
After some Google research and some my modification this solution finally worked for me:
Install PHP 5.6, 7.0 and 7.1 as fpm
sudo su add-apt-repository ppa:ondrej/php apt-get update apt-get install libapache2-mod-fastcgi php5.6 php5.6-fpm php5.6-dev php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-zip php5.6-gd php5.6-xml php5.6-curl php5.6-intl php5.6-json php7.0 php7.0-fpm php7.0-dev php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-zip php7.0-gd php7.0-xml php7.0-curl php7.0-intl php7.0-json php7.1 php7.1-fpm php7.1-dev php7.1-mbstring php7.1-mcrypt php7.1-mysql php7.1-zip php7.1-gd php7.1-xml php7.1-curl php7.1-intl php7.1-json
a2enmod actions a2enmod fastcgi Making PHP-FPM use By default PHP-FPM is listening on the socket /var/run/php/php7.0-fpm.sock. It is also possible to make PHP-FPM use a TCP connection. To do this, open /etc/php5/fpm/pool.d/www.conf, /etc/php/7.1/fpm/pool.d/www.conf and /etc/php/7.0/fpm/pool.d/www.conf from VI Editore. Remove comment and make the listen line look as follows: [...] ;listen = /var/run/php/php7.0-fpm.sock listen = /var/run/php/php7.0-fpm.sock ;listen = /var/run/php/php7.1-fpm.sock listen = /var/run/php/php7.1-fpm.sock ;listen = /var/run/php/php5.6-fpm.sock listen = /var/run/php/php5.6-fpm.sock Then reload PHP-FPM: service php7.0-fpm restart service php7.1-fpm restart service php5.6-fpm restart Next go through your Apache configuration and all your vhosts config add below. vi /etc/apache2/sites-available/www.A.com.conf vi /etc/apache2/sites-available/www.B.com.conf vi /etc/apache2/sites-available/www.C.com.conf <VirtualHost *:80> ServerName www.a.com ServerAlias a.com DocumentRoot /var/www/html <Directory /usr/lib/cgi-bin> Require all granted </Directory> <IfModule mod_fastcgi.c> AddHandler php7.0-fcgi .php Action php7.0-fcgi /php7.0-fcgi virtual Alias /php7.0-fcgi /usr/lib/cgi-bin/php7.0-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php7.0-site2-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization </IfModule> </VirtualHost> <VirtualHost *:80> ServerName www.b.com ServerAlias b.com DocumentRoot /var/www/html <Directory /var/www/html> Options FollowSymLinks MultiViews AllowOverride all Require all granted </Directory> <Directory /usr/lib/cgi-bin> Require all granted </Directory> <IfModule mod_fastcgi.c> AddHandler php7.1-fcgi .php Action php7.1-fcgi /php7.1-fcgi virtual Alias /php7.1-fcgi /usr/lib/cgi-bin/php7.1-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php7.1-fcgi -socket /var/run/php/php7.1-fpm.sock -pass-header Authorization </IfModule> </VirtualHost> <VirtualHost *:80> ServerName www.c.com ServerAlias c.com DocumentRoot "/var/www/html" <Directory /usr/lib/cgi-bin> Require all granted </Directory> <IfModule mod_fastcgi.c> AddHandler php5.6-fcgi .php Action php5.6-fcgi /php5.6-fcgi virtual Alias /php5.6-fcgi /usr/lib/cgi-bin/php5.6-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php5.6-fcgi -socket /var/run/php/php5.6-fpm.sock -pass-header Authorization </IfModule> </VirtualHost> Finally reload Apache: service apache2 restart
You can allso load multiple sites using same php fpm servoce by change name live below
add unique name /usr/lib/cgi-bin/php5.6-fcgi to /usr/lib/cgi-bin/php5.6-site6-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7.0-site2-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization
Alias /php7.1-fcgi /usr/lib/cgi-bin/php7.1-site4-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7.1-site4-fcgi -socket /var/run/php/php7.1-fpm.sock -pass-header Authorization
FastCgiExternalServer /usr/lib/cgi-bin/php5.6-site6-fcgi -socket /var/run/php/php5.6-fpm.sock -pass-header Authorization
Making PHP-FPM use a TCP Connection (optional)
NOTE: This chapter shows the configuration of PHP-FPM over TCP. I will show this as a configuration example and there might be setups where you need this e.g. when the FastCGI process runs on a second server, but in general, it is faster to use sockets. So you might want to skip this chapter.
By default PHP-FPM is listening on the socket /var/run/php/php7.0-fpm.sock. It is also possible to make PHP-FPM use a TCP connection. To do this, open /etc/php5/fpm/pool.d/www.conf...
nano /etc/php/7.0/fpm/pool.d/www.conf
... and make the listen line look as follows:
[...] ;listen = /var/run/php/php7.0-fpm.sock listen = 127.0.0.1:9000 [...]
This will make PHP-FPM listen on port 9000 on the IP 127.0.0.1 (localhost). Make sure you use a port that is not in use on your system.
Then reload PHP-FPM:
systemctl reload php7.0-fpm.service
Like above way, you can do for all PHP-FPM versions.
Above all things are working for me. Below are the screenshots.
Comments
Post a Comment