Install a Web Server

Having a server at home can have many uses. What you will find very quickly though, is that many of the applications you install, or want to install, on it, will need to be accessed via a web browser, either to set up and configure, if not to use them altogether. This means that your server will need to install and run a web server application, so you can serve up these web based interfaces. Having a running web server also allows you to set up web pages for yourself to save links to your applications or even control certain aspects of the server, something we will cover in a later post. This can be something that gets quite fun and interesting once you begin to get into it.

A web server consists of a number of elements, collectively known as a stack, or a LAMP stack. LAMP stands for Linux, Apache, MySQL and PHP. Linux is obviously the platform we are working on and running the server from. Apache is the web server application itself, MySQL is the database server, needed for many applications, though not all, that we will be running, and PHP is the web based scripting language which gives web applications (web apps) their power, features and configurability. PHP is what makes web applications possible, and without it Apache can only show static HTML pages. The LAMP stack gives you a very powerful web server to work with.

To install the server, you can either install Apache, MySQL and PHP individually, or all together. As it has been conveniently packaged up with all needed dependencies already in the Ubuntu software repositories, we are going to go with the LAMP package. Firstly, update the software repositories on your server, that is the list of available software your server knows about

Then install the LAMP server. It is important to add the caret (^) at the end of this command

The server will look up what additional software it needs to download, and notify you of how much disk space it will use up for the install. You can bypass this prompt by adding –y to the end of the install command above, to agree to the installation.


During the installation of the MySQL database, you are presented with a screen asking for a password for the root, or administrative, account. The root user has overall power over the database, so while it is not mandatory, you should indeed set a password. You will get another screen asking you to re-enter the password to ensure you have entered it correctly.


The process will take a few minutes to download and install everything. Once it is done, the command line will return you to a command prompt. If there were any errors during the install (less likely when using the packaged lamp-server), they will be displayed on the screen above the command prompt. To test it, open a web browser on your laptop and enter the IP address of your server. You should get a page showing the Apache Ubuntu default web page, indicating that the web server installed successfully.


Test PHP

To test the PHP install, you need to create a PHP test page. The root directory for your web server, the location which Apache takes your web pages from, is /var/www/html. SSH onto your server and change directory to this, then list the files in this directory

Rename (move) the current homepage to something different, and then, using the nano text editor, create a .php homepage

Enter the following three lines of PHP code

Press Ctrl + O to save, and then Ctrl + X to exit the text editor

Go back to your web browser and refresh the page. You should now see a page displaying detailed PHP information. This page lists intimate details of the version of PHP and its modules which is enabled on your system. Once you are satisfied that PHP is working fine, you should remove it once as it gives someone inside information about your system, which could potentially be used to exploit and take over your server.