ItsmeITItsmeIT
  • Linux
    • Debian
    • Ubuntu
  • PC/Windows
Reading: How to Install PHP 8.1/8.2/8.3 on Debian 11/12
Share
Notification Show More
Font ResizerAa
ItsmeITItsmeIT
Font ResizerAa
  • Categories
    • Linux
    • Debian
    • Ubuntu
    • PC/Windows
Have an existing account? Sign In
Follow US
© 2025 ItsmeIT. All rights reserved.

Home » Linux » Debian » How to Install PHP 8.1/8.2/8.3 on Debian 11/12

How to Install PHP 8.1/8.2/8.3 on Debian 11/12

avatar
By
Loibv
avatar
ByLoibv
The ItsmeIT team – delivering cutting-edge updates, tech trends, and insider knowledge from the world of technology.
Follow:
Last updated: August 26, 2025

Are you stepping into the world of web development on Debian but unsure how to install PHP? Don’t worry! Just like making a good cup of coffee, with the right ingredients and proper steps, everything becomes simple. Let’s explore how to set up a PHP environment on Debian 11/12 smoothly and efficiently!

🛠 Prerequisites

This guide applies to Debian 11 and Debian 12.

  • You need sudo or root privileges to execute commands.

4 Steps to Install PHP 8.1, 8.2, or 8.3 on Debian

1️⃣ Add PHP Repository Signing Key

PHP can be installed from the official Debian repository. However, if you want the latest versions like PHP 8.1, 8.2, or 8.3, it’s best to use the Surý APT repository—a widely trusted source maintained by Ondřej Surý.

👉 Run the following commands to create and verify the GPG key for security:

sudo touch /etc/apt/trusted.gpg.d/php.gpg
sudo wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

🔎 Why is this step necessary?

  • Ensures authenticity: Verifies that the PHP packages are genuine and have not been tampered with.
  • Accesses the latest PHP versions: Debian’s default repositories usually contain older PHP versions.

2️⃣ Add the PHP Repository

Now, add the Surý APT repository to your system by running:

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

Then, update the package list:

sudo apt update

👉 Why add this repository?
By including this source, your system can install and update PHP versions easily from Surý’s repository instead of relying on outdated packages.

3️⃣ Install PHP 8.1, 8.2, or 8.3

👉 To install PHP 8.3:

sudo apt install php8.3

👉 To install PHP 8.2:

sudo apt install php8.2

👉 To install PHP 8.1:

sudo apt install php8.1

4️⃣ Install PHP Extensions

Below is the command to install php8.3-fpm along with commonly used PHP extensions on Debian 11/12. If you need a different PHP version, replace 8.3 with 8.2 or 8.1.

sudo apt install php8.3-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl,fpm,bcmath,mcrypt}
install php extensions
PHP extensions were successfully installed

Explanation of some key extensions:

  • php8.3-fpm → Required when running PHP with Nginx.
  • php8.3-mysql → Enables PHP to interact with MySQL/MariaDB.
  • php8.3-mbstring → Handles multibyte string processing.
  • php8.3-curl → Used for making API requests.
  • And many more essential modules for various functionalities.

After installation, restart PHP-FPM and enable it to start automatically with the system:

sudo systemctl enable php8.3-fpm
sudo service php8.3-fpm restart

Verify PHP Installation

You can check if PHP is working directly in the terminal with:

php -r 'echo "PHP is running!n";'

If you see “PHP is running!“, congratulations! PHP is now ready to use.

To check detailed PHP configuration:

php -i | less

This displays all PHP settings, similar to phpinfo(), but without needing a web browser.

Configuring PHP with a Web Server (Optional)

PHP without a web server is like a coffee shop without customers—it looks fine but no one is using it! 😆

Currently, there are two main choices for running PHP with a web server:

  • Apache: Easy to set up and runs immediately. But as your website grows, it can become resource-intensive.
  • Nginx: Faster and more efficient, preferred by many high-traffic websites like WordPress, forums, and e-commerce platforms.

I personally started with Apache when first using WordPress. But as traffic increased, Apache started consuming resources like a hungry monster. Switching to Nginx + PHP-FPM was a game-changer—faster load times, smoother performance, and fewer worries!

If you’re also using WordPress and want to leverage Nginx, check out these guides:

  • How to Install Nginx on Linux
  • How to Install WordPress with Nginx

Trust me, if your website has growth potential, investing in Nginx is worth it!

Troubleshooting Common PHP Installation Errors

❌ Error: “Unable to Locate PHP Package”

Symptoms:
When running the installation command, you see:

E: Unable to locate package php

Possible Causes:

  • Your system has not been updated with the latest package lists.
  • You haven’t added the correct repository.

Solution:
Remove any old PHP-related repository lists:

sudo rm -rf /etc/apt/sources.list.d/sury-php.list

Update package lists:

sudo apt update

Then, retry the PHP installation steps.

❌ Error: “Wrong PHP Version Installed”

Symptoms:
After installing PHP, running php -v shows an older version than expected.

Possible Causes:

  • Debian uses an older default PHP version from its repositories.
  • You have multiple PHP versions installed, and the system is using the wrong one.

Solution:
Check installed PHP versions:

update-alternatives --list php

Change the default PHP version:

sudo update-alternatives --config php
Select the default PHP version
Select the default PHP version

Select the correct version and verify with:

php -v

❌ Error: “Permission Denied”

If you encounter permission-related errors, they usually require advanced configurations. You can refer to this guide:
How to Configure PHP-FPM to Fix Permission Issues

Installing PHP on Debian is not too complicated, but if you’re unaware of common errors, it can be frustrating! 😆 Hopefully, with these troubleshooting tips, you can set up PHP smoothly without any hiccups.

Still facing an issue? Just ask, and I’ll help debug it until it’s fixed!

Share This Article
Facebook Reddit Telegram Threads
avatar
ByLoibv
Follow:
The ItsmeIT team – delivering cutting-edge updates, tech trends, and insider knowledge from the world of technology.
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

Most Popular

Install Docker on Linux
How to Install Docker on Linux (Ubuntu, Debian, RHEL, AlmaLinux)
Use SCP to Transfer Data in Linux
How to Transfer Files Between Linux Servers Using SCP and SSH
Install Exim4 configure mail server Ubuntu
How to Set Up a Mail Server Using Exim4 on Ubuntu/Linux
ItsmeITItsmeIT
Follow US
© 2025 ItsmeIT. All Rights Reserved.
  • Privacy Policy
  • Terms of Service
Logo ItsmeIT logo
Welcome Back!

Sign in to your account

Continue with Google
Register   |Lost your password?