How to Install PHP on Linux Mint

PHP powers the backend of millions of websites worldwide, from WordPress blogs to enterprise applications. Whether you’re setting up a local development environment, configuring a web server, or running PHP scripts from the command line, this guide walks you through installing PHP on Linux Mint. By the end, you’ll have a working PHP installation with the extensions you need, plus the knowledge to switch between PHP versions when your projects require it.

Understanding PHP Versions on Linux Mint

Linux Mint is based on Ubuntu, and the default PHP version available from the distribution’s repositories depends on which Mint release you’re running. The following table shows this relationship:

Linux Mint VersionUbuntu BaseDefault PHP Version
Linux Mint 22.x (Zena, Zara, Xia, Wilma)Ubuntu 24.04 LTS (noble)PHP 8.3
Linux Mint 21.x (Virginia, Victoria, Vera, Vanessa)Ubuntu 22.04 LTS (jammy)PHP 8.1

If you need a different PHP version than what your distribution provides by default, such as PHP 8.4 for the latest features or PHP 8.5 for testing, you can add the Ondřej Surý PPA to access multiple PHP versions. This guide covers both approaches.

Choose Your PHP Installation Method

You have two main options for installing PHP on Linux Mint. Choose the method that best fits your needs:

MethodPHP VersionsUpdatesBest For
Default RepositorySingle version (8.1 or 8.3)Automatic via system updatesMost users who want stability and simplicity
Ondřej Surý PPAMultiple versions (8.2, 8.3, 8.4, 8.5)Automatic via PPA updatesDevelopers needing specific versions or latest features

For most users, the default repository method is recommended because it provides a stable, well-tested PHP version that integrates seamlessly with your system updates. Only use the PPA if you specifically need a PHP version that your distribution doesn’t provide.

Update Your System

Before installing any software, refresh your package index and apply pending updates. This ensures you install the latest available package versions and avoid dependency conflicts:

sudo apt update
sudo apt upgrade

Method 1: Install PHP from Default Repository

The simplest way to install PHP is from your distribution’s default repository. This method requires no additional configuration and provides automatic security updates through your normal system update process.

Install PHP

Run the following command to install PHP along with the Apache module and command-line interface:

sudo apt install php

This command installs the PHP CLI for running scripts from the terminal, plus the Apache PHP module if Apache is present. Next, verify PHP is working by checking its version:

php -v

The output confirms which PHP version is now active on your system:

Linux Mint 22.x (Ubuntu 24.04 base):

