If you want to host a Linux server to serve any web application the online users then PHP is the most important component. Installing PHP is necessary on the server to handle the server-side tasks written in PHP. Installing PHP on Linux is different for each version of the Linux. It is very easy to install PHP on different Linux operating system versions which are as follows.
Installing PHP on Ubuntu
Ubuntu is very easy to use Linux release if you want to install the latest version of PHP on Ubuntu. There are two methods that you can use to install the PHP on Ubuntu. The first one is pre-installation and the second one is post-installation.
The Pre-Installation is the best way to install PHP, as there is no need to use the terminal for getting and installing PHP packages. This method makes it possible to set up PHP in the start. All you need is to get the latest Ubuntu Server and make a bootable USB drive and boot the system. Go through the installation process of Ubuntu and from the Package selection area choose to install the latest version of MySQL, Apache and PHP from the list of components. Picking up LAMP option with install all of them.
The post-installation of PHP in Ubuntu is necessary for the people who have finished installing the Ubuntu Server and you have not installed LAMP on the Server. All you need is to gain access to the root.
Login to the Server and get root access by:
Now install LAMP server:
apt install install lamp-server^
The apt package manager will run. After the installation is complete, PHP will be running.
Installing PHP on Debian
When using a Debian Linux server, you need to install the PHP package manually by specifying the PHP.
Get the root access from the su – command and use apt-get command to install the PHP package.
apt-get install aptitude install php php-mysql
It will access the PHP package and to run the PHP you need to go through the official documentation.
Installing PHP on Fedora
Fedora is the best Linux release providing the workstation features that best runs the PHP. Get access to the root by su command. Use the DNF package manager to get PHP packages.
sudo dnf -y install php php-cli php-php-gettext php-mbstring php-mcrypt php-mysqlnd php-pear php-curl php-gd php-xml php-bcmath php-zip
Installing PHP on OpenSUSE
You can easily install PHP on OpenSUSE. Access the root shell by su command. From the root, use Zypper command and get PHP packages.
zypper in php7 php7-mysql apache2-mod_php7
OpenSUSE tracks both PHP5 and PHP7 versions. To install PHP5 you need to run the command:
zypper in php5 php5-mysql apache2-mod_php5
Installing PHP on CentOS
For installing the latest version of PHP on CentOS, you need to get the root access using the su command. From the terminal shell, Yum command is there to get the PHP MySQL packages for you.
yum install php php-mysql