1. Home
  2. Linux

How to install PHP on Linux

PHP is one of the core components of the web. If you plan to host a Linux server that delivers web applications, understanding how to install it is a must. Installing the core PHP run-time files on Linux differs, depending on what you’re using, and it can get confusing. For this reason, we’ve decided to show you exactly how you can quickly install PHP on Linux.

Ubuntu instructions

Ubuntu server is the perfect distribution for those on Linux who haven’t got a clue about how to go about installing PHP or any other web software for that matter.

If you’re in need of the latest PHP and you’re using Ubuntu, there are two ways to go about this. The two methods are pre-installation and post-installation.


Pre-installation is the best method for getting PHP working, as you don’t need to use the terminal or any of the elaborate packaging tools that Ubuntu has. Instead, you can just set it up during your initial installation process.

To do it, download the latest version of Ubuntu Server and flash it to a USB drive and boot it up. Then, go through the setup process and install the OS to the machine’s hard drive.

During the installation, you’ll soon get to the package selection area of Ubuntu Server. In this area, you’ll see a huge list of software you can load up.

In the list, scroll through and select “LAMP.” Picking the “LAMP” option will give you the latest Apache web server, MySQL, and PHP.


The post-installation PHP setup for Ubuntu is reserved for those that have an existing Ubuntu Server instance but have chosen to skip the “LAMP” option for whatever reason.

Thankfully, Ubuntu Server being the user-friendly OS it is, getting the latest PHP is just about as easy after the fact as it is during the installation wizard.

To get PHP working, login to your server and gain root access with sudo -s. Then, do:

apt install install lamp-server^

Let the Apt package manager run its course. It will take quite a long time as LAMP is installing the latest MySQL, Apache web server, and PHP tools.

When the installer is done, your Ubuntu server will have PHP up and running!

Debian instructions

Are you using Debian Linux as a server and plan to host PHP applications on it? If so, you’ll need to know how to get the PHP packages up and running.

Installing PHP on Debian isn’t as user-friendly as Ubuntu Server, despite their similarities. There’s no meta-package available. Instead, you’ll need to specify every PHP package manually.

To get PHP working on Debian Linux, gain root access with the su command. Then, use the Apt-get installation command.

su -
apt-get install aptitude install php php-mysql

Once the Apt-get command is done, you’ll have access to PHP. For more information about PHP and running a LAMP stack on Debian, refer to the official documentation here.

Fedora instructions

Though Fedora Linux is mainly known for its workstation component, the developers also offer up an excellent, free server OS which includes dozens of tools, such as the latest PHP.

To get the latest PHP packages up and running on Fedora Linux, you’ll need to gain a root shell. Gaining a root shell on Fedora is done with the su command.

su -

Now that you’ve got access to root use the DNF package manager to get the PHP packages installed.

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

OpenSUSE instructions

OpenSUSE, like many other Linux operating systems that have a server offering distribute the latest PHP packages in their software repositories. If you’re on SUSE and using it as a server, spinning up PHP is easy. Here’s how to do it.

First, gain a root shell using the su command.

su –

Now that the shell has root access, you’ll be able to use the Zypper command and pull down several of the PHP packages.

zypper in php7 php7-mysql apache2-mod_php7

Are you in need of PHP5, rather than PHP 7? Good news! OpenSUSE keeps track of both versions and makes them available in the software sources. To install it, do:

zypper in php5 php5-mysql apache2-mod_php5

CentOS instructions

CentOS is a popular Linux server choice due to its reliability. For this reason, many people go with it when hosting web/PHP applications.

If you’re in need of the latest PHP packages on CentOS and are unsure about how to do it, we can help! To start, launch a terminal window and gain root access with the su command.

su –

Once you’ve got root access in the terminal shell, use the Yum command and load up PHP!

yum install php php-mysql

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.