{"id":10167,"date":"2021-08-23T19:57:40","date_gmt":"2021-08-23T16:57:40","guid":{"rendered":"https:\/\/kifarunix.com\/?p=10167"},"modified":"2024-03-18T18:45:27","modified_gmt":"2024-03-18T15:45:27","slug":"install-php-7-1-7-2-7-3-7-4-on-debian-11","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-php-7-1-7-2-7-3-7-4-on-debian-11\/","title":{"rendered":"Install PHP 7.1\/7.2\/7.3\/7.4 on Debian 11"},"content":{"rendered":"\n

If you want to learn how to install PHP 7.1\/7.2\/7.3\/7.4 on Debian 11, then follow through this guide. <\/p>\n\n\n\n

PHP<\/a> is a fast, flexible, pragmatic, popular general-purpose scripting language that is especially suited to web development.<\/p>\n\n\n\n

Install PHP 7.X on Debian 11<\/h2>\n\n\n\n

The default Debian 11 repositories provide PHP 7.4;<\/p>\n\n\n\n

apt-cache policy php<\/code><\/pre>\n\n\n\n
php:\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<\/code><\/pre>\n\n\n\n

Install PHP 7.4 on Debian 11<\/h3>\n\n\n\n

As seen from the command output above, the default Debian 11 main repositories provide PHP 7.4.<\/p>\n\n\n\n

This make it easy install PHP 7.4 on Debian 11.<\/p>\n\n\n\n

apt install php<\/code><\/pre>\n\n\n\n
\nThe following additional packages will be installed:\n  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libcurl4 liblua5.3-0 libsodium23\n  php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline psmisc 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-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libcurl4 liblua5.3-0 libsodium23 php\n  php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline psmisc ssl-cert\n0 upgraded, 22 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 7,262 kB of archives.\nAfter this operation, 28.3 MB of additional disk space will be used.\nDo you want to continue? [Y\/n] y\n<\/code><\/pre>\n\n\n\n

Once the installation command completes, run the command below to verify the installed version of PHP on Debian 11;<\/p>\n\n\n\n

php -v<\/code><\/pre>\n\n\n\n
PHP 7.4.21 (cli) (built: Jul  2 2021 03:59:48) ( NTS )\nCopyright (c) The PHP Group\nZend Engine v3.4.0, Copyright (c) Zend Technologies\n    with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies<\/code><\/pre>\n\n\n\n

Install PHP 7.4 Modules on Debian 11<\/h3>\n\n\n\n

By default, quite a number of PHP 7.4 modules are already enabled.<\/p>\n\n\n\n

php -m<\/code><\/pre>\n\n\n\n
\n[PHP Modules]\ncalendar\nCore\nctype\ndate\nexif\nFFI\nfileinfo\nfilter\nftp\ngettext\nhash\niconv\njson\nlibxml\nopenssl\npcntl\npcre\nPDO\nPhar\nposix\nreadline\nReflection\nsession\nshmop\nsockets\nsodium\nSPL\nstandard\nsysvmsg\nsysvsem\nsysvshm\ntokenizer\nZend OPcache\nzlib\n\n[Zend Modules]\nZend OPcache\n<\/code><\/pre>\n\n\n\n

To install additional modules, first check if the modules is provided by the default repositories;<\/p>\n\n\n\n

apt-cache search php7.4-EXTENSION<\/code><\/pre>\n\n\n\n

Where EXTENSION<\/strong> is the PHP module you want to install. For example;<\/p>\n\n\n\n

apt-cache search php7.4-mysql<\/code><\/pre>\n\n\n\n

If the module is available, then install it using the command;<\/p>\n\n\n\n

apt install php7.4-EXTENSION<\/code><\/pre>\n\n\n\n

For example;<\/p>\n\n\n\n

apt install php7.4-mysql<\/code><\/pre>\n\n\n\n

Install PHP 7.1\/7.2\/7.3 on Debian 11<\/h3>\n\n\n\n

Install SURY Repository<\/h4>\n\n\n\n

In order to install PHP 7.1\/7.2\/7.3 on Debian 11, you need to add SURY, the third party repositories that provides PHP packages for Debian systems.<\/p>\n\n\n\n

To add SURY repository on Debian 11, run the commands below;<\/p>\n\n\n\n

apt -y install apt-transport-https lsb-release ca-certificates curl wget<\/code><\/pre>\n\n\n\n
wget -O \/etc\/apt\/trusted.gpg.d\/php.gpg https:\/\/packages.sury.org\/php\/apt.gpg<\/code><\/pre>\n\n\n\n
sh -c 'echo \"deb https:\/\/packages.sury.org\/php\/ $(lsb_release -sc) main\" > \/etc\/apt\/sources.list.d\/php.list'<\/code><\/pre>\n\n\n\n

Next, update the system package cache;<\/p>\n\n\n\n

apt update<\/code><\/pre>\n\n\n\n

Install PHP 7.1 on Debian 11<\/h4>\n\n\n\n

Once the repository is in place, install PHP 7.1 on Debian 11 by executing the command;<\/p>\n\n\n\n

apt install php7.1<\/code><\/pre>\n\n\n\n

To install PHP 7.1 modules, run the command;<\/p>\n\n\n\n

apt install php7.1-EXTENSION<\/code><\/pre>\n\n\n\n

Install PHP 7.2 on Debian 11<\/h4>\n\n\n\n

To install PHP 7.2 on Debian 11 by executing the command;<\/p>\n\n\n\n

apt install php7.2<\/code><\/pre>\n\n\n\n

To install PHP 7.2 modules, run the command;<\/p>\n\n\n\n

apt install php7.2-EXTENSION<\/code><\/pre>\n\n\n\n

Install PHP 7.3 on Debian 11<\/h4>\n\n\n\n

Once the repository is in place, install PHP 7.3 on Debian 11 by executing the command;<\/p>\n\n\n\n

apt install php7.3<\/code><\/pre>\n\n\n\n

To install PHP 7.3 modules, run the command;<\/p>\n\n\n\n

apt install php7.3-EXTENSION<\/code><\/pre>\n\n\n\n

Set default PHP version on Debian 11<\/h3>\n\n\n\n

If you have multiple versions of PHP installed on Debian 11, you can choose to make one of the versions as the default PHP version.<\/p>\n\n\n\n

To list the available versions;<\/p>\n\n\n\n

update-alternatives --config php<\/code><\/pre>\n\n\n\n

Sample command output;<\/p>\n\n\n\n

There are 4 choices for the alternative php (providing \/usr\/bin\/php).\n\n  Selection    Path             Priority   Status\n------------------------------------------------------------\n* 0            \/usr\/bin\/php7.4   74        auto mode\n  1            \/usr\/bin\/php7.1   71        manual mode\n  2            \/usr\/bin\/php7.2   72        manual mode\n  3            \/usr\/bin\/php7.3   73        manual mode\n  4            \/usr\/bin\/php7.4   74        manual mode\n\nPress <enter> to keep the current choice[*], or type selection number:<\/code><\/pre>\n\n\n\n

As you can see, we have PHP 7.4 as the default version of PHP.<\/p>\n\n\n\n

To change the default version, simply enter the number that matched the appropriate version you want to make as the default and press ENTER.<\/p>\n\n\n\n

For example, to make PHP 7.2 as the default version, simply type 2 and press ENTER.<\/p>\n\n\n\n

You can simply execute the command below to change the version straight away;<\/p>\n\n\n\n

update-alternatives --set php \/usr\/bin\/php7.2<\/code><\/pre>\n\n\n\n

Checking the version;<\/p>\n\n\n\n

php -v<\/code><\/pre>\n\n\n\n
PHP 7.2.34-23+0~20210701.63+debian11~1.gbpd7cd48 (cli) (built: Jul  1 2021 16:13:42) ( NTS )\nCopyright (c) 1997-2018 The PHP Group\nZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies\n    with Zend OPcache v7.2.34-23+0~20210701.63+debian11~1.gbpd7cd48, Copyright (c) 1999-2018, by Zend Technologies<\/code><\/pre>\n\n\n\n

And that is it on how to you can install PHP 7.x on Debian 11.<\/p>\n\n\n\n

Other Tutorials<\/h3>\n\n\n\n

Install PHP 8 on Debian 11<\/a><\/p>\n\n\n\n

Install MySQL 8 on Debian 11<\/a><\/p>\n\n\n\n

Install MariaDB 10.6 on Debian 11<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

If you want to learn how to install PHP 7.1\/7.2\/7.3\/7.4 on Debian 11, then follow through this guide. PHP is a fast, flexible, pragmatic, popular<\/p>\n","protected":false},"author":1,"featured_media":10170,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121],"tags":[3995,3999,3996,3997,3998,203,4000,1267,343,1132],"class_list":["post-10167","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-install-php-7-1-debian-11","tag-install-php-7-1-7-2-7-3-7-4-on-debian-11","tag-install-php-7-2-debian-11","tag-install-php-7-3-debian-11","tag-install-php-7-4-debian-11","tag-php","tag-php-7-1","tag-php-7-2","tag-php-7-3","tag-php-7-4","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\/10167"}],"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=10167"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10167\/revisions"}],"predecessor-version":[{"id":21680,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10167\/revisions\/21680"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10170"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=10167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=10167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=10167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}