PHP remains one of the most widely used backend technologies for websites and web applications. If you want to Install PHP on Ubuntu systems for platforms like WordPress, Laravel, or Magento, Ubuntu 24.04 makes the process fast and straightforward with official repositories and updated packages.
This guide explains how to install PHP 8.3 on Ubuntu 24.04, configure it with Apache or Nginx, add common extensions, and manage multiple PHP versions efficiently.
Ubuntu 24.04 includes PHP 8.3 in its default repositories, which means you can deploy modern PHP applications without adding third-party sources. PHP works seamlessly with popular web servers and offers strong performance for dynamic websites.
Whether you run a development machine or a production server, Ubuntu provides a stable environment for PHP applications.
If your server uses Apache, installing PHP is very simple. Start by updating the package index and installing the required packages:
sudo apt updatesudo apt install php libapache2-mod-php
Once installation finishes, restart Apache to activate the PHP module:
sudo systemctl restart apache2
You can verify the installation using:
php -v
The output should display the installed PHP version.
Unlike Apache, Nginx does not process PHP files directly. Instead, it relies on PHP-FPM.
Install PHP and PHP-FPM with the following command:
sudo apt updatesudo apt install php-fpm
After installation, confirm that PHP-FPM is running:
sudo systemctl status php8.3-fpm
Next, configure your Nginx server block to handle PHP files:
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.3-fpm.sock;} Restart Nginx afterward:
sudo systemctl restart nginx
Most PHP applications require additional extensions for databases, image processing, or caching.
You can install extensions individually:
sudo apt install php-mysql php-gd php-curl
Some commonly used extensions include:
php-mysql for MySQL databasesphp-curl for HTTP requestsphp-xml for XML supportphp-mbstring for multibyte text handlingphp-zip for archive managementTo list installed PHP modules:
php -m
After adding extensions, restart Apache or PHP-FPM.
Create a test file inside your web root:
echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php
Open your browser and visit:
http://your_server_ip/info.php
If PHP is configured correctly, a detailed PHP information page will appear.
For security reasons, remove the file after testing:
sudo rm /var/www/html/info.php
Some applications require older PHP releases. Ubuntu supports multiple PHP versions through the popular Ondřej Surý repository.
Add the repository:
sudo add-apt-repository ppa:ondrej/phpsudo apt update
Then install a specific version:
sudo apt install php8.1
You can switch between installed versions using:
sudo update-alternatives --config php
Learning how to Install PHP on Ubuntu servers is essential for developers, administrators, and hosting environments. Ubuntu 24.04 simplifies PHP deployment with official repositories, PHP-FPM support, and flexible version management.
Once PHP is installed, you can add extensions, optimize performance, and begin deploying modern web applications with confidence.
Introduction Bash scripting is a powerful way to automate Linux tasks, but writing a script…
Introduction A self-signed SSL certificate is a certificate that is created and signed by the…
Introduction Debugging is an important part of Bash scripting. When a script does not work…
Introduction Cron jobs are used in Linux to run commands or Bash scripts automatically at…
Introduction Pipes are an important feature in Linux and Bash scripting. A pipe allows you…
Introduction The grep, awk, and sed commands are powerful text-processing tools in Linux. They are…