We are going to show you how to install PHP and PHP-FPM on Ubuntu 24.04. PHP, or Hypertext Preprocessor, is a popular open-source programming language used mostly for online development. The only PHP implementation of PHP FastCGI that is really helpful for websites with a lot of traffic is PHP. At the end of this guide, you should be ready to go with PHP running on your server.
PREREQUISITES
- Before we start, please confirm you have the following:
- Ubuntu 24.04 LTS installed on the server
- A user account with the sudo access
- An essential command-line operation understanding
- A reliable internet connection for downloading software packages
To ensure that your system is up to date, run the following commands:
sudo apt update sudo apt upgrade
INSTALL APACHE
Launch the Apache web server using the following command:
sudo apt install apache2
INSTALL PHP
Let’s begin with installing the PHP package in Ubuntu 24.04 server.
First, open a terminal on your Ubuntu system.
PHP and common modules are included in the installation action:
sudo apt install php
That command installs the core PHP package, the command-line interface, and common libraries.
Make sure the installation works:
php -v
INSTALL PHP EXTENSIONS
sudo apt install php8.3-curl php8.3-mbstring php8.3-xml php8.3-mysql php8.3-gd php8.3-zip
Short description:
- php-mysql – Allows MySQL database connection
- php-gd – Adds ability to manipulate images
- php-curl – Makes possible to communicate with servers
- php-mbstring – Provides multibyte string support
- php-xml – Enables XML support
- php-zip – Enables ZIP support
Additional extensions can be installed as you see fit for your projects. You can search
them using:
apt-cache search php-
INSTALL AND CONFIGURE PHP-FPM
PHP-FPM is essential when dealing with high-traffic websites. To install and configure it:
1.Install the package:
sudo apt install php8.3-fpm
2.Launch PHP-FPM service. Depending on the installation, version number may differ.
sudo systemctl start php8.3-fpm
3.Tell PHP-FPM to go on boot:
sudo systemctl enable php8.3-fpm
4.Verify PHP-FPM is working:
systemctl status php8.3-fpm
This will output a response that says „Active (Running)” if everything is working as expected.
CONFIGURATON
1.Set Up Apache for PHP-FPM. Ensure Apache is made compatible for PHP-FPM, by first finding Apache configuration file (usually /etc/apache2/sites-available/your_conf.conf) then inserting:
<FilesMatch \.php$> SetHandler "proxy:unix:/var/run/php/php8.3-fpm.sock|fcgi://localh </FilesMatch>
- OPTIONAL: You can put this line on .htaccess file (this work only for directory where is the .htaccess file)
Remember we must alter specific PHP version and socket path to suit individual settings of the server.
2.Activate PHP and PHP-FPM. Enable PHP and PHP-FPM following these instructions:
sudo apt install libapache2-mod-php sudo a2enmod proxy_fcgi setenvif
3.Reboot Apache. Apply changes by restarting Apache server:
sudo systemctl restart apache2
4.To ensure that PHP and PHP-FPM are both running with no problems, create a test file then serve it via the website’s server. Let’s say it uses Apache in this example:
Generate PHP Info File. To show PHP settings using the phpinfo() function, do the following:
mkdir -p /var/www/html echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
5.Access PHP Info Page. First open your web browser and go to:
http://your_server_ip/info.php




Good tutorial – try to reproduce first on virtual machine