PHP 8.3.6 (cli) (built: Jul 14 2025 18:30:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Linux Mint 21.x (Ubuntu 22.04 base):

PHP 8.1.2-1ubuntu2.22 (cli) (built: Jul 15 2025 12:11:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.22, Copyright (c), by Zend Technologies

Install PHP-FPM (Optional)

If you’re using Nginx or prefer PHP-FPM (FastCGI Process Manager) with Apache for better performance under load, install the FPM package. PHP-FPM runs PHP as a separate service, which allows it to handle requests more efficiently than the traditional Apache module approach.

For Linux Mint 22.x:

sudo apt install php8.3-fpm

For Linux Mint 21.x:

sudo apt install php8.1-fpm

Once installed, verify the FPM service is running:

For Linux Mint 22.x:

sudo systemctl status php8.3-fpm

For Linux Mint 21.x:

sudo systemctl status php8.1-fpm

Install Common PHP Extensions

PHP extensions add functionality for specific tasks like database connections, image processing, or encryption. Because most web applications require several extensions beyond the base PHP installation, use the pattern php-[extension] to install them for the default PHP version:

sudo apt install php-mysql php-curl php-gd php-mbstring php-xml php-zip

This command installs extensions commonly needed by WordPress, Laravel, Drupal, and other PHP applications:

  • php-mysql – MySQL and MariaDB database connectivity
  • php-curl – HTTP requests and API integrations
  • php-gd – Image processing (thumbnails, resizing)
  • php-mbstring – Multibyte string handling (required for UTF-8)
  • php-xml – XML parsing and processing
  • php-zip – ZIP archive handling

Additionally, to see which extensions are currently loaded, run:

php -m

Method 2: Install PHP from Ondřej Surý PPA

The Ondřej Surý PPA provides multiple PHP versions that you can install side-by-side. This is useful when you need a specific PHP version for compatibility, want the latest PHP features, or work on multiple projects requiring different PHP versions.

The Ondřej Surý PPA supports Ubuntu LTS releases, which means it works on Linux Mint 21.x (jammy) and Linux Mint 22.x (noble). As new PHP versions are released (such as PHP 8.6 and beyond), they will appear in this PPA before reaching distribution repositories.

Add the PHP PPA

First, install the software-properties-common package if it’s not already present, then add the PPA:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then, update your package index to make the new packages available:

sudo apt update

Install Your Preferred PHP Version

With the PPA added, you can install specific PHP versions. The PPA currently provides PHP 8.2, 8.3, 8.4, and 8.5. Choose the version that matches your project requirements:

PHP 8.2 (security fixes only):

sudo apt install php8.2

PHP 8.3 (active support):

sudo apt install php8.3

Alternatively, PHP 8.4 (active support, latest stable):

sudo apt install php8.4

For the latest, PHP 8.5 (cutting-edge features):

sudo apt install php8.5

Check PHP’s supported versions page to see current support status for each release. As of early 2026, PHP 8.2 receives security fixes only, while 8.3, 8.4, and 8.5 are under active development. When PHP 8.6 or later releases become available, they will appear in this PPA.

Once installed, verify the version:

php -v
PHP 8.4.16 (cli) (built: Dec 18 2025 23:38:28) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies

Install PHP-FPM for Your Version

When using the PPA, install the version-specific FPM package that matches your PHP installation:

sudo apt install php8.4-fpm

Replace 8.4 with your installed version number (8.2, 8.3, 8.4, or 8.5). As a result, each PHP version runs its own FPM service, allowing you to run different PHP versions simultaneously for different websites.

Install Extensions for Specific Versions

When using multiple PHP versions from the PPA, install extensions with the version-specific package name pattern:

sudo apt install php8.4-mysql php8.4-curl php8.4-gd php8.4-mbstring php8.4-xml php8.4-zip

Similarly, to see available extensions for a specific PHP version, search the package cache:

apt-cache search php8.4- | grep "^php8.4-"

This displays all available extensions with their descriptions, which helps you identify packages you might need.

Switch Between PHP Versions

When you have multiple PHP versions installed, you can switch which version the php command uses. This is particularly useful when different projects require different PHP versions.

View Installed PHP Versions

First, check which PHP versions are available and which one is currently active:

update-alternatives --display php

The output shows all installed PHP versions and indicates which one is currently selected:

php - auto mode
  link best version is /usr/bin/php8.4
  link currently points to /usr/bin/php8.4
  link php is /usr/bin/php
/usr/bin/php8.1 - priority 81
/usr/bin/php8.4 - priority 84

Switch PHP Version

To switch to a different PHP version, use the update-alternatives --set command with the full path to the PHP binary:

sudo update-alternatives --set php /usr/bin/php8.1

The system confirms the switch:

update-alternatives: using /usr/bin/php8.1 to provide /usr/bin/php (php) in manual mode

Finally, verify the change by checking the PHP version again:

php -v

Interactive Version Selection

Alternatively, use the interactive selection menu to choose from all available versions:

sudo update-alternatives --config php

This displays a numbered menu of installed PHP versions. Enter the number corresponding to your desired version and press Enter.

Switching the CLI PHP version doesn’t automatically change which PHP version your web server uses. For Apache with mod_php, you’ll need to disable the old module and enable the new one. For PHP-FPM, configure your web server to connect to the appropriate FPM socket.

Remove PHP from Linux Mint

If you need to remove PHP from your system, follow these steps based on how you installed it.

Remove Default Repository PHP

For PHP installed from the default repository, remove the package and clean up unused dependencies:

sudo apt remove --purge php
sudo apt autoremove

The autoremove command removes packages that were automatically installed as dependencies and are no longer needed.

Remove PPA PHP Versions

For PHP installed from the PPA, remove the specific version packages:

sudo apt remove --purge php8.4 php8.4-fpm php8.4-*
sudo apt autoremove

Replace 8.4 with whatever version you want to remove. If you want to completely remove the PPA as well:

sudo add-apt-repository --remove ppa:ondrej/php
sudo apt update

Troubleshooting Common Issues

PHP Command Not Found

If you receive “php: command not found” after installation, the PHP binary may not be in your PATH. First, verify the installation succeeded:

which php
ls -la /usr/bin/php*

However, if PHP is installed but not linked, recreate the alternatives link:

sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.4 84

Replace php8.4 and 84 with your installed version and a priority number.

PHP-FPM Not Starting

If the PHP-FPM service fails to start, check its status and logs:

sudo systemctl status php8.4-fpm
sudo journalctl -xeu php8.4-fpm

Common causes include port conflicts with another PHP-FPM version or configuration syntax errors. To diagnose further, check the FPM configuration:

sudo php-fpm8.4 -t

The -t flag tests the configuration syntax without starting the service. A successful test outputs “CONFIGURATION FILE … test is successful.”

Extension Not Loading

If an extension isn’t available after installation, verify it’s enabled in the PHP configuration. Check if the extension appears in the loaded modules:

php -m | grep curl

If no output appears, the extension is installed but not loaded. In that case, enable it manually:

sudo phpenmod curl
sudo systemctl restart php8.4-fpm

Conclusion

You now have PHP installed on Linux Mint, whether from the default repository for simplicity or from the Ondřej Surý PPA for access to multiple versions. With the extensions installed and the ability to switch between PHP versions, you’re ready to develop and run PHP applications. To build a complete web development environment, pair PHP with a database server and either Apache or Nginx as your web server.

Leave a Comment

Let us know you are human: