Hostwinds Tutorials

Search results for:


Table of Contents


Installation Instructions

How to Install PHP in Ubuntu 18.04

Tags: Ubuntu 

Installation Instructions

PHP is a prevalent open-source scripting language that is ideal for web-based development. It is executed on the server-side and is used in a variety of websites/web-based applications. PHP is also an integral part of a LAMP stack, a widely used method to host websites, as it can do things such as process code to display content dynamically and connect to a MySQL database. Although this package is not included in Ubuntu by default, it is quite simple to install with a few commands and a little bit of time. The focus of this article is to help you get PHP installed and operational in Ubuntu 18.04.

Installation Instructions

Before getting started, you'll need to log in to your server using SSH. If you're not familiar with how to do this, please take a moment and read through the following: Connecting to Your Server via SSH. Once you have connected to your server via SSH, please proceed with the installation. Like most software installed in Ubuntu, you'll be using the apt-get command to install the necessary PHP packages and some additional helpful packages as the root or sudo user.

apt-get install php libapache2-mod-php

If you're using a Sudo user, please ensure that you add sudo before the command.

Once you confirm the installation of these packages and the process completes, PHP should be installed. However, we're not done just yet. Next, you need to ensure that the Apache webserver will correctly serve your server's PHP files. You can do this by editing the following conf file with a text editor of your choice. To learn more about which text editor is right for you, please refer to our article: How to Edit Files from a Linux Shell. We will be using nano to edit this conf file as the root or sudo user for this article.

nano /etc/apache2/mods-enabled/dir.conf

If you're using a Sudo user, please ensure that you add sudo before the command

It should look similar to the following:

<IfModule mod_dir.c>
   DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm  

You'll need to move the index.php file up in this list, preferably to the very beginning of the list. Once you're satisfied with the edits, you have made save and close the file. To finalize the installation, you'll need to restart Apache by issuing the following command as the root or sudo user.

service apache2 restart

If you're using a Sudo user, please ensure that you add sudo before the command.

If everything is completed successfully with no errors, PHP should now be installed and ready to go! It is possible (and optional) to add some additional modules to augment PHP's functionality. Suppose this sounds like something you need to do. Please feel free to check out our article covering How to install PHP modules (Ubuntu 14.04). There are also additional PHP extensions that can be installed via PECL. More details on PECL and the installation of PECL extensions can be found here.

Written by Michael Brower  /  June 22, 2017