Install PHP 8.0/8.1/8.2/8.x on Ubuntu 22.04

|
Last Updated:
|
|

In this tutorial, you will learn how to install PHP 8.0/8.1/8.2/8.x on Ubuntu 22.04. PHP 8 is a major update of the PHP language. It contains many new features and optimizations including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.

Installing PHP 8.x on Ubuntu 22.04

The default Ubuntu 22.04 repositories provide upto PHP 8.1 packages as of this writing;

apt-cache policy php8*

Sample output;

php8.0-pdo-pgsql:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-enchant:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-pdo-firebird:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-simplexml:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-mysqlnd:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-pspell:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-raphf:
  Installed: (none)
  Candidate: 2.0.1+1.1.2-13
  Version table:
     2.0.1+1.1.2-13 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-interbase:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-bcmath:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-simplexml:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-ctype:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-pgsql:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-enchant:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-interbase:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-iconv:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-sass:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-msgpack:
  Installed: (none)
  Candidate: 2.2.0~rc1+2.1.2+0.5.7-6
  Version table:
     2.2.0~rc1+2.1.2+0.5.7-6 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-gmagick:
  Installed: (none)
  Candidate: 2.0.6~rc1+1.1.7~rc3-10
  Version table:
     2.0.6~rc1+1.1.7~rc3-10 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-pdo-mysql:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-snmp:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-soap:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-snmp:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-pdo-mysql:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-soap:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-pdo-sqlite:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-solr:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-pdo-sqlite:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-http:
  Installed: (none)
  Candidate: 4.0.0+3.2.4+2.6.0-0+deb11u1ubuntu1
  Version table:
     4.0.0+3.2.4+2.6.0-0+deb11u1ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-yaml:
  Installed: (none)
  Candidate: 2.2.2+2.1.0+2.0.4+1.3.2-5
  Version table:
     2.2.2+2.1.0+2.0.4+1.3.2-5 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-ssh2:
  Installed: (none)
  Candidate: 1.3.1+0.13-6
  Version table:
     1.3.1+0.13-6 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-common:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-curl:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-opcache:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-smbclient:
  Installed: (none)
  Candidate: 1.0.6-6
  Version table:
     1.0.6-6 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-imagick:
  Installed: (none)
  Candidate: 3.6.0-4
  Version table:
     3.6.0-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-mysql:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-mailparse:
  Installed: (none)
  Candidate: 3.1.2+2.1.7~dev20160128-7
  Version table:
     3.1.2+2.1.7~dev20160128-7 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-tidy:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-curl:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-imap:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-intl:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu jammy/main i386 Packages
php8.1:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu jammy/main i386 Packages
php8.1-shmop:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-tidy:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-odbc:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-imap:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-phpdbg:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-intl:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-calendar:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-mysqli:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-opcache:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-odbc:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-gd:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-sybase:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-mysqli:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-memcache:
  Installed: (none)
  Candidate: 8.0+4.0.5.2+3.0.9~20170802.e702b5f9+-7
  Version table:
     8.0+4.0.5.2+3.0.9~20170802.e702b5f9+-7 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-mbstring:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-xmlreader:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-ctype:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-memcached:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-pgsql:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-calendar:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-json:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-iconv:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-fileinfo:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-posix:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-phar:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-uopz:
  Installed: (none)
  Candidate: 7.1.1+6.1.2-2ubuntu1
  Version table:
     7.1.1+6.1.2-2ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-common:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-xmlrpc:
  Installed: (none)
  Candidate: 3:1.0.0~rc3-2
  Version table:
     3:1.0.0~rc3-2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-json:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-pcov:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-mongodb:
  Installed: (none)
  Candidate: 1.12.0+1.9.2+1.7.5-4
  Version table:
     1.12.0+1.9.2+1.7.5-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-readline:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-gettext:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-uuid:
  Installed: (none)
  Candidate: 1.2.0-11
  Version table:
     1.2.0-11 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-phar:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-pdo-dblib:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-sockets:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-ds:
  Installed: (none)
  Candidate: 1.4.0-4
  Version table:
     1.4.0-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-gd:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-ps:
  Installed: (none)
  Candidate: 1.4.4+1.3.7-6
  Version table:
     1.4.4+1.3.7-6 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-igbinary:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-exif:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-mbstring:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-pdo-dblib:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-xmlreader:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-phpdbg:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-exif:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-fileinfo:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-gettext:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-redis:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-sqlite3:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-mysql:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-xmlwriter:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-sockets:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-pspell:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-readline:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-bcmath:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-sysvmsg:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-shmop:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-gearman:
  Installed: (none)
  Candidate: 2.1.0+1.1.2-11
  Version table:
     2.1.0+1.1.2-11 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-sysvsem:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-sysvshm:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-sybase:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-bz2:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-tokenizer:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-cgi:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-cli:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-dba:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-dev:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-dom:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-ldap:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-pdo-odbc:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-sqlite3:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-ffi:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-fpm:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-ftp:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-ast:
  Installed: (none)
  Candidate: 1.0.16-4
  Version table:
     1.0.16-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-gmp:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-bz2:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-cgi:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-cli:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-dba:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-dev:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-dom:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-ffi:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-fpm:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-ftp:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-ldap:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-gmp:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-pdo:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-sysvmsg:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-xmlwriter:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-amqp:
  Installed: (none)
  Candidate: 1.11.0-4
  Version table:
     1.11.0-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-pdo:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-psr:
  Installed: (none)
  Candidate: 1.2.0-4
  Version table:
     1.2.0-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-sysvsem:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-sysvshm:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-apcu:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-rrd:
  Installed: (none)
  Candidate: 2.0.3+1.1.3-6
  Version table:
     2.0.3+1.1.3-6 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-xml:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.0-xsl:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe i386 Packages
