How To Install PHP 7.4 on Ubuntu!

How To Install PHP 7.4 on Ubuntu!

Written by Adam. R on Sep 26th, 2021 ・ Views ・ Report Post

Installation

Step 1. Setting Up PHP 7.4

Run the following command to update apt-get itself, which ensures that you have access to the latest versions of anything you want to install:

sudo apt-get update

Next, install software-properties-common, which adds management for additional software sources:

sudo apt -y install software-properties-common

The -y flag will automatically agree to the installation. Without that, you would receive a prompt in your terminal window for each installation.

Next, install the repository ppa:ondrej/php, which will give you all your versions of PHP:

sudo add-apt-repository ppa:ondrej/php

Finally, you update apt-get again so your package manager can see the newly listed packages:

sudo apt-get update

Now you’re ready to install PHP 7.4 using the following command:

sudo apt -y install php7.4

Check the version installed:

php -v

You will receive something similar to the following:

PHP 7.4.0beta4 (cli) (built: Aug 28 2019 11:41:49) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0beta4, Copyright (c), by Zend Technologies

Besides PHP itself, you will likely want to install some additional PHP modules. You can use this command to install additional modules, replacing PACKAGE_NAME with the package you wish to install:

sudo apt-get install php7.4-PACKAGE_NAME

You can also install more than one package at a time. Here are a few suggestions of the most common modules you will most likely want to install:

sudo apt-get install -y php7.4-cli php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath

This command will install the following modules:

 - php7.4-cli
 - php7.4-json
 - php7.4-common
 - php7.4-mysql
 - php7.4-zip
 - php7.4-gd
 - php7.4-mbstring
 - php7.4-curl
 - php7.4-xml
 - php7.4-bcmath

PHP configurations related to Apache are stored in /etc/php/7.4/apache2/php.ini. You can list all loaded PHP modules with the following command:

php -m

You have installed PHP and verified the version you have running. You also installed any required PHP modules and were able to list the modules that you have loaded.

You could start using PHP right now, but you will likely want to use various libraries to build PHP applications quickly. Before you test your PHP environment, first set up a dependency manager for your projects.


That’s it, you have successfully installed PHP on your Ubuntu Server and you can start using it!

If you found this usful then please share this and follow me! Also check out my website where I also post everything from here

Comments (0)