Configure multiple php version on ubuntu

In this article I will explain how khổng lồ install the latest PHP version on the Ubuntu operating system. Your system may not always have the latest packages for installing PHP. However, PPA (Personal Package Archive), which contains the missing packages, can help us. PHP 7.4 is the latest stable version available for installation. You can also install PHP 7.3, PHP 7.2, PHP 7.1, PHP 7.0 with this instruction.Bạn vẫn xem: Install php 7

Adding PHP repository

Let"s địa chỉ cửa hàng the PHP repository lớn the system. But first install the necessary software.

Before any software installation, it is recommended to update the các mục of repository packages by running the command in the terminal:

sudo apt-get updateNow install the necessary software:

sudo apt-get install software-properties-commonAdd the PHP repository (Ondřej Surý) lớn the danh sách of sources:

sudo add-apt-repository ppa:ondrej/php

Bạn đang xem: Configure multiple php version on ubuntu

*

Installing PHP 7.x

First you need to lớn update the danh mục of repository packages by running the command in the terminal:

sudo apt-get updateThen install PHP 7.x by running the command in the terminal:

for PHP 7.4

sudo apt-get install php7.4for PHP 7.3sudo apt-get install php7.3for PHP 7.2sudo apt-get install php7.2for PHP 7.1sudo apt-get install php7.1for PHP 7.0sudo apt-get install php7.0You can also install PHP 8.x on Ubuntu.

Additionally, the necessary packages will be installed, some of which are standard PHP 7.x extensions:

libapache2-mod-php7.4 libpcre2-8-0 php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline


*

Xem thêm: Sửa Lỗi Monitor Going To Sleep, Not Starting Computer, Monitor Going To Sleep, Not Starting Computer

Installing PHP 7.x extensions

The following syntax is used to install PHP 7.x extensions:

sudo apt-get install php7.x-extension

or

sudo apt-get install php-extension

Let"s install the most commonly used PHP 7.x extensions by running the command in the terminal:

for PHP 7.4

sudo apt-get install php7.4-mysql php7.4-mbstring php7.4-xml php7.4-bcmath php7.4-curl php7.4-gd php7.4-zipfor PHP 7.3sudo apt-get install php7.3-mysql php7.3-mbstring php7.3-xml php7.3-bcmath php7.3-curl php7.3-gd php7.3-zipfor PHP 7.2sudo apt-get install php7.2-mysql php7.2-mbstring php7.2-xml php7.2-bcmath php7.2-curl php7.2-gd php7.2-zipfor PHP 7.1sudo apt-get install php7.1-mysql php7.1-mbstring php7.1-xml php7.1-bcmath php7.1-curl php7.1-gd php7.1-zipfor PHP 7.0sudo apt-get install php7.0-mysql php7.0-mbstring php7.0-xml php7.0-bcmath php7.0-curl php7.0-gd php7.0-zip

*

Testing PHP

Let"s find out the version of installed PHP by running the command in the terminal:

php -vCreate a test file that will return information about our vps by running the command in the terminal:

echo "" | sudo tee /var/www/html/info.phpLet"s make sure that the hệ thống correctly displays the nội dung generated by the PHP script by opening this page in the browser:

http://192.168.0.101/info.php

or for localhost

http://localhost/info.php

You will see a similar page:


*

After checking for security reasons, you need to lớn delete this tệp tin by running the command in the terminal: