How to Install PHP on Linux Mint 22 and 21

Last updated Thursday, May 28, 2026 12:35 pm Joshua James 8 min read

Linux Mint installs PHP through APT, giving you a supported runtime for local development, PHP-FPM sites, and command-line scripts without a standalone download. If you need to install PHP on Linux Mint for WordPress, Laravel, Composer, or a small test server, the distro packages are the safest place to start.

Linux Mint 22.x uses the Ubuntu 24.04 noble base and installs PHP 8.3.x by default, while Linux Mint 21.x uses the Ubuntu 22.04 jammy base and installs PHP 8.1.x. You normally do not need a standalone PHP installer; use the default repositories first, then add the Ondrej PHP PPA only when a project needs a newer branch such as PHP 8.4 or 8.5.

Install PHP on Linux Mint

Start with Mint’s default PHP branch unless an application explicitly asks for something newer. That keeps updates tied to the Ubuntu-based packages your Mint release already trusts.

Check the Default PHP Version for Your Mint Release

This quick reference shows which PHP branch Linux Mint ships before you add any external repository.

Linux Mint releaseUbuntu baseDefault PHP branch
Linux Mint 22.xUbuntu 24.04 LTS (noble)PHP 8.3.x
Linux Mint 21.xUbuntu 22.04 LTS (jammy)PHP 8.1.x

Use the default branch when you want the least maintenance and automatic security updates through Mint’s normal package flow. Move to the PPA only when your application requires a branch Mint does not ship.

Update Linux Mint Before Installing PHP

Refresh package metadata and install pending updates first so the PHP packages resolve against current dependencies.

sudo apt update
sudo apt upgrade

These commands use sudo because PHP installs system-wide. If your Mint account still needs admin access, follow the guide on create and add users to sudoers on Linux Mint.

Install the Default PHP Command Line and PHP-FPM Packages

The bare php metapackage pulls Apache helpers on both supported Mint releases, so it is cleaner to install the CLI and FPM packages directly when you want a PHP-FPM or command-line workflow.

Linux Mint 22.x:

sudo apt install php8.3-cli php8.3-fpm

Linux Mint 21.x:

sudo apt install php8.1-cli php8.1-fpm

These packages give you the php command for scripts and the versioned PHP-FPM service for Nginx or Apache proxy_fcgi. If you want Apache’s embedded PHP module instead, install libapache2-mod-php8.3 on Mint 22.x or libapache2-mod-php8.1 on Mint 21.x.

Verify the Installed PHP Branch

Check the active CLI binary after installation so you know which PHP branch Mint placed on your path.

php -v

Linux Mint 22.x:

PHP 8.3.6 (cli) (built: Mar 20 2026 02:32: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:

PHP 8.1.2-1ubuntu2.23 (cli) (built: Jan  7 2026 08:37:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
	with Zend OPcache v8.1.2-1ubuntu2.23, Copyright (c), by Zend Technologies

If you also installed PHP-FPM, verify the matching service next.

Linux Mint 22.x:

sudo systemctl status php8.3-fpm --no-pager --lines=0

Linux Mint 21.x:

sudo systemctl status php8.1-fpm --no-pager --lines=0

Install Common PHP Extensions

Most PHP applications need database, text, archive, and XML extensions on top of the base runtime. Install the set that matches your Mint release so the packages stay aligned with the branch you actually run.

Linux Mint 22.x:

sudo apt install php8.3-bcmath php8.3-curl php8.3-gd php8.3-intl php8.3-mbstring php8.3-mysql php8.3-xml php8.3-zip

Linux Mint 21.x:

sudo apt install php8.1-bcmath php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-xml php8.1-zip

The generic package names such as php-mysql and php-xml only follow Mint’s default branch. When you later install PHP 8.4 or 8.5 from the PPA, switch to matching versioned names such as php8.4-mysql or php8.5-xml.

Use PHP with Apache, Nginx, or Composer

If you want a local PHP development box, install Composer as a separate project dependency tool after the PHP command line package is in place. Many projects also work more smoothly after you install Git on Linux Mint for VCS-based dependencies.

For web serving, install Apache or Nginx from Mint’s own repositories and point the site at the matching php8.x-fpm service rather than a generic php-fpm unit. For Nginx handoffs, use the separate Nginx PHP-FPM configuration guide after PHP-FPM is installed.

Install a Newer PHP Version with the Ondrej PHP PPA

Use the Ondrej PHP PPA when your project needs a branch Mint does not ship, or when you want multiple PHP branches side by side for testing. This is the practical route for PHP 8.4 and 8.5 on supported Mint releases.

Check PHP’s supported versions page before choosing an older branch. That helps you keep production systems on supported releases instead of treating the PPA as a permanent parking spot for an outdated runtime.

Add the Ondrej PHP PPA

Mint normally provides add-apt-repository through mintsources. Install that helper only when the command is missing, then add the PPA and refresh package metadata. The -y option accepts the PPA confirmation prompt.

command -v add-apt-repository >/dev/null 2>&1 || sudo apt install mintsources
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update

On Mint 22.x the helper writes an Ubuntu noble source file; on Mint 21.x it writes jammy. Do not replace those with Mint codenames such as zena or virginia, because Launchpad publishes the PPA for the Ubuntu base.

Confirm that the PPA now supplies the branch you plan to install. The candidate rows should come from ppa.launchpadcontent.net/ondrej/php/ubuntu.

apt-cache policy php8.4-cli php8.5-cli

Install PHP 8.4 or PHP 8.5 from the PPA

Pick the branch you need for CLI work, then install the matching PHP-FPM service if you serve sites through Nginx or Apache proxy_fcgi.

PHP 8.4:

sudo apt install php8.4-cli php8.4-fpm

PHP 8.5:

sudo apt install php8.5-cli php8.5-fpm

Mint keeps each branch in separate packages, so you can install more than one version at the same time. The newer command line package usually becomes the default php command because it registers a higher alternatives priority than the older branch. Review APT’s transaction before confirming, especially on Mint 21.x, where PPA PHP packages can replace shared PHP-related libraries.

Install Matching Extensions for the PPA Branch

Keep extension packages on the same branch as the runtime you just installed so the CLI, FPM service, and extension ABI stay aligned.

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

Replace 8.4 with 8.5 if that is the branch you installed. You can also inspect available packages with apt-cache search php8.4- or the matching 8.5 pattern.

Verify the PPA PHP Branch

Check the versioned binary before relying on the plain php command. That proves the branch package is installed even when your shell alternative still points somewhere else.

php8.4 -v
systemctl is-active php8.4-fpm
php8.4 -m | grep -E '^bcmath$|^curl$|^gd$|^intl$|^mbstring$|^mysqli$|^xml$|^zip$'

The version output should start with PHP 8.4, the service check should print active, and the module list should show the extensions you installed. Replace 8.4 with 8.5 when that is your PPA branch.

Switch the Active PHP Version for the Command Line on Linux Mint

When you keep more than one PHP CLI branch installed, Linux Mint uses update-alternatives to decide which binary the plain php command runs.

List the Installed PHP Alternatives

Check the available alternatives before switching so you can see the current default and the exact binary paths Mint registered.

update-alternatives --display php

Relevant output includes:

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
  slave php.1.gz is /usr/share/man/man1/php.1.gz
/usr/bin/php8.4 - priority 84

Point the PHP Command at Another Branch

Set the command line version explicitly when a project expects a different branch than Mint’s default.

sudo update-alternatives --set php /usr/bin/php8.4
php -v

Relevant output includes:

update-alternatives: using /usr/bin/php8.4 to provide /usr/bin/php (php) in manual mode
PHP 8.4.21 (cli) (built: May 14 2026 16:00:58) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.4.21, Copyright (c) Zend Technologies

Change the binary path to /usr/bin/php8.1, /usr/bin/php8.3, or /usr/bin/php8.5 when you need another branch. Re-running php -v immediately after the switch confirms the CLI now points to the version you expected.

Remember That Web Server Handlers Do Not Switch Automatically

Changing the CLI alternative only affects the php command in your shell. Apache still uses its installed libapache2-mod-php8.x module, and Nginx or Apache proxy_fcgi still talks to the specific php8.x-fpm service and socket you configured.

Update PHP on Linux Mint

Default Mint PHP packages and PPA-installed PHP packages both update through APT. Keep the Ondrej PHP PPA enabled while you use a PPA branch, because disabling the source also stops future updates for packages installed from it.

sudo apt update
sudo apt upgrade

Review APT’s transaction before confirming upgrades on systems that use the PPA. PPA branches can update helper packages such as php-common and shared libraries such as libgd3, not only the visible php8.x packages.

Remove PHP on Linux Mint

Remove the branch you actually installed instead of purging every PHP package blindly. That keeps cleanup predictable when you use Mint’s default branch and a newer PPA branch on the same machine.

Remove the Default Mint PHP Packages

Use the branch that matches your Mint release when you want to remove the default CLI, FPM service, and the common extensions installed earlier.

Linux Mint 22.x:

sudo apt remove php8.3-cli php8.3-fpm php8.3-common php8.3-opcache php8.3-readline php8.3-bcmath php8.3-curl php8.3-gd php8.3-intl php8.3-mbstring php8.3-mysql php8.3-xml php8.3-zip

Linux Mint 21.x:

sudo apt remove php8.1-cli php8.1-fpm php8.1-common php8.1-opcache php8.1-readline php8.1-bcmath php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-xml php8.1-zip

If you also installed Apache’s embedded PHP module, add libapache2-mod-php8.3 on Mint 22.x or libapache2-mod-php8.1 on Mint 21.x to the same removal command.

Run sudo apt autoremove separately only if you want to review the dependency list first. On systems with older package history, an automatic autoremove can include unrelated packages you did not mean to clean up yet.

Remove a PPA-Installed PHP Branch

Remove the exact PPA branch you added instead of targeting every PHP package on the system. For PHP 8.4, remove the branch and its common extensions.

sudo apt remove php8.4-cli php8.4-fpm php8.4-common php8.4-opcache php8.4-readline php8.4-bcmath php8.4-curl php8.4-gd php8.4-intl php8.4-mbstring php8.4-mysql php8.4-xml php8.4-zip

Swap the version number for 8.5 when that is the branch you want to remove. Once the PPA-specific packages are gone, remove the repository itself if you no longer need it. The helper removes the generated source file and its Mint-created keyring on supported Mint releases.

Before removing the source, check whether any PPA-versioned helper package or shared library remains installed. If this command prints packages such as php-common or libgd3, keep the PPA enabled until you intentionally remove or downgrade those packages.

dpkg-query -W -f='${binary:Package}\t${Version}\n' | grep '+deb.sury.org' || true
sudo add-apt-repository --remove -y ppa:ondrej/php
sudo apt update

Verify the cleanup with package policy and source-file checks. After the PPA is gone, no live ppa.launchpadcontent.net/ondrej/php candidate should remain for the removed branch.

apt-cache policy php8.4-cli
dpkg-query -W -f='${binary:Package}\t${Version}\n' | grep '+deb.sury.org' || true
sudo find /etc/apt/sources.list.d /etc/apt/keyrings -maxdepth 1 \( -iname '*ondrej*php*' -o -iname '*B8DC7E53946656EFBCE4C1DD71DAEAAB4AD4CAB6*' \) -print

If the grep and find commands print no output, the PPA package, source, and keyring cleanup is complete. A local /var/lib/dpkg/status row can remain after a normal package removal; it is dpkg history, not an active repository.

Troubleshoot PHP on Linux Mint

Most Mint PHP issues come down to the active CLI alternative or an extension package that does not match the branch you are actually running.

Fix the PHP Command Not Found Error After Switching Versions

Check the path and the registered alternatives first so you can see whether PHP is missing entirely or the shell link simply points nowhere useful after a php: command not found error.

command -v php
update-alternatives --display php

If the alternatives entry is missing, recreate it with the branch that is actually installed on your system.

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

Replace php8.4 and the priority number when another branch is the one you installed.

Fix the PHP-FPM Service Unit Not Found Error on Linux Mint

Linux Mint does not create a generic php-fpm.service unit. Each installed branch uses its own versioned service name, so restart or check the unit that matches the PHP branch on your system.

Linux Mint 22.x:

sudo systemctl restart php8.3-fpm
sudo systemctl status php8.3-fpm --no-pager --lines=0

Linux Mint 21.x:

sudo systemctl restart php8.1-fpm
sudo systemctl status php8.1-fpm --no-pager --lines=0

If you installed a newer PPA branch, use that versioned unit instead, such as php8.4-fpm or php8.5-fpm.

Check Whether a PHP Extension Loaded

Use the loaded module list to confirm the extension name you expect is actually active.

php -m | grep -E '^curl$|^mbstring$|^mysqli$|^xml$'

If a module is missing, install the package that matches the PHP branch you run and restart the matching PHP-FPM service when you use FPM.

sudo apt install php8.4-curl
sudo systemctl restart php8.4-fpm

Conclusion

PHP is installed on Linux Mint with either the distro default branch or a newer PPA branch, and versioned php8.x-fpm services keep web stacks predictable. Next, configure the Nginx PHP-FPM handoff and review project-specific extensions before exposing a local stack.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: