Advertisements

How to Install PHP 8.2 on Linux Server (Debian/Ubuntu)

  • Post last modified:October 21, 2023
  • Post category:Linux / Web
  • Post comments:0 Comments
  • Reading time:7 mins read

In this post, i will show you how to install PHP 8.2 and some extensions step by step.

Before we begin, make sure you have root access to your Linux server.

Table of Contents:

Step 1: Update Your System

update your system to make sure you have the latest packages:

sudo apt update
sudo apt upgrade

Step 2: Install Required Dependencies

Advertisements

Install the dependencies:

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

Step 3: Install PHP 8.2 and Extensions

Now that we have the required dependencies installed, we can proceed to install PHP and some popular extensions:

sudo apt install php8.2 php8.2-cli php8.2-common php8.2-curl php8.2-gd php8.2-mbstring php8.2-mysql php8.2-xml php8.2-zip

This will install PHP 8.2 and the following extensions:

  • php8.2-cli
  • php8.2-common
  • php8.2-curl
  • php8.2-gd
  • php8.2-mbstring
  • php8.2-mysql
  • php8.2-xml
  • php8.2-zip

You can install any extensions by adding the name to php8.2-extensionname

If don’t want to install any extensions Run the following command to install PHP 8.1 only:

sudo apt install php8.2

Step 4: Verify PHP Installation

To verify that PHP 8.2:

php -v

If everything has been installed correctly, you should see the following output:

PHP 8.2.x (cli) (built: DATE) (NTS)

Step 5: Check installed extensions

Note: before doing this make sure you have installed Apache.

To view the list of installed extensions, you can create a PHP info file by following these steps

Create a new file called info.php in your web server’s root directory:

sudo nano /var/www/html/info.php

Note: If you’re using a different web server, the root directory may be different.

Add the following code to the info.php file:

<?php
phpinfo();
?>

Save the file and exit the text editor.

Open a web browser and navigate to http://your-server-ip/info.php. You should see a page with detailed information about the PHP installation, including a list of installed extensions.

testing php version
This screenshot from this post old version (PHP 8.1) you will see a page similar like this

Advertisements

If you’re using a firewall, make sure to allow inbound traffic on port 80 (HTTP) to access the PHP info page.

Once you’re done checking the installed extensions, you can remove the info.php file from your server to avoid exposing sensitive information.

rm /var/www/html/info.php

Conclusion

In this tutorial, I have shown you the steps required to install PHP 8.2 and some extensions. you should now have PHP 8.2 and the extensions up and running on your server. If you encounter any issues during the installation process, feel free to leave a comment below.

Leave a Reply