Install Apache with PHP & FastCGI on CentOS/RHEL
You can also visit the previous tutorial to configure Apache with multiple PHP versions using PHP-FPM/FastCGI on Ubuntu systems.
Apache Installation
Apache packages are available under default repositories. SSH to your Ubuntu 18.04 LTS system with sudo privileges account and install Apache web server from the official repository.
PHP Installation
For the PHP installation we recommend to use ppa:ondrej/php PPA, which provides latest PHP versions for Ubuntu systems. Use the below couple of commands to add the PPA to your system. Then install PHP 7.3 the latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages. After installing above packages php7.3-fpm service will automatically be started. You can make sure by typing below command on terminal.
Apache Configuration
Now enable few modules required for the configuration of multiple PHP versions with Apache. These modules are necessary to integrate PHP FPM and FastCGI with Apache server. Let’s configure the Apache VirtualHost to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost. Update the configuration as followings.
Save your changes to the configuration file and restart Apache to reload the changes.
Test Setup
Create a PHP script with phpinfo() function and place it to your server document root. Use below command to do it. Now access the info.php using server IP address (for default VirtualHost) for your configured domain in Apache VirtualHost.
Conclusion
You have successfully configured a Apache with PHP-FPM on your Ubuntu 18.04 (Bionic) LTS. You can now host a website from your server.