Home > Operation and Maintenance > Linux Operation and Maintenance > How to install php7.2, php7.3, php7.4 in Ubuntu? (Detailed explanation of method)

How to install php7.2, php7.3, php7.4 in Ubuntu? (Detailed explanation of method)

青灯夜游
Release: 2020-07-18 15:42:31
forward
8671 people have browsed it

How to install php7.2, php7.3, php7.4 in Ubuntu? (Detailed explanation of method)

Works with any Ubuntu version and other Ubuntu-based versions. Ubuntu 14.04, Ubuntu 16.04, Ubuntu 18.04 or even Ubuntu 19.10.

Before you begin

PHP has different versions and distributions that you can use. The current PHP official website supports the oldest version (PHP 7.2) to PHP 7.3 and the latest version (PHP 7.4).

This blog provides instructions for PHP 7.4, PHP 7.2 (the default in Ubuntu 18.04), and the default PHP version (PHP 7) in the Ubuntu 16.04 repository.

It is recommended that you install PHP 7.3 because it is stable and has many improvements and new features. If you are still using PHP 7.1, you will definitely need to upgrade as soon as possible, as its security support will end at the end of 2019.

Install PHP 7.4 on Ubuntu 18.04 or 16.04

PHP 7.4 is the latest version of PHP with many improvements. These instructions are very similar to PHP 7.3.

Update Ubuntu

First, update your Ubuntu server:

apt-get update && apt-get upgrade
Copy after login

Add PHP Storage Repository

To install PHP 7.4, you need to use a third-party repository. We will use the repository of Ondřej Surý that we have used again before.

First, make sure you have the following packages installed so you can add the repository:

apt-get install software-properties-common
Copy after login

Next, add the PHP repository from Ondřej:

add-apt-repository ppa:ondrej/php
Copy after login

Finally, update the installation Package:

apt-get update
Copy after login

Install PHP 7.4

After adding the repository, you can install PHP 7.4 using the following command:

apt-get install php7.4
Copy after login

This command will install additional packages:

  • libapache2-mod-php7.4

  • libaprutil1-dbd-sqlite3

  • php7.4-cli

  • php7.4-common

  • php7.4-json

  • php7.4-opcache

  • php7.4-readline

  • Wait...
    That’s it . To check if PHP 7.4 is installed on your server, run the following command:

php -v
Copy after login
Copy after login
Copy after login
Copy after login

Install PHP 7.4 Modules

Depending on your application, you may need additional packages and modules. The most commonly used modules can be installed using the following command:

apt-get install php-pear php7.4-curl php7.4-dev php7.4-gd php7.4-mbstring php7.4-zip php7.4-mysql php7.4-xml
Copy after login

Just like that, you can start using PHP on your Ubuntu server.

Installing PHP 7.2 on Ubuntu 16.04

PHP 7.2 is the stable version of PHP with many new features, improvements, and bug fixes. If you want a better and faster website/app, you should definitely use it.

Update Ubuntu

Of course, as always, update Ubuntu first:

apt-get update && apt-get upgrade
Copy after login
Copy after login
Copy after login

Add PHP Storage Repositories

You can use third-party repositories to install the latest version of PHP. We will use Ondřej Surý’s repository.

First, make sure you have the following packages installed so you can add the repository:

apt-get install software-properties-common
Copy after login
Copy after login

Next, add the PHP repository from Ondřej:

add-apt-repository ppa:ondrej/php
Copy after login
Copy after login

Finally, update the installation Package:

apt-get update
Copy after login
Copy after login

Install PHP 7.2

After adding the repository, you can install PHP 7.2 using the following command:

apt-get install php7.2
Copy after login

This command will install additional packages:

  • ibapache2-mod-php7.2

  • libargon2-0

  • libsodium23

  • libssl1.1

  • php7.2-cli

  • ##php7 .2-common

  • php7.2-json

  • ##php7.2-opcache
  • php7.2-readline
  • That’s it. To check if PHP 7.2 is installed on your server, run the following command:
php -v
Copy after login
Copy after login
Copy after login
Copy after login

Install PHP 7.2 ModuleAccording to your application, You may need other packages and modules. The most commonly used modules can be installed using the following command:

apt-get install php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml
Copy after login

Just like that, you can start using PHP on your Ubuntu server.

Install PHP 7.2 on Ubuntu 18.04

Update UbuntuAgain, before doing anything, you should update your server:

apt-get update && apt-get upgrade
Copy after login
Copy after login
Copy after login

Install PHP 7.2Next, on Ubuntu 18.04 To install PHP 7.2, just run the following command:

apt-get install php
Copy after login

This command will install PHP 7.2 along with some other dependencies.

To verify that PHP is installed, run the following command:

php -v
Copy after login
Copy after login
Copy after login
Copy after login

You should get a response similar to the following:

PHP 7.2.3-1ubuntu1 (cli) (built: Mar 14 2018 22:03:58) ( NTS )
Copy after login

That’s it. PHP 7.2 is installed on Ubuntu 18.04 server.

Install PHP 7.2 ModulesThese are the most common PHP 7.2 modules that are often used by php applications. You may need more or less, so check the requirements for the software you plan to use:

apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
Copy after login

To check all available PHP modules in Ubuntu, run:

apt-cache search --names-only ^php
Copy after login

Install PHP 7.3 on Ubuntu 18.04 or 16.04

PHP 7.3是一个稳定的版本,可以在服务器上安全使用。

更新Ubuntu

首先,更新你的Ubuntu服务器:

apt-get update && apt-get upgrade
Copy after login
Copy after login
Copy after login

添加PHP存储库

要安装PHP 7.3,您需要使用第三方存储库。我们将使用以前使用的OndřejSurý的存储库。

首先,请确保已安装以下软件包,以便可以添加存储库:

apt-get install software-properties-common
Copy after login
Copy after login

接下来,从Ondřej添加PHP存储库:

add-apt-repository ppa:ondrej/php
Copy after login
Copy after login

最后,更新安装包

apt-get update
Copy after login
Copy after login

安装PHP 7.3

添加存储库后,可以使用以下命令安装PHP 7.3:

apt-get install php7.3
Copy after login

此命令将安装其他软件包:

  • libapache2-mod-php7.3

  • libaprutil1-dbd-sqlite3

  • php7.3-cli

  • php7.3-common

  • php7.3-json

  • php7.3-opcache

  • php7.3-readline

  • 等等其他……
    就是这样。要检查服务器上是否安装了PHP 7.3,请运行以下命令:

php -v
Copy after login
Copy after login
Copy after login
Copy after login

安装PHP 7.3模块
根据你的应用程序,你可能需要其他软件包和模块。可以使用以下命令安装最常用的模块:

apt-get install php-pear php7.3-curl php7.3-dev php7.3-gd php7.3-mbstring php7.3-zip php7.3-mysql php7.3-xml
Copy after login

就这样。现在,你可以在Ubuntu服务器上开始使用PHP。

如何更改你使用的PHP版本

如果你在Ubuntu服务器上安装了多个PHP版本,则可以更改默认版本。

要将PHP 7.2设置为默认值,请运行:

update-alternatives --set php /usr/bin/php7.2
Copy after login

要将PHP 7.3设置为默认值,请运行:

update-alternatives --set php /usr/bin/php7.3
Copy after login

要将PHP 7.4设置为默认值,请运行:

update-alternatives --set php /usr/bin/php7.4
Copy after login

相关教程推荐:《linux教程》、《PHP教程

The above is the detailed content of How to install php7.2, php7.3, php7.4 in Ubuntu? (Detailed explanation of method). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template