# TL;DR version

Here is the short version of setting up PHP version 7.3 on your Ubuntu Machine (I am currently on v 20.04)

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.3

# Detailed Version

Installing PHP 7.3 on Ubuntu v 20.04

Here are the steps.

# 1. Add PPA repository

Open the terminal and add the following repository

sudo apt-get-repository ppa:ondrej/php

sudo apt-add-repository ppa php

# 2. Run apt-get update

The sudo apt-get update command is used to download package information from all configured sources. Run the apt-get update command to download the latest package information.

sudo apt-get update

sudo apt-get update

# 3. Install PHP

The next and final step is to install PHP, Run the following command in your terminal.

sudo apt-get install -y php7.3

This command will download the given version of PHP from the repository and will install on the local Ubuntu machine.

sudo apt-get install -y php 7.3

# PHP -v

Run the command php -v to test if PHP has been installed successfully.

php -v

php -v ubuntu

# PHP.ini Location

Once PHP is installed you may want to know the location of PHP.ini configuration file. PHP.ini holds all the default configuration of PHP and editing this file can be used to override the default values.

Here is the location where PHP is installed

/etc/php/7.3

There are two php.ini configuration file in your PHP installation, one for the CLI (Command line interface) and another for the Web (Apache2). Following are the location of both php.ini files

/etc/php/7.3/apache2/php.ini

/etc/php/7.3/cli/php.ini

# Additional Modules Installed

Following are the additional modules that got installed as part of PHP dependencies

  • libapr1:amd64
  • libaprutil1:amd64
  • libaprutil1-dbd-sqlite3
  • libaprutil1-ldap:amd64
  • apache2-bin
  • apache2-data
  • apache2-utils
  • apache2
  • php-common
  • php7.3-common
  • php7.3-json
  • php7.3-opcache
  • php7.3-readline
  • php7.3-cli
  • libapache2-mod-php7.3

To get the list of modules installed with PHP, you can run the following command

php -m

# PHP Built-in WebServer

PHP comes with a builtin HTTP WebServer , To test the PHP script, create a new folder and create new file named index.php inside it.

Open the terminal and navigate to the newly created directory and run the following command

php -S localhost:8000

This will fire up the server on port 8000, You can now access the PHP webpage in your browser by going to http://localhost:8000
Put the following code in the index.php file

<?php
phpinfo();
?>

phpinto output

# PHP Installation Location

The executable PHP Binaries are installed in the /usr/bin directory

/usr/bin/php
/usr/bin/php7.3

The Additional PHP modules are installed in /usr/share directory

/usr/share/php7.3-json 
/usr/share/php7.3-common 
/usr/share/php7.3-readline

Ini files for PHP and different modules are available under /etc/php directory


/etc/php/7.3/apache2/php.ini
/etc/php/7.3/cli/php.ini

Modules INI

/etc/php/7.3/mods-available/pods.ini
/etc/php/7.3/mods-available/json.ini
...

That's all about Installing PHP on your Ubuntu Machine

Comments