Introduction to the Worlds Quickest Web Server Tutorial
This tutorial is a very short and a “need to know” step by step on setting up a web server on Ubuntu 16.04. The tutorial will not cover advanced features, it is meant purely as the Worlds Quickest Web Server Tutorial to getting a web server up and running. The end result will be a web server that delivers html pages, PHP pages and has the ability to run databases.
What it covers
- Ubuntu Setup
- Apache Web Server
- MySQL/MariaDB Database
- PHP – Scripting Language
This tutorial assumes you have done the needed setup on a server; hostnames, security and Firewalls etc. If you need help with that, consult another tutorial on this website or another website.
Lets get started!
First we need to make sure the system is up to date. Run the following command in the terminal.
sudo apt-get update
Install Apache Web Server
sudo apt-get install apache2
You will likely be asked about a password for the sudo user, this you would have setup during server setup of Ubuntu.
Test the installation by going to the following address on a computer in your local network or the computer itself.
Firstly you need to install MySQL Server, the following command will do just that.
sudo apt-get install mysql-server
After the install, you will need to run the following command to doing the initial setup. Following through the install wizard and each page will guide you through the options.
PHP is required to interface between websites and the MySQL databases you will have. There are other languages too, but PHP is a widely used language for dynamic websites. The following command will install the PHP libraries and various support addons for MySQL and Apache.
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
Since we have installed PHP, it is likely because you wish to serve PHP files as the primary web files to users. To ensure .php files load before .html files you need to alter the load order.
Typing in the following command to open the
dir.conf file in nano (a Linux terminal text editor will do just this.
sudo nano /etc/apache2/mods-enabled/dir.conf
It will look like this:
<IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
You can see that directly after the DirectoryIndex part of the file is listed index.html. We want index.php to be first so we need to move it accordingly. It should look like the following:
<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
Save and close the file by hitting Ctrl-X. You will have to save by typing Y and then hit Enter to confirm the file save location.
Restarting the Services and Testing the Installation
You will need to restart Apache to make the changes take effect. Copy and paste the following command:
sudo systemctl restart apache2
Its a good idea to test the PHP works by making a small test file that prints out your PHP installation settings.
To do this run the following sets of commands.
sudo nano /var/www/html/info.php
In the blank file that opens write in the following text.
Save and close the file as before and then go to the following address in your favorite browser.
Now you can see the above page, you will want to remove it from the server as it contains information that other people could use to hack your website/server.
Other Tutorials for Servers/Ubuntu
Now you have your server up and running, perhaps you want to do some other tasks with it. Follow below some other tutorials and guides to help you get what you want out of your server.