General Guides

Search Knowledge Base by Keyword

How To Install PHP In Ubuntu 18.04

You are here:
Share:

PHP is a very popular 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, with a few commands and a little bit of time it is quite simple to install. 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 login 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 that can be 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.

 

 

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 web server will serve up your servers PHP files correctly. 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. For the purpose of this article we will be using nano to edit this conf file as the root or sudo user.

 

 

If you’re using a sudo user please ensure that you add sudo before the command

 

It should look similar to the following:

 

 

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.

 

 

If you’re using a sudo user please ensure that you add sudo before the command

 

If everything 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. If this sounds like something you need to do please feel free to checkout our article that covers 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.

 

Related Articles


Share: