How To Install PHP on Linux
PHP is one of the popular opensource server side scripting language mostly used in web development. PHP originally stood for "Personal Home Page", but it now stands for the recursive backronym PHP: Hypertext Preprocessor.
Today I'm going to show you how to install PHP on Linux
First things first, You need to install apache web server first.. Because often we use PHP incombination with Apache.. See, How To Install Apache On Different Linux Distros...
After installing the Apache web server successfully... start to install PHP..
Installing PHP On Ubuntu
Following command will install PHP and libapache2-mod-php5, php5-mcrypt modules.. which are useful for web developers..
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-mysql
Or, On Newer systems (Ubuntu 16.04 and later versions..)
sudo apt install php libapache2-mod-php php-mcrypt php-mysql
PHP has a variety of useful libraries and modules that you can add onto your virtual server. You can see the libraries that are available.
Run, apt-cache search php- (For Ubuntu 16.04) or apt-cache search php5- (For Ubuntu 14.04) to see the list of possible/available modules.
If you would like to install one of the available modules.. Run command like one shown below..
sudo apt-get install name_of_the_module
or
sudo apt install name_of_the_module
Installing PHP On CentOS, RHEL and Fedora Linux
For Fedora 22 and later versions..
sudo dnf -y install php php-mysql
For CentOS, RHEL, Fedora 21 and earlier..
sudo yum -y install php php-mysql
To list available modules for PHP, Run the following command..
dnf search php-
Or (For CentOS, RHEL and older Fedora systems..)
yum search php-
If you would like to install one of the available modules.. Run command like one shown below..
sudo dnf name_of_the_module
or
sudo yum name_of_the_module
Installing PHP On Arch Linux
First, make sure that your Arch Linux System is up-to-date by running following command
sudo pacman -Syu
Now Install PHP with following command..
sudo pacman -S php
Installing PHP On SUSE Linux
Run following command to install PHP on SUSE Linux..
sudo zypper install php5 apache2-mod_php5
Installing PHP On Gentoo Linux
Run the following command to ensure that your Gentoo Linux System is up-to-date..
sudo emerge --sync && sudo emerge --update world
Now run the following command to install PHP on Gentoo..
sudo emerge -pv php
That's it.. ☻