installphp.info


← Back to home page

Install PHP 8.1 on Ubuntu 20.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 20.04

Prerequisites

  • Ubuntu 20.04 LTS system
  • User account with sudo privileges
  • Terminal access
  • Internet connection

Installation

  1. Update the system package list:

    sudo apt update
  2. Add the PHP repository:

    sudo add-apt-repository ppa:ondrej/php
  3. Install PHP 8.1:

    sudo apt install php8.1
  4. Install common PHP extensions:

    sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl

Verification

  1. Check the PHP version:

    php -v

    The output should show PHP 8.1.x

  2. Verify installed PHP modules:

    php -m

    This will list all installed PHP modules

  3. Create a PHP info file:

    echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
  4. Access the PHP info page in a web browser:

    http://your_server_ip/info.php

    This page will display detailed information about your PHP installation