php8.1-xdebug:
  Installed: (none)
  Candidate: 3.1.2+2.9.8+2.8.1+2.5.5-4
  Version table:
     3.1.2+2.9.8+2.8.1+2.5.5-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-mysqlnd:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-zip:
  Installed: (none)
  Candidate: 8.0.8-1ubuntu2
  Version table:
     8.0.8-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-pdo-pgsql:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-xml:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-xsl:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu jammy/main i386 Packages
php8.1-yac:
  Installed: (none)
  Candidate: 2.3.1+0.9.2-4
  Version table:
     2.3.1+0.9.2-4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.1-zip:
  Installed: (none)
  Candidate: 8.1.0-1
  Version table:
     8.1.0-1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
php8.1-zmq:
  Installed: (none)
  Candidate: 1.1.3-23
  Version table:
     1.1.3-23 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
php8.0-pdo-odbc:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-tokenizer:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-pdo-firebird:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.0-posix:
  Installed: (none)
  Candidate: (none)
  Version table:
php8.1-oauth:
  Installed: (none)
  Candidate: 2.0.7+1.2.3-14
  Version table:
     2.0.7+1.2.3-14 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages

Install PHP 8.0 on Ubuntu 22.04

Thus, to install PHP 8.0 on Ubuntu 22.04, run the command;

apt install php8.0

This command will install PHP 8.0 along with other required package dependencies as seen from the output below.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap php-common php8.0-cli
  php8.0-common php8.0-opcache php8.0-readline
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
  php-pear
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap php-common php8.0
  php8.0-cli php8.0-common php8.0-opcache php8.0-readline
0 upgraded, 15 newly installed, 0 to remove and 727 not upgraded.
Need to get 6,628 kB of archives.
After this operation, 27.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

To install any other PHP 8.0 extensions, simply run the command below;

apt install php8.0-Extension

Where Extension is the name of the respective extension that you want to install. For example;

apt install php8.0-snmp

Install PHP 8.1 on Ubuntu 22.04

You can now install PHP 8.1 and any required extension on Ubuntu 22.04, run the command below;

apt install php8.1

This command will install PHP 8.1 along with other required package dependencies as seen from the output below.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap php-common php8.1-cli
  php8.1-common php8.1-opcache php8.1-readline
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
  php-pear
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap php-common php8.1
  php8.1-cli php8.1-common php8.1-opcache php8.1-readline
0 upgraded, 15 newly installed, 0 to remove and 727 not upgraded.
Need to get 7,012 kB of archives.
After this operation, 28.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

To install any other PHP 8.1 extensions/modules, simply run the command below;

apt install php8.1-Extension

Replace Extension with the specific module/extension. For example;

apt install php8.1-mysql php8.1-xml

Install PHP 8.2 on Ubuntu 22.04

As of this writing, default Ubuntu 22.04 repositories doesn’t have PHP 8.2 packages.

Thus, you need to install Andrej SURY APT repository on Ubuntu 22.04;

add-apt-repository ppa:ondrej/php --yes

You can then install PHP 8.2 and any required extension on Ubuntu 22.04;

apt install php8.2

This command will install PHP 8.2 along with other required package dependencies.

To install any other PHP 8.2 extensions/modules, simply run the command below;

apt install php8.2-Extension

Replace Extension with the specific module/extension. For example;

apt install php8.2-mysql php8.2-xml

Check version of PHP Installed

You can check the version of PHP installed using the command;

php -v

PHP 8.2.4 (cli) (built: Mar 16 2023 14:34:48) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.4, Copyright (c), by Zend Technologies

How to Set Default PHP Version on Debian

You can set the default PHP version using the update-alternatives command.

If you have multiple versions of PHP installed, there could be some situations that might make you choose a default version to use.

You can list the paths of the installed PHP versions by running the command update-alternatives --list php.

update-alternatives --list php

Sample output;

/usr/bin/php8.0
/usr/bin/php8.1
/usr/bin/php8.2

Thus, to set the default PHP version, you can use the update-alternatives command with the --config option followed by the path of the desired PHP version. For example, to set PHP version 8.1 as the default PHP version, run the command;

update-alternatives --config php /usr/bin/php8.1

You can also run the command interactively by omitting the path to PHP;

update-alternatives --config php

There are 3 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.2   82        auto mode
  1            /usr/bin/php8.0   80        manual mode
  2            /usr/bin/php8.1   81        manual mode
  3            /usr/bin/php8.2   82        manual mode

Press <enter> to keep the current choice[*], or type selection number:

To set a specific version of PHP as the default version, simply choose a number and press ENTER.

For example, in the above prompt, you can enter 2 and press ENTER to set PHP 8.1 as the default version;


There are 3 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.2   82        auto mode
  1            /usr/bin/php8.0   80        manual mode
  2            /usr/bin/php8.1   81        manual mode
  3            /usr/bin/php8.2   82        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/php8.1 to provide /usr/bin/php (php) in manual mode

Confirm the version;

PHP 8.1.17 (cli) (built: Mar 16 2023 14:37:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies

That is all on how to install PHP 8.x on Ubuntu 22.04.

Other Tutorials

Install PHP 7.1/7.2/7.3/7.4 on Debian 11

Install phpLDAPAdmin on Debian 10/Debian 11

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment