Install PHP and Common PHP Extensions for Compatible with Apache2 and MySQL

Experiment with PHP 7.4

3 years ago SETHA THAY 3811
Install PHP and Common PHP Extensions for Compatible with Apache2 and MySQL

PHP is a programming language that is widely used all around the world. Facebook, the biggest social media platform nowadays also begin its journey with PHP as well. In order to host your web application written in PHP or any kind of PHP framework such as Laravel, Cake PHP, etc, you have to install PHP with a fit compatible version in your development environment after finishing installing Apache2 which is written in a post "How to install apache2 on your cloud server ubuntu 10.04"

DigitalOcean Referral Badge

Step 1: Update your server

First, you have to update your server. By executing the below command doesn't actually install new versions of software on the server. Instead, it updates the package lists for upgrades for packages that need upgrading, as well as welcomes a new package that has just been added into the repositories.

sudo apt-get update

Step 2: Installing PHP 7.4

Finding the correct version of PHP is crucial for production deployment as well as the development environment or staging/testing environment. We have to make sure we have the same version of PHP in all environments to prevent any method deprecation that might happen in the higher version or not supported method in the old version. This is also the reason why docker exists. we will cover the docker in another post later.

sudo apt-get install php7.4

Step 3: Installing Common PHP 7.4 Extensions

When you install PHP with the above command, you only got the core feature of PHP. If you want more features in your application like working with MySQL database you have to install PHP extension that works perfectly with MySQL (php7.4-mysql). If you work with XML you have to install php7.4-xml. Below are list of common extensions which we usually work with.

sudo apt-get install php7.4-bcmath php7.4-bz2 php7.4-intl php7.4-gd php7.4-mbstring php7.4-mysql php7.4-zip php7.4-fpm php7.4-curl php7.4-json php7.4-cgi php7.4-xsl php7.4-xml php7.4-soap php7.4-zip php7.4-common

Step 4: Check installed version on PHP

Once everything is installed, you can check whether your PHP is running properly by using the below command. Remember that you can have multiple versions in your server so make sure which version and configuration you are actually using with to configure your application.

php --version

PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Step 5: Create index.php file to check PHP info on web browser

This step is just a small snippet of code we can do you list information of php as well as common extensions that we just installed using function phpinfo();

cd /var/www/html/

sudo vi index.php

<?php
phpinfo();
?>

Open your web browser and type HTTP://your_ip_address/index.php

installing-php-and-common-php-extensions-result


About author

Author Profile

SETHA THAY

Software Engineer & Project Manager. I am willing to share IT knowledge, technical experiences and investment to financial freedom. Feel free to ask and contact me.



Scroll to Top