search
HomeOperation and MaintenanceLinux Operation and MaintenanceHow 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)

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

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

Next, add the PHP repository from Ondřej:

add-apt-repository ppa:ondrej/php

Finally, update the installation Package:

apt-get update

Install PHP 7.4

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

apt-get install php7.4

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

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

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

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

Next, add the PHP repository from Ondřej:

add-apt-repository ppa:ondrej/php

Finally, update the installation Package:

apt-get update

Install PHP 7.2

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

apt-get install php7.2

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

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

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

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

apt-get install php

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

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

php -v

You should get a response similar to the following:

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

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

To check all available PHP modules in Ubuntu, run:

apt-cache search --names-only ^php

Install PHP 7.3 on Ubuntu 18.04 or 16.04

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

更新Ubuntu

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

apt-get update && apt-get upgrade

添加PHP存储库

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

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

apt-get install software-properties-common

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

add-apt-repository ppa:ondrej/php

最后,更新安装包

apt-get update

安装PHP 7.3

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

apt-get install php7.3

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

  • 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

安装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

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

如何更改你使用的PHP版本

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

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

update-alternatives --set php /usr/bin/php7.2

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

update-alternatives --set php /usr/bin/php7.3

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

update-alternatives --set php /usr/bin/php7.4

相关教程推荐:《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!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
What is Maintenance Mode in Linux? ExplainedWhat is Maintenance Mode in Linux? ExplainedApr 22, 2025 am 12:06 AM

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

Linux: A Deep Dive into Its Fundamental PartsLinux: A Deep Dive into Its Fundamental PartsApr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

Linux Architecture: Unveiling the 5 Basic ComponentsLinux Architecture: Unveiling the 5 Basic ComponentsApr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux Operations: Utilizing the Maintenance ModeLinux Operations: Utilizing the Maintenance ModeApr 19, 2025 am 12:08 AM

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

Linux: How to Enter Recovery Mode (and Maintenance)Linux: How to Enter Recovery Mode (and Maintenance)Apr 18, 2025 am 12:05 AM

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool