How to Install PHP 8 on Debian 12 – Simple Guide

In the world of web development, having the right tools at your disposal is crucial. PHP 8, the latest version of the popular scripting language, brings with it a host of new features and improvements that can elevate your web projects. If you’re running Debian 12 and looking to harness the power of PHP 8, you’re in the right place.

In this guide, we will walk you through the straightforward steps to install PHP 8 on Debian 12.

Prerequisites

  • Debian 12 Installed system
  • Sudo User with admin rights
  • Internet connection

Without any further delay, let’s jump into PHP 8 installation steps on Debian 12 system.

Installing PHP 8 Using Default Package Repositories

Debian 12  default package repositories has PHP 8.2, so it’s installation is straightforward using following apt commands. Open terminal and run beneath commands,

$ sudo apt update $ sudo apt install php -y

Apt-Install-php-Debian12-Default-Package-Repo

Once PHP 8 packages are installed, verify the PHP version by running,

$ php -v

Check-PHP-Version-After-Installation

In order to extend PHP functionalities, install its famous extensions using beneath command,

$ sudo apt install -y php-{curl,mbstring,zip,xml,soap,cli}

Install-php-extensions-Debian12

Installing PHP 8 via Sury PPA

In case, you want to install latest version of PHP 8, then enable Sury PPA repository. Execute following set of commands to enable Sury PPA,

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

Enable-PHP-Sury-PPA-Repo-Debian12

At time of writing this guide, php 8.3 was the latest version available in Sury PPP. So to install it run,

$ sudo apt install php8.3 -y

Install-PHP-8-3-Debian12-Sury-PPA

Check the php version post installation,

$ php -v

Verify-PHP-Version-Sury-Debian12

Configure PHP 8 for Apache Web Server

To configure PHP 8 for the web applications like Apache web server, edit its configuration file ‘/etc/php/8.2/apache2/php.ini’, add or change the below parameters that suits to your application

$ sudo vi /etc/php/8.2/apache2/php.in
-------------------------upload_max_filesize = 16M
post_max_size = 30M
memory_limit = 128M
max_execution_time = 500
max_input_vars = 2000
max_input_time = 1000
----------------------------

Save & close the file. To make the above changes into the effect restart Apache service

$ sudo systemctl restart apache2

Foe NGINX web server, edit its configuration file ‘/etc/php/8.2/fpm/pool.d/www.conf‘ and set the parameters that suits to your nginx server setup. After making the changes to file, don’t forget to restart php 8 fpm service

$ sudo systemctl restart php8.2-fpm

Test PHP 8 Installation

Create a simple PHP script to verify that everything is working correctly. Use your preferred text editor to create a file called info.php in your web server’s root directory. For Apache, it’s usually /var/www/html/

$ sudo vi /var/www/html/info.php
<?php
phpinfo();
?>

Save & exit the file.

Now, open your web browser and navigate to http://your_server_ip/info.php (replace your_server_ip with your server’s actual IP address). You should see a page displaying extensive information about your PHP installation. If this page loads successfully, congratulations! PHP 8 is up and running on Debian 12.

PHP-Info-Page-Debian12

Perfect, above screen confirms that PHP 8.2.9 has been installed successfully on your Debian 12 system. That’s all from this guide, please don’t hesitate to share your feedback and comments in below comments section.

3 thoughts on “How to Install PHP 8 on Debian 12 – Simple Guide”

  1. Hello,
    Thanks for your tutorial.
    I flow your instruction but I got at the end PHP Version 7.3.28-2+0~20210604.85+debian10~1.gbp219f11.
    I use Debian 10 on root server und also ISPConfig.
    I will be glad, if you could help me.
    Thanks und best Regards,
    Joseph

    Reply
    • Hi Joseph,
      It seems like apt have used default Debian 10 package repositories for installing PHP 8.
      Please cross check whether you have enabled php 8 repository and updated the repositories using ‘apt update’ command

      Reply

Leave a Reply to Joseph Cancel reply