Skip to content

How to Install Apache & PHP-FPM on Debian 12/11

Advertisement

Apache is one of the most popular open-source web servers available. It’s incredibly powerful, capable of serving a high number of requests per second. PHP-FPM is an efficient method used to deliver PHP content on high-traffic servers. When combined, they can efficiently serve dynamic PHP applications.

In this article, we will guide you on how to install Apache and PHP-FPM on Debian 12/11 Linux system.

Prerequisites

  • A running Debian 12/11 Linux system.
  • Root or sudo access to the system.

Step 1: Update the System

First, it is always a good practice to update the system packages. Run the following command in your terminal:

sudo apt update 
sudo apt upgrade -y 

This command will fetch the list of available packages and update them.

Step 2: Install Apache

After updating the system, you can install Apache with the following command:

sudo apt install apache2 -y 

When the installation is complete, you can check the status of Apache using the command:

sudo systemctl status apache2 

If Apache is running properly, you will see “active (running)” in the output.

Step 3: Install PHP-FPM and necessary PHP modules

The next step is to install PHP-FPM. Debian 12/11 may already have PHP in its repository. Install PHP-FPM and necessary PHP modules with the following command:

sudo apt install php-fpm php-mysql -y 

This will install PHP-FPM and the PHP MySQL extension. If you need any other PHP extensions, you can install them similarly.

Check the status of the PHP-FPM service by running:

sudo systemctl status php7.4-fpm 

The PHP-FPM service should now be active and running.

Step 4: Configuring Apache to use PHP-FPM

By default, Apache uses the PHP module to process PHP files. To change this to PHP-FPM, we first need to disable the PHP module. Execute the following command:

sudo a2dismod php7.4 

Next, enable the necessary proxy modules and the proxy_fcgi module:

sudo a2enmod proxy_fcgi setenvif 

Now, we need to enable the PHP-FPM configuration for Apache.

sudo a2enconf php7.4-fpm 

Ensure you’ve enabled the php7.4-fpm.conf file. It’s provided by the PHP-FPM package and instructs Apache to pass PHP requests to FPM via a Unix socket.

Restart Apache to implement these changes:

sudo systemctl restart apache2 

Step 5: Testing the Configuration

After configuring Apache to use PHP-FPM, we should test it to ensure it works correctly. We can create a phpinfo() file, which displays the details of your PHP configuration. Run the following command to create the file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php 

Now, open a web browser and navigate to http://your-server-ip/info.php. You should see the PHP configuration page showing that the Server API is FPM/FastCGI, which indicates that Apache is indeed using PHP-FPM.

Conclusion

You have successfully installed Apache with PHP-FPM on Debian 12/11. This powerful combination allows you to serve dynamic PHP applications efficiently. Always ensure to keep your system and services updated for the best security and performance.

This tutorial provided a basic configuration to get you started. However, both Apache and PHP-FPM have a wide range of configurations that can be adjusted according to your specific needs. Make sure to look into further optimizations and security measures.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top