Cantech Knowledge Base

Your Go-To Hosting Resource

How to Install PHP and PHP-FPM on Ubuntu 24.04?

Introduction

If you’re in the process of configuring your web server and would like to install PHP and PHP-FPM on Ubuntu 24.04, you’ve come to the right place! PHP is required for a website or dynamic app

to run successfully, so whether you’re installing WordPress or just creating a new website, getting PHP installed right is the first step toward getting your stack up and running seamlessly.

This beginner’s tutorial will walk you through every step to install PHP 8.3, PHP-FPM, and your web server (Apache or Nginx) on Ubuntu 24.04.
Let’s get started!

What is PHP and PHP-FPM?

PHP (Hypertext Preprocessor) is one of the most widely used server-side scripting languages. From WordPress to Drupal to Joomla, it’s used in some of the most widely known platforms on the internet.

PHP-FPM (FastCGI Process Manager) is a PHP handler that significantly increases the performance of PHP applications; this is especially true when we’re using Nginx. PHP-FPM can manage pools of PHP workers that take care of multiple requests easily and improve the speed of your sites under load. Read more about How to Install Apache, MySQL, PHP (LAMP Stack) on Debian 12.

Prerequisites

Before installing PHP, ensure you have the following:

  • An Ubuntu 24.04 server set up and running
  • A non-root user with sudo access
  • A stable internet connection to download packages

Step 1: Update Your System

We start with a system update every time to ensure we have the latest package information.

sudo apt update 
sudo apt upgrade

Step 2: Install PHP

On Ubuntu 24.04, PHP is available directly from the default APT repositories. You can install it with just a few commands.

Install PHP

sudo apt install php -y

Verify the installation by checking the PHP version:

php -v

Output:

PHP 8.3.10 (cli) (built: Aug 15 2025 17:08:30) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.10, Copyright (c) Zend Technologies
with Zend OPcache v8.3.10, Copyright (c), by Zend Technologies

Install PHP Extensions

PHP extensions add extra features to your PHP setup, such as database support, image processing, and data handling. Many PHP applications and frameworks require these extensions to work properly.

Install common PHP extensions:

sudo apt install -y php-mysql php-xml php-bcmath php-gd php-mbstring php-zip php-curl
    Here’s what these extensions do:

  • php-mysql – Connect PHP applications to MySQL databases
  • php-bcmath – Provide precision math functions
  • php-gd – Enable image processing and manipulation
  • php-xml – Enable XML parsing and support
  • php-curl – Allow communication with other servers via URL requests
  • php-zip – Add support for working with ZIP archives
  • php-mbstring – Handle multibyte string and UTF-8 text formats

To see available PHP extensions for your version, run:

apt-cache search php

To confirm which extensions are installed on your server, use:

Php -m

This will list all active PHP modules, and you should see entries like curl, mbstring, xml, and others depending on your installation.

Step 3: Install PHP-FPM

Now let’s install PHP-FPM, which is especially useful when running Nginx (or if you prefer it over the default Apache mod_php setup):

sudo apt install php-fpm -y

Check the status:

sudo systemctl status php8.3-fpm

You should see active (running), which means it’s working!

Step 4: Configure PHP-FPM with a Web Server

Now, depending on what you’re using, Apache or Nginx, follow the setup below.

Using Apache with PHP-FPM

1. Install Apache (if not already):

sudo apt install apache2 -y

2. Enable Required Modules:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm

3. Restart Apache:

sudo systemctl restart apache2

Apache will now forward PHP requests to PHP-FPM!

Using Nginx with PHP-FPM

1. Install Nginx:

sudo apt install nginx -y

2. Configure Nginx to Use PHP-FPM:

Open your default server block:

sudo nano /etc/nginx/sites-available/default

Look for the location ~ \.php$ block and edit it like this:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}

3. Restart Nginx:

sudo systemctl restart nginx

Need a full server stack? Here’s a step-by-step guide on how to install Apache, MySQL, PHP (LAMP Stack) on Rocky Linux 9.

Step 5: Test Your PHP Installation

Let’s create a quick test file to make sure everything is working:

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

Now visit: http://your_server_ip/info.php

PHP Version | Cantech

Don’t forget to delete it afterward to avoid exposing sensitive server info:

sudo rm /var/www/html/info.php

Bonus: Want to Install PHP 8.4 or Multiple Versions?

If you need PHP 8.4 (or multiple PHP versions), you can add the Ondřej Surý PPA that is trusted by the community:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.4 php8.4-fpm

You can switch between PHP versions in Apache using:

sudo a2dismod php8.3
sudo a2enmod php8.4
sudo systemctl restart apache2

Security Tip

If you’re using PHP-FPM with public-facing servers, ensure:

  • You’ve disabled display_errors in production.
  • You’re regularly updating PHP with sudo apt upgrade.
  • You monitor for slow or malicious PHP scripts using logs.

Conclusion

And that’s it! You have learned how to install PHP and PHP-FPM in Ubuntu 24.04 and set it all up to work with Apache or Nginx. Whether you are starting a blog, creating APIs, or building Laravel/WordPress, this is a fast, dependable, and production-ready setup.

FAQs

How to install PHP in Ubuntu?

To install PHP in Ubuntu, update the package list with sudo apt update, then run sudo apt install php -y.
Check with php -v Also, Read about How To Install PHP 8 on Debian 11.

What is PHP-FPM, and why use it?

PHP-FPM (FastCGI Process Manager) optimizes PHP performance and is best suited for Nginx-based setups for efficient request handling.

Can I run both Apache and Nginx with PHP-FPM?

Yes, but it’s uncommon. Choose one web server and configure PHP-FPM accordingly.

How do I change PHP versions?

Use update-alternatives for CLI and a2dismod / a2enmod for Apache to switch between versions.

How do I check the PHP-FPM status?

Run: sudo systemctl status php8.3-fpm

September 6, 2025