PHP is widely used langauge in world of web. PHP is an open sourece language and free for everyone. It’s a server side scripting lanaguge which compiles on server and can embedded with html too.
Currently, there is three version are available of PHP that are as below
PHP 5
PHP 7
PHP 8
In these 3 versions of PHP, PHP 7 is most stable version currently.
In this tutorial we will learn to install the PHP stable version in Ubuntu software repositories.
Let’s learn with step by step.
Step 1: Check stable version in the Ubuntu software repositories
sudo apt show php
it will show
Package: php
Version: 2:7.4+75
Priority: optional
Section: php
Source: php-defaults (75)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 13.3 kB
Depends: php7.4
Download-Size: 2712 B
APT-Manual-Installed: yes
APT-Sources: http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
.
This package is a dependency package, which depends on latest stable
PHP version (currently 7.4).
Step 2: Install PHP default version
sudo apt install php
//or if we want some packages also
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip php-mbstring
Step 3: Check PHP versions in CLI
php -v
It will show the output as below :
PHP 7.3.1 (cli) (built: Jul 5 2021 15:13:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.3.1, Copyright (c), by Zend Technologies
Step 4: Check in browser
Go to folder /var/www/html and create a file info.php
cd /var/www/html
Then type command to edit the or create a new file
sudo vi info.php
And type
<?php
echo phpinfo();
Then, open http://ip_domain/info.php
how to Install different version of PHP?
Sometimes it’s required to install the different version of PHP rather then the default one of Ubuntu Repository System.
To install the different version we will follow the basic steps before installation of PHP
Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.
Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa
You can get more information about the packages at https://deb.sury.org
IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.
BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting
CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
or ppa:ondrej/nginx
Step 2 : Update the system
sudo apt-get update
Step 3 : Check php versions available
sudo apt show php
Output :
Package: php
Version: 2:8.0+84+ubuntu20.04.1+deb.sury.org+1
Priority: optional
Section: php
Source: php-defaults (84+ubuntu20.04.1+deb.sury.org+1)
Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Installed-Size: 13.3 kB
Depends: php8.0
Download-Size: 6960 B
APT-Sources: http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
.
This package is a dependency package, which depends on latest stable
PHP version (currently 8.0).
Package: php
Version: 2:7.4+75
Priority: optional
Section: php
Source: php-defaults (75)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 13.3 kB
Depends: php7.4
Download-Size: 2712 B
APT-Manual-Installed: yes
APT-Sources: http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
.
This package is a dependency package, which depends on latest stable
PHP version (currently 7.4).
Now, we have installed multiple versions of php but at a time we can use one so let’s choose one PHP version
Step 1 : To check available versions of PHP
sudo update-alternatives --config php
Output:
There are 2 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php7.4 74 auto mode
1 /usr/bin/php7.0 70 manual mode
2 /usr/bin/php7.4 74 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Enter the number and you have successfully changed the version of PHP.
Laravel eloquent provides multiple ways to build the query one the of the feature of laravel eloquent is creating dynamic query based on condition or complicated queries.In this article i will show you to build where condition in laravel with example. I will show you multiple example to create where…
In this article i will show you to filter data using the relational model in laravel. Using the laravel relationship between the models we can easily fetch relative data but sometimes we want to fetch the data by filtering the child model that affect the result of parent model. You…
If you’re a developer working with Bit bucket repositories, using SSH keys can make your workflow more secure and efficient. Instead of entering your username and password each time you interact with your repository, SSH keys provide a seamless and secure connection. In this guide, we’ll walk you through the…