{"id":10157,"date":"2021-08-21T12:14:47","date_gmt":"2021-08-21T09:14:47","guid":{"rendered":"https:\/\/kifarunix.com\/?p=10157"},"modified":"2024-03-18T18:46:37","modified_gmt":"2024-03-18T15:46:37","slug":"install-php-8-on-debian-11","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-php-8-on-debian-11\/","title":{"rendered":"Install PHP 8.0\/8.1\/8.2\/8.x on Debian 11"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to install PHP 8.0\/8.1\/8.2\/8.x on Debian 11. <em><a href=\"https:\/\/www.php.net\/releases\/8.0\/en.php\" target=\"_blank\" rel=\"noreferrer noopener\">PHP 8.x<\/a> is a major update of the PHP language.<br>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<\/em>.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#install-php-8-x-on-debian-11\">Install PHP 8.x on Debian 11<\/a><ul><li><a href=\"#install-sury-apt-repository\">Install SURY APT Repository<\/a><\/li><li><a href=\"#run-system-update\">Run System Update<\/a><\/li><li><a href=\"#install-php-8-x-on-debian-11-1\">Install PHP 8.x on Debian 11<\/a><ul><li><a href=\"#install-php-8-0-on-debian-11\">Install PHP 8.0 on Debian 11<\/a><\/li><li><a href=\"#install-php-8-1-on-debian-11\">Install PHP 8.1 on Debian 11<\/a><\/li><li><a href=\"#install-php-8-2-on-debian-11\">Install PHP 8.2 on Debian 11<\/a><\/li><\/ul><\/li><li><a href=\"#installing-other-php-8-0-8-1-8-2-8-x-modules\">Installing other PHP 8.0\/8.1\/8.2\/8.x modules;<\/a><\/li><li><a href=\"#how-to-set-default-php-version-on-debian\">How to Set Default PHP Version on Debian<\/a><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"install-php-8-x-on-debian-11\">Install PHP 8.x on Debian 11<\/h2>\n\n\n\n<p>The default Debian 11 repositories provide PHP 7.4;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt-cache policy php<\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>\nphp:\n  Installed: (none)\n  Candidate: 2:7.4+76\n  Version table:\n     2:7.4+76 500\n        500 http:\/\/deb.debian.org\/debian bullseye\/main amd64 Packages\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-sury-apt-repository\">Install SURY APT Repository<\/h3>\n\n\n\n<p>To install PHP 8.x, you need to install SURY, third party repositories that provides PHP packages as follows;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt -y install apt-transport-https lsb-release ca-certificates curl wget gnupg2<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>wget -qO- https:\/\/packages.sury.org\/php\/apt.gpg | gpg --dearmor &gt; \/etc\/apt\/trusted.gpg.d\/sury-php-8.x.gpg<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sh -c 'echo \"deb https:\/\/packages.sury.org\/php\/ $(lsb_release -sc) main\" &gt; \/etc\/apt\/sources.list.d\/php.list'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"run-system-update\">Run System Update<\/h3>\n\n\n\n<p>Re-synchronize your system packages to the latest versions;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-php-8-x-on-debian-11-1\"><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\"><\/meta>Install PHP 8.x on Debian 11<\/h3>\n\n\n\n<p>PHP 8 is now available for installation;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-cache policy php<\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>\nphp:\n  Installed: (none)\n  Candidate: 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc\n  Version table:\n     2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc 500\n        500 https:\/\/packages.sury.org\/php bullseye\/main amd64 Packages\n     2:7.4+76 500\n        500 http:\/\/deb.debian.org\/debian bullseye\/main amd64 Packages\n<\/code><\/pre>\n\n\n\n<p>You can now install PHP 8.x as follows;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-php-8-0-on-debian-11\">Install PHP 8.0 on Debian 11<\/h4>\n\n\n\n<p>To install PHP 8.0 on Debian 11, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install php8.0<\/code><\/pre>\n\n\n\n<p>This command will install PHP 8.0 along with other required package dependencies.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>Reading package lists... Done\nBuilding dependency tree... Done\nReading state information... Done\nThe following additional packages will be installed:\n  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 libsodium23 php-common\n  php8.0-cli php8.0-common php8.0-opcache php8.0-readline ssl-cert\nSuggested packages:\n  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear\nThe following NEW packages will be installed:\n  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 libsodium23 php-common\n  php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline ssl-cert\n0 upgraded, 18 newly installed, 0 to remove and 3 not upgraded.\nNeed to get 6,658 kB of archives.\nAfter this operation, 28.5 MB of additional disk space will be used.\nDo you want to continue? [Y\/n] y\n<\/code><\/pre>\n\n\n\n<p>Confirming the installed version;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>\nPHP 8.0.28 (cli) (built: Feb 14 2023 18:26:48) ( NTS )\nCopyright (c) The PHP Group\nZend Engine v4.0.28, Copyright (c) Zend Technologies\n    with Zend OPcache v8.0.28, Copyright (c), by Zend Technologies\n\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-php-8-1-on-debian-11\">Install PHP 8.1 on Debian 11<\/h4>\n\n\n\n<p>To install PHP 8.1 on Debian 11, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install php8.1<\/code><\/pre>\n\n\n\n<p>This command will install PHP 8.1 along with other required package dependencies.<\/p>\n\n\n\n<p>Confirming the installed version;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>\nPHP 8.1.17 (cli) (built: Mar 16 2023 14:37:38) (NTS)\nCopyright (c) The PHP Group\nZend Engine v4.1.17, Copyright (c) Zend Technologies\n    with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-php-8-2-on-debian-11\">Install PHP 8.2 on Debian 11<\/h4>\n\n\n\n<p>To install PHP 8.2 on Debian 11, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install php8.2<\/code><\/pre>\n\n\n\n<p>This command will install PHP 8.2 along with other required package dependencies.<\/p>\n\n\n\n<p>Confirming the installed version;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>\nPHP 8.2.4 (cli) (built: Mar 16 2023 14:37:38) (NTS)\nCopyright (c) The PHP Group\nZend Engine v4.2.4, Copyright (c) Zend Technologies\n    with Zend OPcache v8.2.4, Copyright (c), by Zend Technologies\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-other-php-8-0-8-1-8-2-8-x-modules\">Installing other PHP 8.0\/8.1\/8.2\/8.x modules;<\/h3>\n\n\n\n<p>You can install other PHP 8.x modules using the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install php8.N-EXTENSION<\/code><\/pre>\n\n\n\n<p>Where N is the minor version of PHP 8 which can either be 0, 1, 2&#8230;<\/p>\n\n\n\n<p>Replace <strong>EXTENSION<\/strong> with the specific module\/extension. For example, for PHP 8.0 modules;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install php8.0-mysql php8.0-xml<\/code><\/pre>\n\n\n\n<p>And that is it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-set-default-php-version-on-debian\">How to Set Default PHP Version on Debian<\/h3>\n\n\n\n<p>You can set the default PHP version using the <code>update-alternatives<\/code> command.<\/p>\n\n\n\n<p>If you have multiple versions of PHP installed, there could be some situations that might make you choose a default version to use.<\/p>\n\n\n\n<p>You can list the paths of the installed PHP versions by running the command <code>update-alternatives --list php<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>update-alternatives --list php<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/bin\/php8.0\n\/usr\/bin\/php8.1\n\/usr\/bin\/php8.2<\/code><\/pre>\n\n\n\n<p>Thus, to set the default PHP version, you can use the <code>update-alternatives<\/code> command with the <code>--config<\/code> 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;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>update-alternatives --set php \/usr\/bin\/php8.1<\/code><\/pre>\n\n\n\n<p>You can also run the command interactively by omitting the path to PHP;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>update-alternatives --config php<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nThere are 3 choices for the alternative php (providing \/usr\/bin\/php).\n\n  Selection    Path             Priority   Status\n------------------------------------------------------------\n* 0            \/usr\/bin\/php8.2   82        auto mode\n  1            \/usr\/bin\/php8.0   80        manual mode\n  2            \/usr\/bin\/php8.1   81        manual mode\n  3            \/usr\/bin\/php8.2   82        manual mode\n\nPress &lt;enter> to keep the current choice[*], or type selection number:\n<\/code><\/pre>\n\n\n\n<p>To set a specific version of PHP as the default version, simply choose a number and press ENTER.<\/p>\n\n\n\n<p>For example, in the above prompt, you can enter 2 and press ENTER to set PHP 8.1 as the default version;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nThere are 3 choices for the alternative php (providing \/usr\/bin\/php).\n\n  Selection    Path             Priority   Status\n------------------------------------------------------------\n* 0            \/usr\/bin\/php8.2   82        auto mode\n  1            \/usr\/bin\/php8.0   80        manual mode\n  2            \/usr\/bin\/php8.1   81        manual mode\n  3            \/usr\/bin\/php8.2   82        manual mode\n\nPress &lt;enter> to keep the current choice[*], or type selection number: 2\nupdate-alternatives: using \/usr\/bin\/php8.1 to provide \/usr\/bin\/php (php) in manual mode\n<\/code><\/pre>\n\n\n\n<p>Confirm the version;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP 8.1.17 (cli) (built: Mar 16 2023 14:37:38) (NTS)\nCopyright (c) The PHP Group\nZend Engine v4.1.17, Copyright (c) Zend Technologies\n    with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies<\/code><\/pre>\n\n\n\n<p>That is all on how to install PHP 8.x on Debian 11.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-mysql-8-on-debian-11\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install MySQL 8 on Debian 11<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-mariadb-10-6-on-debian-11\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install MariaDB 10.6 on Debian 11<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to install PHP 8.0\/8.1\/8.2\/8.x on Debian 11. PHP 8.x is a major update of the PHP language.It contains<\/p>\n","protected":false},"author":1,"featured_media":10159,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,342],"tags":[3993,3988,3989,6452,6453,3992,3990,3991,3994],"class_list":["post-10157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-php","tag-debian-11-install-php-8","tag-install-php-8-debian-11","tag-install-php-8-0-debian-11","tag-install-php-8-1-on-debian-11","tag-install-php-8-2-on-debian","tag-php-8","tag-php-8-debian-11","tag-php-8-0-debian-11","tag-sury-php-8-repository","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10157"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=10157"}],"version-history":[{"count":6,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10157\/revisions"}],"predecessor-version":[{"id":21682,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10157\/revisions\/21682"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10159"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=10157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=10157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=10157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}