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.
Versions | Released Dates | End of life |
8.2 | 06 Dec 2022 | 08 Dec 2025 |
8.1 | 23 Nov 2021 | 25 Nov 2024 |
8.0 | 24 Nov 2020 | 26 Nov 2023 |
7.4 | 26 Nov 2019 | 28 Nov 2022 |
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.
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!!!
Good post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis. Its always useful to read content from other authors and practice something from their websites.
A motivating discussion is definitely worth comment. There is no doubt that you need to write more on this subject matter, it may not be a taboo matter but generally folks don’t discuss such subjects. To the next! Kind regards!!
Awesome! Its genuinely remarkable post, I have got much clear idea regarding from this post.
I like the efforts you have put in this, regards for all the great content.
I truly appreciate your technique of writing a blog. I added it to my bookmark site list.
This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!