{"id":11312,"date":"2022-01-18T22:24:00","date_gmt":"2022-01-18T19:24:00","guid":{"rendered":"https:\/\/kifarunix.com\/?p=11312"},"modified":"2024-03-14T19:11:05","modified_gmt":"2024-03-14T16:11:05","slug":"install-php-7-1-7-2-7-3-7-4-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-php-7-1-7-2-7-3-7-4-on-ubuntu-22-04\/","title":{"rendered":"Install PHP 7.1\/7.2\/7.3\/7.4 on Ubuntu 22.04"},"content":{"rendered":"\n
In this tutorial, you will learn how to install PHP 7.1\/7.2\/7.3\/7.4 on Ubuntu 22.04. PHP<\/a> is a fast, flexible, pragmatic, popular general-purpose scripting language that is especially suited to web development.<\/p>\n\n\n\n The default Ubuntu 22.04 repositories provide PHP 8.x;<\/p>\n\n\n\n To install PHP, you need to install SURY, third party repositories that provides PHP packages.<\/p>\n\n\n\n Re-synchronize your system packages to the latest versions;<\/p>\n\n\n\n Once the SURY repos are in place, you should now be able to install PHP 7.4 on Ubuntu 22.04 by running the command below;<\/p>\n\n\n\n By default, quite a number of PHP 7.4 modules are already enabled.<\/p>\n\n\n\n To install additional modules, first check if the modules is provided by the default repositories;<\/p>\n\n\n\n Where EXTENSION<\/strong> is the PHP module you want to install. For example;<\/p>\n\n\n\n If the module is available, then install it using the command;<\/p>\n\n\n\n For example;<\/p>\n\n\n\n Once the repository is in place, install PHP 7.3 on Ubuntu 22.04 by executing the command;<\/p>\n\n\n\n To install PHP 7.3 modules, run the command;<\/p>\n\n\n\n To install PHP 7.2 on Ubuntu 22.04 by executing the command;<\/p>\n\n\n\n To install PHP 7.2 modules, run the command;<\/p>\n\n\n\n Once the repository is in place, install PHP 7.1 on Ubuntu 22.04 by executing the command;<\/p>\n\n\n\n To install PHP 7.1 modules, run the command;<\/p>\n\n\n\n If you have multiple versions of PHP installed on Ubuntu 22.04, 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 Sample command output;<\/p>\n\n\n\n As you can see, we have PHP 8.1 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.4 as the default version, simply type 3 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 Checking the version;<\/p>\n\n\n\n And that is it on how to you can install PHP 7.x on Ubuntu 22.04.<\/p>\n\n\n\n Install PHP 8 on Ubuntu 22.04<\/a><\/p>\n\n\n\n Install PHP 8 on Debian 11<\/a><\/p>\n\n\n\nInstalling PHP 7.x on Ubuntu 22.04<\/h2>\n\n\n\n
apt-cache policy php<\/code><\/pre>\n\n\n\n
php:\n Installed: (none)\n Candidate: 2:8.0+82~0build1\n Version table:\n 2:8.0+82~0build1 500\n 500 http:\/\/us.archive.ubuntu.com\/ubuntu jammy\/main amd64 Packages\n 500 http:\/\/us.archive.ubuntu.com\/ubuntu jammy\/main i386 Packages<\/code><\/pre>\n\n\n\n
Install SURY APT Repository<\/h3>\n\n\n\n
add-apt-repository ppa:ondrej\/php --yes &> \/dev\/null<\/code><\/pre>\n\n\n\n
Run System Update<\/h3>\n\n\n\n
apt update<\/code><\/pre>\n\n\n\n
Install PHP 7.4 on Ubuntu 22.04<\/h3>\n\n\n\n
apt install php7.4<\/code><\/pre>\n\n\n\n
Reading package lists... Done\nBuilding dependency tree... Done\nReading state information... Done\nThe following additional packages will be installed:\n libapache2-mod-php7.4 libffi7 libpcre2-8-0 php-common php7.4-cli\n php7.4-common php7.4-json php7.4-opcache php7.4-readline\nSuggested packages:\n php-pear\nThe following NEW packages will be installed:\n libapache2-mod-php7.4 libffi7 php7.4 php7.4-cli php7.4-common php7.4-json\n php7.4-opcache php7.4-readline\nThe following packages will be upgraded:\n libpcre2-8-0 php-common\n2 upgraded, 8 newly installed, 0 to remove and 736 not upgraded.\nNeed to get 4,365 kB of archives.\nAfter this operation, 18.0 MB of additional disk space will be used.\nDo you want to continue? [Y\/n] y\n<\/code><\/pre>\n\n\n\n
Install PHP 7.4 Modules on Ubuntu 22.04<\/h3>\n\n\n\n
php7.4 -m<\/code><\/pre>\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
apt-cache search php7.4-EXTENSION<\/code><\/pre>\n\n\n\n
apt-cache search php7.4-mysql<\/code><\/pre>\n\n\n\n
apt install php7.4-EXTENSION<\/code><\/pre>\n\n\n\n
apt install php7.4-mysql<\/code><\/pre>\n\n\n\n
Install PHP 7.3 on Ubuntu 22.04<\/h4>\n\n\n\n
apt install php7.3<\/code><\/pre>\n\n\n\n
apt install php7.3-EXTENSION<\/code><\/pre>\n\n\n\n
Install PHP 7.2 on Ubuntu 22.04<\/h4>\n\n\n\n
apt install php7.2<\/code><\/pre>\n\n\n\n
apt install php7.2-EXTENSION<\/code><\/pre>\n\n\n\n
Install PHP 7.1 on Ubuntu 22.04<\/h4>\n\n\n\n
apt install php7.1<\/code><\/pre>\n\n\n\n
apt install php7.1-EXTENSION<\/code><\/pre>\n\n\n\n
Set default PHP version on Ubuntu 22.04<\/h3>\n\n\n\n
update-alternatives --config php<\/code><\/pre>\n\n\n\n
\nThere are 4 choices for the alternative php (providing \/usr\/bin\/php).\n\n Selection Path Priority Status\n------------------------------------------------------------\n* 0 \/usr\/bin\/php8.1 81 auto mode\n 1 \/usr\/bin\/php7.2 72 manual mode\n 2 \/usr\/bin\/php7.3 73 manual mode\n 3 \/usr\/bin\/php7.4 74 manual mode\n 4 \/usr\/bin\/php8.1 81 manual mode\n\nPress
update-alternatives --set php \/usr\/bin\/php7.4<\/code><\/pre>\n\n\n\n
php -v<\/code><\/pre>\n\n\n\n
PHP 7.4.27 (cli) (built: Dec 20 2021 21:28:15) ( NTS )\nCopyright (c) The PHP Group\nZend Engine v3.4.0, Copyright (c) Zend Technologies\n with Zend OPcache v7.4.27, Copyright (c), by Zend Technologies<\/code><\/pre>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n