How to Configure Apache with PHP-FPM handler in ubuntu 20.04
Prerequisite
User with Sudo privileges, Ubuntu version 20.04.
Procedure
Login to the Ubuntu server & follow the below steps to Configure Apache with PHP-FPM handler.
Ensure that all the packages you have installed on your server are up to date, by running the following command you can find it.
$ sudo apt update
If still any packages need to update, run the following command:
$ sudo apt upgrade
Step 1: Add PHP repository $ sudo apt install software-properties-common $ sudo add-apt-repository ppa:ondrej/php Step 2: Update after adding repository $ sudo apt update Step 3: Install PHP-FPM $ sudo apt install php8.1-fpm Step 4: Check status of php8.1-fpm $ sudo systemctl status php8.1-fpm The output should be "active (running)" as mentioned below. OUTPUT:Active: active (running) Step 5: Check apache it is installed or not. Run the following command to check the apache status, $ sudo systemctl status apache2 If not installed, then run the below command. $ sudo apt install apache2 Step 6: Configure Apache with PHP-FPM $ sudo a2dissite 000-default.conf Disable the existing PHP versions $ sudo a2dismod php*.* Here "*.*" will be php versions-5.5, 5.6, 7.0, 7.1. It is based on your php default version, if installed. Disable the Apache prefork module $ sudo a2dismod mpm_prefork Enable the Apache Event module $ sudo a2enmod mpm_event proxy_fcgi setenvif Now enable the PHP-FPM Configuration $ sudo a2enconf php8.1-fpm Enable HTTP2 module $ sudo a2enmod http2 Configuration of Apache with PHP-FPM is done. Step 7: Configuration on PHP-FPM $ sudo vim /etc/php/8.1/fpm/php.ini Add the required parameters, for example 1.upload_max_filesize 2.post_max_size Save and exit the file. Restart the PHP-FPM after the modification done on php.ini file to take in effect. $ sudo systemctl restart php8.1-fpm Step 8: To configure the Apache Virtual Hosts $ sudo vim /etc/apache2/sites-available/domain_name.conf Modify the configuration file as per the requirements, <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName domain_name ServerAlias www.domain_name DocumentRoot /var/www/domain_name ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> Save and exit the file. Enable the new Apache configuration file for the domain, $ sudo a2ensite domain_name.conf Restart the Apache service, $ sudo systemctl restart apache2 Step 9: To check PHP-FPM with the Apache $ cd /var/www/html/domain_name/public_html $ vim phpinfo.php Add the content and Save & exit the file. Go to the browser and search your domain name or IP address followed by phpinfo.php. You will get the PHP info page and you can conform that Apache is configured with PHP-FPM.