PHP, which stands for Hypertext Preprocessor, is a server-side programming language that is widely used for web development. It was created in 1995 by Rasmus Lerdorf and has since evolved to become one of the most popular programming languages for building dynamic web applications. In this blog post, we will go over the steps to install PHP on Linux servers.

One of the main advantages of using PHP is that it is easy to learn and use. It is an open-source language, which means that it is free to use and can be modified by anyone. Additionally, PHP is compatible with a wide range of operating systems, including Windows, Linux, and Mac, making it a versatile option for web developers.

PHP is particularly well-suited for building dynamic websites and web applications. It allows developers to easily create and manipulate databases, process forms, and handle sessions. PHP also integrates seamlessly with HTML, CSS, and JavaScript, making it a great choice for building the front-end of web applications.

PHP versions, Release Dates and EOL:

Here I am listing PHP versions, its released date and End Of Life so you will get idea to install most updated PHP version for your Linux server.

VersionsReleased DatesEnd of life
8.206 Dec 202208 Dec 2025
8.123 Nov 202125 Nov 2024
8.024 Nov 202026 Nov 2023
7.426 Nov 201928 Nov 2022
PHP versions, Release Dates and EOL

Steps to install latest PHP on Linux server

Before we begin, it’s important to note that different Linux distributions have different package management systems, so we are covering commonly used Linux distributions.

If you want to install latest MySQL for your PHP application then read this article.

Latest php installation on linux server
Latest PHP installation on Linux server

Prerequisites:

  • sudo privileges.
  • Stable internet connection.

First check server OS version then start installation as per OS version:

# egrep '^(VERSION|NAME)=' /etc/os-release

PHP installation on Ubuntu or Debian:

Simple Steps to install latest PHP on Ubuntu or Debian server.

Now install the utility and add the following PPA.

# apt install --no-install-recommends software-properties-common apt-transport-https ca-certificates gnupg2 lsb-release -y

For Ubuntu
# add-apt-repository ppa:ondrej/php -y

For Debian
# wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
# echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

Refresh the apt cache

# apt update

And finally install PHP

# apt install php8.2 -y

PHP installation on CentOS and related distros:

Simple steps to install Latest PHP on CentOS, Red Hat Enterprise Linux, Oracle Linux or Rocky Linux.

First we need to add PHP 8.2 repository:

For RHEL / CentOS / Oracle version 7
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
# yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

For RHEL / CentOS / Oracle / Rocky Linux version 8
# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
# dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

For RHEL / CentOS / Oracle / Rocky Linux version 9
# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y
# dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

Then enable remi repo for PHP installation:

# yum-config-manager --enable remi-php82

 Now install PHP 8.2:

RHEL / CentOS / Oracle Linux version 7
# yum install php -y

RHEL / CentOS / Oracle Linux / Rocky Linux version 8 and 9
# dnf install php -y

Verify installed version of PHP:

# php -v

Installing PHP Modules:

Besides PHP itself, We need to install some additional PHP modules:

Note: We are installing most common modules here but you can install PHP modules as per your need.

For Ubuntu / Debian
# apt install php8.2-{bcmath,fpm,xml,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi} -y

For RHEL / CentOS / Oracle Linux version 7
# yum install php-{bcmath,fpm,xml,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi} -y

For RHEL / CentOS / Oracle Linux / Rocky Linux 8 and 9
# dnf install php-{bcmath,fpm,xml,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi} -y

Installed modules can be listed with:

# php -m

Uninstall PHP

To completely remove PHP from a system, you must remove the PHP applications, the configuration files, and any directories containing data and logs.

Warning: This process will completely remove PHP, its configuration, and all modules. This process is not reversible, so ensure that all of your configuration is backed up before proceeding.

Remove any PHP packages that previously installed.

For RHEL / CentOS / Oracle Linux / Rocky Linux
# yum erase $(rpm -qa | grep php)
OR
# dnf erase $(rpm -qa | grep php)

For Ubuntu / Debian
# apt autoremove --purge php8.2*

Conclusion

Congratulations!!! We’ve installed Latest PHP on Linux system like CentOS, RHEL, Ubuntu and Debian. We hope this 2 minutes stuff helped you and thank you for visiting our website.
Cheers!!!