Installing PHP

Learn how to install PHP on a Linux Ubuntu operating system.

Run the following commands in the terminal below to install PHP and the required PHP packages.

Update Linux packages

First, we must update our Linux packages and upgrade the current packages. We can do so by running the following command:

sudo apt update && sudo apt upgrade -y 

We’ll be prompted to input a password, which is educativecourse.

Update apt repositories with common software packages.

sudo apt install -y software-properties-common

Add PHP repository and update

Now, add the PHP repository.

sudo add-apt-repository -y ppa:ondrej/php

Update the Linux apt packages.

sudo apt update

Install PHP

Now, we can install PHP 8.1.

sudo apt install -y php8.1 

Check PHP

Now, check if PHP is installed.

php -v

Successful installation should look somewhat like this:

php -v
PHP 8.1.12 (cli) (built: Oct 28 2022 17:39:57) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies

Well done! Now, you have PHP 8 installed.

Get hands-on with 1200+ tech skills courses.