Category Archives: Howto Tutorials (EN)

Knowledge Network for Tutorials, Howto’s, Workaround, DevOps Code for Professionals.

Multiple PHP-FPM versions with Apache on Debian 12

The Apache web server provide virtual hosts to support multiple domains on a single instance, and PHP-FPM manage multiple PHP versions on a Debian server.

Apache WebserverMultiple PHP-FPM versions with Apache on Debian

Together, with Apache and PHP-FPM to hosting multiple PHP web-applications, each using a different version of PHP, all on the same server, and all at the same time. This because different applications may require different versions of PHP, but some server stacks, like a regularly configured LAMP stack, can only manage one. Using Apache with PHP-FPM FastCGI Process Manager is also a more cost-efficient solution than hosting each application on its own instance.

In this tutorial you’ll learn how to deploy two PHP sites on a single instance. Each site will use its own domain, and each domain use its own version of PHP. The first, site1.mydomain will use PHP 8.2. The second, site2.mydomain use PHP 7.4.

Step 1 – Installing PHP Version 8.2 with PHP-FPM

After the requirements are met, install PHP versions 7.4 and 8.2 as well as PHP-FPM and several additional extensions. To achieve this, the Sury PHP repository must first be added to the system.

The installation on Debian is done here as root by using “su -“.
First of all, required service packages are installed.

$ apt install lsb-release apt-transport-https ca-certificates wget gnupg -y

Add the Sury Repository for latest PHP version on the system.

$ 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/php.list

Update the package lists as follows.

$ apt update

Install the Apache web server it is not already done.

$ apt install apache2 -y

Now install PHP 8.2 and PHP-FPM FastCGI Process Manager together with the most important PHP modules.

$ apt install php8.2 php8.2-fpm php8.2-{cli,mysql,imap,intl,apcu,cgi,bz2,zip,mbstring,gd,curl,xml,common,opcache,imagick,libapache2-mod-php8.2,libapache2-mod-fcgid} -y

Step 2 – Installing PHP Version 7.4 with PHP-FPM

Next step repeat the process for PHP version 7.4 with PHP-FPM.

$ apt install php7.4 php7.4-fpm php7.4-{cli,mysql,imap,intl,apcu,cgi,bz2,zip,mbstring,gd,curl,xml,common,opcache,imagick,libapache2-mod-php7.4} -y

quote  As you may have noticed, the libapache2-mod-fcgid package is not included in the command because it was already installed in step 1.

Update the packages as follows.

$ apt update && apt upgrade -y
$ [ -f /run/reboot-required ] && reboot -f

With installing two PHP versions, start the php8.2-fpm service.

$ systemctl start php8.2-fpm

Next, verify the status of the php8.2-fpm service.

$ systemctl status php8.2-fpm

Repeating this process, now start the php7.4-fpm service.

$ systemctl start php7.4-fpm

And verify the status of the php7.4-fpm service.

$ systemctl status php7.4-fpm

Step 3 – Configure Apache for Multiple PHP-FPM versions

Finaly, enable several modules using the Apache helper command so that your Apache2 service work with multiple PHP versions.

$ a2enmod actions fcgid alias proxy_fcgi

Now restart the Apache service to apply your changes.

$ systemctl restart apache2

With this steps you have installed two PHP versions on your server. Next, you’ll create a docroot for each website you want to deploy.

Step 4 – Creating Docroot for 2 Apache Websites

In this step, you will create a document root directory and an index page for each of your two websites.

First, create document root directories for site1.mydomain and site2.mydomain.

$ mkdir /var/www/site1.mydomain
$ mkdir /var/www/site2.mydomain

By default, the Apache webserver runs as a www-data user and www-data group. To ensure that you have the correct ownership and permissions of your website root directories, execute the following commands.

$ chown -R www-data:www-data /var/www/site1.mydomain
$ chown -R www-data:www-data /var/www/site2.mydomain
$ chmod -R 755 /var/www/site1.mydomain
$ chmod -R 755 /var/www/site2.mydomain

Next you’ll create an phpinfo.php file inside each website document root. This will display each website’s PHP version information. Now let’s begin with site1.

$ vi /var/www/site1.mydomain/phpinfo.php

quote Use the editor of your choice, maybe it’s nano, it’s possible for old dudes who can’t replace the heavy rock VIM with anything!

Add the following code into it.

<?php phpinfo(); ?>

Save and close the file. Now copy the phpinfo.php file you created to site2.

$ cp /var/www/site1.mydomain/phpinfo.php /var/www/site2.mydomain/phpinfo.php

The web server should now have the document root directories that each site requires to serve data to visitors. Next, you will configure the Apache web server to work with two different PHP versions.

Step 5 – Configuring Apache for Both Websites

In this step, you’ll create two Apache virtual host configuration files. This will enable your two websites to work simultaneously with two different PHP versions.

In order for Apache to serve this content, it is necessary to create a virtual host file that contains the needed directives. Instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf, you’ll create two new ones inside the directory /etc/apache2/sites-available/.

First create a new Apache virtual host configuration file for the website site1.mydomain. Here you will direct Apache to render content using php8.2.

$ vi /etc/apache2/sites-available/site1.mydomain.conf

Add the following content. Make sure the website DocumentRoot path, ServerName, and PHP version match your setup.

<VirtualHost *:80>
     ServerAdmin admin@site1.mydomain
     ServerName site1.mydomain
     DocumentRoot /var/www/site1.mydomain
     DirectoryIndex phpinfo.php

     <Directory /var/www/site1.mydomain>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

    <FilesMatch \.php$>
      # For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
      SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
    </FilesMatch>

     ErrorLog ${APACHE_LOG_DIR}/site1.mydomain_error.log
     CustomLog ${APACHE_LOG_DIR}/site1.mydomain_access.log combined
</VirtualHost>

In this file you updated the DocumentRoot to your new directory and ServerAdmin to an email that the mydomain site administrator can access. You’ve also updated ServerName, which establishes the base domain for this virtual host configuration, and you’ve added a SetHandler directive to run PHP as a FastCGI Process Manager.

Save and close the file.

Next, create a new virtual host configuration file for the website site2.mydomain. You will specify this subdomain to deploy php7.4.

$ vi /etc/apache2/sites-available/site2.mydomain.conf

Add the following content. Again, make sure the website directory path, ServerName, and PHP version match your unique information.

<VirtualHost *:80>
     ServerAdmin admin@site2.mydomain
     ServerName site2.mydomain
     DocumentRoot /var/www/site2.mydomain
     DirectoryIndex phpinfo.php

     <Directory /var/www/site2.mydomain>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

    <FilesMatch \.php$>
      # For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
      SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>

     ErrorLog ${APACHE_LOG_DIR}/site2.mydomain_error.log
     CustomLog ${APACHE_LOG_DIR}/site2.mydomain_access.log combined
</VirtualHost>

Save and close the file when you are finished. Then check the Apache configuration file for any syntax errors.

$ apachectl configtest

You’ll see the following output.

Syntax OK

Next, enable both virtual host configuration files.

$ a2ensite site1.mydomain
$ a2ensite site2.mydomain

Now disable the default site, since you won’t need it.

$ a2dissite 000-default.conf

Finally, restart the Apache service to implement your changes.

$ systemctl restart apache2

Now that you have configured Apache to serve each site, you will test them to make sure the proper PHP versions are running.

Step 6 – Testing Websites using Apache with PHP-FPM versions

At this step, you have configured two Apache websites to run two different versions of PHP. Now test the results.

Open your web browser and visit both sites http://site1.mydomain and http://site2.mydomain. You will see two pages that look like this.

phpinfo Multiple PHP-FPM versions with Apache on Debian
http://site1.mydomain, PHP Version 8.2.3
phpinfo Multiple PHP-FPM versions with Apache on Debian
http://site2.mydomain, PHP Version 7.4.27

Note the titles. The first page indicates that site1.mydomain deployed PHP version 8.2. The second indicates that site2.mydomain deployed PHP version 7.4.

Step 7 – Finally, clean up no needed files

Now that you’ve tested your sites, remove the phpinfo.php files. Because they contain sensitive information about your server and are accessible to unauthorized users, they pose a security threat. To remove both files, run the following commands.

$ rm -rf /var/www/site1.mydomain/phpinfo.php
$ rm -rf /var/www/site2.mydomain/phpinfo.php

You now have a single Debian 12 server handling two websites with two different PHP versions. PHP-FPM, however, is not limited to this one application.

Conclusion

You have now combined Apache virtual hosts and PHP-FPM to serve multiple websites and multiple versions of PHP on a single server. The only practical limit on the number of PHP sites and PHP versions that your Apache service can handle is the processing power of your instance.

From here you might consider exploring PHP-FPM’s more advanced FastCGI Process Manager features, like its adaptive spawning process or how it can log sdtout and stderr. Alternatively, you could now secure your websites.

PuTTY Help: Command-line Options

PuTTY Help for Options in Command-line

PuTTY Help Command-line Options

PuTTY getting and installing

You can download the PuTTY client for Windows from here, or perform the Windows package installer winget in the command prompt.

C:\> winget install PuTTY

PuTTY terminal client for Windows

PuTTY is still a popular versatile terminal client and is mainly used as an ssh terminal emulator in Windows, commonly used for connecting from Windows to the Linux shell. If you want to use PuTTY or the clone KiTTY in the command line, or for processing in batch files, you will quickly notice that the help option is not available. If you try putty -h or putty -help also the -? option does not get any help.

PuTTY Command-line Options Help

That’s why I’ve listed a collection of all known putty command-line options help here.

-1 and -2: specify an SSH protocol version
-4 and -6: specify an Internet protocol version
-A and -a: control agent forwarding
-agent and -noagent: control use of Pageant for authentication
-C: enable compression
-hostkey: manually specify an expected host key
-i: specify an SSH private key
-L, -R and -D: set up port forwardings
-l: specify a login name
-load: load a saved session
-loghost: specify a logical host name
-m: read a remote command or script from a file
-N: suppress starting a shell or command
-nc: make a remote network connection in place of a remote shell or command
-P: specify a port number
-pgpfp: display PGP key fingerprints
-proxycmd: specify a local proxy command
-pw: specify a password
-restrict-acl: restrict the Windows process ACL
-sercfg: specify serial port configuration
-sessionlog, -sshlog, -sshrawlog: specify session logging
-t and -T: control pseudo-terminal allocation
-v: increase verbosity
-X and -x: control X11 forwarding
protocols: -ssh, -telnet, -rlogin, -raw -serial

PuTTY free SSH client for Windows

PuTTY is a versatile terminal client for Windows. It is the world’s most popular free SSH client. PuTTY supports SSH, telnet, and raw socket connections with full featured terminal emulation. The PuTTY client supports public key authentication and Kerberos single-sign-on. It also includes command-line SFTP and SCP implementations, but without command-line help.

PuTTY Key Features

  • Windows client. Mac and Linux ports exist. No server included.
  • Supports both 32-bit and 64-bit Windows. An MSI installer has been available since 2016.
  • Supports SSH client, telnet client, SFTP client (command line only), and rlogin client. Both SSH2 and SSH1 protocols are supported. Note that use of SSH1 is not recommended for security reasons. Practically all devices support SSH2 these days.
  • Supports public key authentication and Active Directory/Kerberos authentication.
  • File transfers only using a separate command-line programs. No integrated file transfer support.
  • No scripting support, but can be used together with WinSCP.

PuTTY SSH client alternatives

There many SSH clients that are more modern. A major shortcoming of PuTTY is that it does not have integrated file transfers in the client itself. Instead, file transfers have to be done via the command-line options (without help). This is too complicated for most users. WinSCP is a versatile and known popular file transfer client. PuTTY also does not include an SSH server.

KiTTY as a fork from PuTTY version 0.76

KiTTY is a free and open source GPU accelerated terminal emulator for Linux and macOS that focuses on performance and features. It is written in C and Python programming languages. KiTTY is only designed for the Microsoft Windows platform, with all the features from the original software, and adds many others as decribed in this website. Just like the original, KiTTY doesn’t provide any help for options in the command-line.