On this today guide I will teach you on how to installing and configuring MultiPHP-FPM version on Debian 9 (Stretch). It will give you more benefits rather than using single PHP version on the same server. For example if you have more than one site on the same server you can swicth to different PHP version whenever you want. Also it will help you if your site app or CMS required older PHP version, for example PHP 5.6 or 7.0 which actually has reached its end of life.
The multiphp-fpm configuration should be run with Nginx web server on any server like vps, cloud or dedicated server. So, simply read the following tutorial to install and configure MultiPHP-FPM on Debian 9 machine.
PREREQUISITES:
* Cloud / VPS / Dedicated Server
* Debian 9 (Stretch) Linux x86_64
* Server Full Root Access
* gNome Terminal for Linux
* PuTTy SSH Client for Windows/Mac
1.) Upgrade System Software and Package
For the newly deployed server, don’t forget run system update in order to get the latests package and security pacth from the official Debian team / OS vendor.
--------------------------------------------------------------------- $ apt update $ apt upgrade -y ---------------------------------------------------------------------
2.) Add PPA Repository for MultiPHP Version
After that, let’s adding PPA (Personal Package Archieve) repository for MultiPHP version to your system.
--------------------------------------------------------------------- $ apt -y install lsb-release apt-transport-https ca-certificates $ wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg $ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php7.3.list ---------------------------------------------------------------------
3.) Run System Update
Then after adding PPA, you need to run system update once again in order the system to take effect with the above PPA.
--------------------------------------------------------------------- $ apt update ---------------------------------------------------------------------
4.) Install MultiPHP Version
Let’s install MultiPHP version or your preffered version to your Debian machine. Simply run the following commands, or you can select one of the following PHP versions which you want to install on your system. This include any PHP extensions and modules, like memcached and redis cache.
--------------------------------------------------------------------- $ apt-get install php5.6 php5.6-common php5.6-mysql php5.6-xmlrpc php5.6-curl php5.6-cgi php5.6-cli php5.6-fpm php5.6-json php-pear php5.6-dev php5.6-imap php5.6-mcrypt php5.6-mbstring memcached php-memcache php5.6-xml php5.6-tidy php5.6-sqlite3 php5.6-xsl php5.6-gmp php5.6-gd zip unzip php5.6-zip php5.6-soap php-redis ---------------------------------------------------------------------
--------------------------------------------------------------------- $ apt-get install php7.0 php-xdebug php-apcu php7.0-common php7.0-mysql php7.0-xmlrpc php7.0-curl php7.0-gd php7.0-cgi php7.0-json php7.0-cli php7.0-fpm php-pear php7.0-dev php7.0-imap php7.0-mcrypt php7.0-mbstring memcached php-memcache php7.0-xml php7.0-tidy php7.0-sqlite3 php7.0-xsl php7.0-gmp php7.0-zip php7.0-soap php-redis ---------------------------------------------------------------------
--------------------------------------------------------------------- $ apt-get install php7.1 php-xdebug php-apcu php7.1-common php7.1-mysql php7.1-xmlrpc php7.1-curl php7.1-gd php7.1-cgi php7.1-json php7.1-cli php7.1-fpm php-pear php7.1-dev php7.1-imap php7.1-mcrypt php7.1-mbstring memcached php-memcache php7.1-xml php7.1-tidy php7.1-sqlite3 php7.1-xsl php7.1-gmp php7.1-zip php7.1-soap php-redis ---------------------------------------------------------------------
--------------------------------------------------------------------- $ apt-get install php7.2 php-xdebug php-apcu php7.2-common php7.2-mysql php7.2-xmlrpc php7.2-curl php7.2-gd php7.2-cgi php7.2-json php7.2-cli php7.2-fpm php-pear php7.2-dev php7.2-imap php-mcrypt php7.2-mbstring memcached php-memcache php7.2-xml php7.2-tidy php7.2-sqlite3 php7.2-xsl php7.2-gmp php7.2-zip php7.2-soap php-redis ---------------------------------------------------------------------
--------------------------------------------------------------------- $ apt-get install php7.3 php-apcu php7.3-common php7.3-mysql php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-cgi php7.3-json php7.3-cli php7.3-fpm php-pear php7.3-dev php7.3-imap php7.3-mbstring memcached php-memcache php7.3-xml php7.3-tidy php7.3-sqlite3 php7.3-xsl php7.3-gmp php7.3-zip php7.3-soap ---------------------------------------------------------------------
--------------------------------------------------------------------- $ apt-get install php7.4 php-apcu php7.4-common php7.4-mysql php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-cgi php7.4-json php7.4-cli php7.4-fpm php-pear php7.4-dev php7.4-imap php7.4-mbstring php7.4-xml php7.4-tidy php7.4-sqlite3 php7.4-xsl php7.4-gmp php7.4-zip php7.4-soap php-redis memcached php-memcache ---------------------------------------------------------------------
--------------------------------------------------------------------- $ apt-get install php8.0 php-apcu php8.0-common php8.0-mysql php8.0-curl php8.0-gd php8.0-cgi php8.0-cli php8.0-fpm php-pear php8.0-dev php8.0-imap php8.0-mbstring php8.0-xml php8.0-tidy php8.0-sqlite3 php8.0-xsl php8.0-gmp php8.0-zip php8.0-soap php-redis memcached php-memcache ---------------------------------------------------------------------
5.) Enable PHP*-FPM.SOCK on Nginx ServerBlock Levels
Make sure to enable one of the following php*-fpm.sock on your Nginx domains serverblock. This should be enabled on your side if you want to run your prefered PHP version on your server. For example I want to enable PHP8.0-FPM on my virtual machine, so I need to uncomment the variable php8.0-fpm.sock.
--------------------------------------------------------------------- # Fastcgi-Cache Config location ~ \.php$ { try_files $uri =404; #fastcgi_pass unix:/run/php/php5.6-fpm.sock; #fastcgi_pass unix:/run/php/php7.0-fpm.sock; #fastcgi_pass unix:/run/php/php7.1-fpm.sock; #fastcgi_pass unix:/run/php/php7.2-fpm.sock; #fastcgi_pass unix:/run/php/php7.3-fpm.sock; #fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_pass unix:/run/php/php8.0-fpm.sock; include fastcgi_params; include fastcgi.conf; fastcgi_param HTTP_PROXY ""; fastcgi_index index.php; # fastcgi_intercept_errors on; } ---------------------------------------------------------------------
PLEASE NOTE: the socket variable should be match with the PHP-FPM Pool Directive which is located at www.conf file inside the pool.d directory. Also if you set to TCP/IP instead of UNIX-Socket connection on your PHP-FPM Pool Directive (www.conf file), you should set it as well at Nginx ServerBlock levels. For example:
--------------------------------------------------------------------- $ "fastcgi_pass 127.0.0.1:9000;" should match to "listen = 127.0.0.1:9000" $ "fastcgi_pass unix:/run/php/php8.0-fpm.sock;" should match to "listen = /run/php/php8.0-fpm.sock" ---------------------------------------------------------------------
--------------------------------------------------------------------- $ nano /etc/php/php.version/fpm/pool.d/www.conf --------------------------------------------------------------------- [www] user = www-data group = www-data listen = /run/php/php8.0-fpm.sock #listen = /run/php/php7.4-fpm.sock #listen = /run/php/php7.3-fpm.sock #listen = /run/php/php7.2-fpm.sock #listen = /run/php/php7.1-fpm.sock #listen = /run/php/php7.0-fpm.sock #listen = /run/php/php5.6-fpm.sock
Well, you can change the above line / variable with the following TCP/IP variable.
--------------------------------------------------------------------- listen = 127.0.0.1:9006 #listen = 127.0.0.1:9005 #listen = 127.0.0.1:9004 #listen = 127.0.0.1:9003 #listen = 127.0.0.1:9002 #listen = 127.0.0.1:9001 #listen = 127.0.0.1:9000 ---------------------------------------------------------------------
6.) Restart PHP-FPM Services
After that, you can restart the following PHP-FPM services.
--------------------------------------------------------------------- $ service php5.6-fpm restart $ service php7.0-fpm restart $ service php7.1-fpm restart $ service php7.2-fpm restart $ service php7.3-fpm restart $ service php7.4-fpm restart $ service php8.0-fpm restart ---------------------------------------------------------------------
7.) Verify Your PHP Version
Now, let’s verify your PHP version using the following commands.
$ php -v $ php5.6 -v $ php7.0 -v $ php7.2 -v $ php7.3 -v $ php7.4 -v $ php8.0 -v
--------------------------------------------------------------------- PHP 8.0.1 (cli) (built: Jan 12 2021 14:01:16) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.1, Copyright (c) Zend Technologies with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans ---------------------------------------------------------------------
CONCLUSION:
Installing and configuring MultiPHP-FPM version on Debian 9 machine is give you more benefits rather than run single PHP version on the same machine, although it may be a bit complicated for you. But you will have more than one PHP version on your server, so you can use one of the available PHP versions on your Debian machine.
———————————————————————