This article is the first in a mini-series of quick reference guides for installing Apache, PHP, and MySQL in Ubuntu 16. These steps are possibly the minumum required for getting a development environment up and running, and can be used for testing your web development locally. This first article will cover the installation of the Apache HTTP Server.
There are many excellent guides availble which provide much more explanation. For a more detailed walkthrough of the process the below examples may be useful:
- DigitalOcean Community: How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
- Ubuntu 16.04 LTS LAMP server tutorial with Apache 2.4, PHP 7 and MySQL
My environment for these steps is Ubuntu 16 running on VirtualBox in Windows 10 x64.
Install Apache HTTP Server in Ubuntu
First we need to check if Apache httpd is already installed. There are a few different ways to do this. Here I’ll use
apache2 -vto try check the Apache version. Check this StackOverflow question for another option using a package manager.
Open a new terminal and type
If Apache is not installed you will see an error message like this:
"The program 'apache2' is currently not installed. You can install it by typing: sudo apt install apache2-bin"
Now we can install the Apache web server
sudo apt-get update sudo apt-get install apache2
A small sidenote: you may have noticed the error message we got from
apache2 -vindicated we should install
apache2-bin, but instead we installed
-bin). Why is that?
I wondered the same thing and found this SuperUser question: Difference between apache2 and apache2-bin. Basically,
apache2-binis just part of the overall Apache pacakge, so by installing
apache2we not only get
apache2-bin, but a heap of other neccessary items.
Open a web browser and navigate to
127.0.0.1) and you should see the Apache2 Ubuntu Default Page
By default the Apache service will run automatically when Ubuntu starts.
Apache was installed to the
/etc/apache2directory. We can
cdinto this folder and list the files:
cd /etc/apache2 ls -l
This is also where Apache’s main configuration file
apache2.confcan be found. Its full path is:
We can also check Apache’s document root which by default is set as
cd /var/www/html ls -l
Files placed in this location are accessible via the browser.
This next step is not neccesary, but can be useful for final verification of the install. Create a new file within
Paste the below html into the file and save:
<html> <head><title>Apache test</title></head> <body> <p1>Apache 2 web server - it works</p1> </body> </html>
In your browser navigate to
127.0.0.1/test.html) and you should see the words
Apache 2 web server - it works.
That’s it for this quick article. In the next part we’ll install MySQL in Ubuntu.