Logo
Overview
How to install PHP 7.3 in Ubuntu 18.04

How to install PHP 7.3 in Ubuntu 18.04

October 8, 2019
3 min read

Overview

By default, Ubuntu 18.04 LTS includes PHP 7.2 in its official repositories. However, many modern applications require PHP 7.3 or later—for example, the latest WordPress versions, Laravel frameworks, and other web applications.

This guide shows how to install PHP 7.3 on Ubuntu 18.04 using Ondřej Surý’s PPA, a widely-trusted source for newer PHP versions.

Note

Why Not Use Official Repos? Ubuntu LTS versions (like 18.04) maintain package versions for stability. Third-party PPAs like Ondřej’s provide newer versions with security updates for the application lifecycle.

Prerequisites

  • Ubuntu 18.04 LTS or derivative (Linux Mint, Pop!_OS, etc.)
  • Root or sudo access
  • Internet connection
  • apt package manager

Step 1: Add Ondřej Surý’s PPA Repository

Ondřej Surý maintains a well-maintained repository of unsupported PHP versions for Debian and Ubuntu. First, add his PPA:

Terminal window
sudo add-apt-repository ppa:ondrej/php
sudo apt update

This adds the PPA to your system and refreshes the package list.

Tip

Adding multiple repos: You can add other PPAs from Ondřej for related tools like ppa:ondrej/apache2 (for Apache) or ppa:ondrej/nginx (for Nginx) if needed.

Step 2: Install PHP 7.3

After adding the PPA, install PHP 7.3. Choose based on your web server:

For Nginx (with PHP-FPM)

Terminal window
sudo apt install php7.3-fpm

This installs PHP 7.3 FastCGI Process Manager (FPM) for use with Nginx. FPM is more efficient than mod_php for high-traffic sites.

For Apache (with mod_php)

Terminal window
sudo apt install php7.3

This installs PHP 7.3 with Apache module support, automatically enabling mod_php.

Install Common Extensions (Optional)

Most applications need additional PHP extensions:

Terminal window
sudo apt install php7.3-mysql php7.3-gd php7.3-curl php7.3-mbstring php7.3-xml php7.3-zip
Note

Common Extensions Explained:

  • php7.3-mysql — MySQL/MariaDB database support
  • php7.3-gd — Image manipulation (required for many CMS platforms)
  • php7.3-curl — HTTP requests (needed for API calls)
  • php7.3-mbstring — Multi-byte string support (internationalization)
  • php7.3-xml — XML parsing support
  • php7.3-zip — ZIP archive support

Step 3: Verify the Installation

Confirm that PHP 7.3 was installed correctly:

Terminal window
php -v

Output should show:

PHP 7.3.x-x (cli) (built: ...)
Copyright (c) 1997-2019 The PHP Group

Check PHP Information

For detailed information about your PHP installation (modules, configuration, etc.):

Terminal window
php -i

Or create a simple info script:

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

Then visit http://yourserver/info.php in a browser.

Warning

Security: Always delete the info.php file after verification. Exposing phpinfo() publicly reveals system details to attackers.

Step 4: Enable PHP-FPM Service (Nginx only)

If you installed php7.3-fpm, enable and start the service:

Terminal window
sudo systemctl enable php7.3-fpm
sudo systemctl start php7.3-fpm

Verify it’s running:

Terminal window
sudo systemctl status php7.3-fpm

Troubleshooting

Dependency Conflicts

If you receive dependency errors, clear the package cache:

Terminal window
sudo apt clean
sudo apt autoclean
sudo apt autoremove
sudo apt update

Multiple PHP Versions

If you have multiple PHP versions installed, check which is default:

Terminal window
update-alternatives --list php

Switch versions:

Terminal window
sudo update-alternatives --set php /usr/bin/php7.3

Check Apache Module

For Apache, verify mod_php is enabled:

Terminal window
sudo a2enmod php7.3
sudo systemctl restart apache2

Summary

You have successfully installed PHP 7.3 on Ubuntu 18.04. Your web server (Nginx or Apache) can now run modern PHP applications that require version 7.3. Remember to keep your system updated with:

Terminal window
sudo apt update && sudo apt upgrade

For additional help, consult the official Ondřej Surý PPA page or PHP documentation.