installphp.info


← Back to home page

Install PHP 8.1 on Ubuntu 22.04

Warning! This version of PHP is outdated.

PHP 8.1 reached end of active support on 25 Nov 2023. As of today, PHP 8.1 is only receiving security related updates through 31 Dec 2025, at which point it will be considered end-of-life and receive no further updates. It's strongly recommended to upgrade to the latest version of PHP before then.

Installing PHP 8.1 on Ubuntu 22.04

Prerequisites

  • Ubuntu 22.04 LTS installed
  • User account with sudo privileges
  • Terminal access
  • Internet connection

Installation

  1. Update the package list:

    sudo apt update
  2. Install PHP 8.1 and common extensions:

    sudo apt install php8.1 php8.1-cli php8.1-common php8.1-curl php8.1-mbstring php8.1-mysql php8.1-xml
  3. Confirm the installation:

    php -v

Verification

  1. Create a PHP info file:

    echo '<?php phpinfo();' | sudo tee /var/www/html/info.php
  2. Start the Apache web server (if not already running):

    sudo systemctl start apache2
  3. Open a web browser and navigate to:

    http://localhost/info.php

    You should see the PHP information page displaying details about PHP 8.1.

  4. After verification, remove the info.php file for security reasons:

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