Run multiple PHP versions on the same server using php-fpm in linux, install with fastcgi(FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features (mostly) useful for heavy-loaded sites.
)
Install php 5.6 and 7.1 as fpm in linux 16.04
)
Install php 5.6 and 7.1 as fpm in linux 16.04
sudo su
add-apt-repository ppa:ondrej/php
apt-get update
Enables apache modules to support FPMapt-get install libapache2-mod-fastcgi php5.6-fpm php5.6 php5.6-dev php5.6-mcrypt php5.6-mbstring php5.6-mysql php5.6-zip php5.6-gd php5.6-xml php7.1-fpm libapache2-mod-fastcgi php7.1-fpm php7.1 php7.1-dev php7.1-mbstring php7.1-mysql php7.1-zip php7.1-gd php7.1-xml php7.1-curl php7.1-intl php7.1-json php7.1-mcrypt
Add handlers for both version to your Apache vhost , Example of Php 5.6 version using virtual hosta2enmod actions
a2enmod fastcgi
let's create a virtual host to access php version on each site different.
Create directory to for the website
sudo mkdir var/www/html/example
create a file sudo nano /etc/apache2/sites-available/example.conf
Now, add this to use php.5.6 to example.conf<VirtualHost *:80> ServerName example.local ServerAlias www.example.local ServerAdmin admin@example.local DocumentRoot /var/www/html/example <Directory /var/www/html/example> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
final complete output is example.conf is<IfModule mod_fastcgi.c> AddHandler php56-fcgi-www .php Action php56-fcgi-www /php56-fcgi-www Alias /php56-fcgi-www /usr/lib/cgi-bin/php56-fcgi-www FastCgiExternalServer /usr/lib/cgi-bin/php56-fcgi-www -socket /run/php/php5.6-fpm.sock -pass-header Authorization <Directory "/usr/lib/cgi-bin"> Require all granted </Directory> </IfModule> <IfModule mod_fastcgi.c> <FilesMatch ".+\.ph(p[345]?|t|tml)$"> SetHandler php56-fcgi-www </FilesMatch> </IfModule>
if you would like to use php7.1 Then use this code and replace with php5.6 code in example.conf file<VirtualHost *:80> ServerName example.local ServerAlias www.example.local ServerAdmin admin@example.local DocumentRoot /var/www/html/test <Directory /var/www/html/test> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> <IfModule mod_fastcgi.c> AddHandler php56-fcgi-www .php Action php56-fcgi-www /php56-fcgi-www Alias /php56-fcgi-www /usr/lib/cgi-bin/php56-fcgi-www FastCgiExternalServer /usr/lib/cgi-bin/php56-fcgi-www -socket /run/php/php5.6-fpm.sock -pass-header Authorization <Directory "/usr/lib/cgi-bin"> Require all granted </Directory> </IfModule> <IfModule mod_fastcgi.c> <FilesMatch ".+\.ph(p[345]?|t|tml)$"> SetHandler php56-fcgi-www </FilesMatch> </IfModule> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
We can use the a2ensite tool to enable each of our sites like this:<IfModule mod_fastcgi.c>
AddHandler php71-fcgi-www .php
Action php71-fcgi-www /php71-fcgi-www
Alias /php71-fcgi-www /usr/lib/cgi-bin/php71-fcgi-www
FastCgiExternalServer /usr/lib/cgi-bin/php71-fcgi-www -socket /run/php/php7.1-fpm.sock -idle-timeout 1800 -pass-header Authorization
<Directory "/usr/lib/cgi-bin">
Require all granted
</Directory>
</IfModule>
<IfModule mod_fastcgi.c>
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler php71-fcgi-www
</FilesMatch>
</IfModule>
restart serversudo a2ensite test.conf
sudo service apache2 restart
Add to file /etc/hostsNow run in the browser127.0.0.1 example.local www.example.local
example.local
No comments:
Post a Comment