How to Install PHP and PHP-FPM on Ubuntu 24.04
Install and Configure PHP (All Versions) for Your Server
Step 1: Update and Install Dependencies
Start by updating your system and installing necessary packages.
sudo apt update
sudo apt upgrade -y
sudo apt install software-properties-common
Step 2: Add the PHP PPA Repository
Add the PPA repository for PHP to install multiple versions of PHP.
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Step 3: Select PHP Version and Install
Select the PHP version you want to install.
PHP Installation Commands
Based on your selection, here are the installation commands:
sudo apt install php7.4 php7.4-cli php7.4-fpm php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-pear php7.4-bcmath
Step 4: Install PHP-FPM
Install PHP-FPM to handle PHP processing:
sudo apt install php8.3-fpm
Step 5: Apache and PHP-FPM Configuration
Configure Apache to use PHP-FPM by enabling the necessary configuration:
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2
Step 6: Verify Installation
Verify the PHP installation by running the following command:
php -v
Step 7: Install PHP Extensions
Install essential PHP extensions:
sudo apt install php8.3-cli php8.3-mbstring php8.3-xml php8.3-curl php8.3-mysql php8.3-zip php8.3-gd php8.3-bcmath php8.3-pear php8.3-intl
For more details, check out our blog post for other PHP versions and configurations!