This article is the first in a mini-series of quick reference guides for installing Apache, PHP, and MySQL in Ubuntu 18. These steps are possibly the minumum required for getting a web development environment up and running, and can be used for local testing of your web development. This first article will cover the installation of the Apache HTTP Server.
My environment for these steps is Ubuntu 18.04 LTS running on VirtualBox in Windows 10 x64.
Update Ubuntu package list
First, make sure your Ubuntu package list is up to date.
sudo apt update
Install Apache HTTP Server in Ubuntu 18
Next, ensure that Apache httpd is not already installed. There are a few different ways to do this. The first is to try print the
Open a new terminal and type
If Apache is not installed you will see an error message like this:
Command 'apache2' not found, but can be installed with: sudo apt install apache2-bin
Another method is to use
dpkgpacket management software (credit to this StackOverflow answer for providing this option.
dpkg --get-selections | grep apache
This command will not return any output if Apache is not installed.
Now we can install the Apache web server
sudo apt install apache2
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 previously 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 all the other neccessary items.
At the prompt hit
Enterto download the Apache packages and install them.
When the installation is complete, the Apache service will be automatically started. Apache will also run automatically everytime Ubuntu starts.
You can check the Apache service status using
sudo systemctl status apache2
Ctrl + Cto return to the command prompt.
Open a web browser and navigate to
127.0.0.1) and you should see the Apache2 Ubuntu Default Page
Apache configuration file apache2.conf
Apache configuration is specified in the file
apache2.conf which is read by Apache during startup. Changes to this file require the Apache service to be restarted.
By default, Apache is installed to the
/etc/apache2directory. We can
cdinto this folder and list the files:
cd /etc/apache2 ls -l
This is where Apache’s main configuration file
apache2.confcan be found.
The full path to this file is:
Apache document root
The document root is where Apache stores documents and by default is located at
/var/www/html. In general, files placed in this location are accessible via the browser.
Change into the document root
/var/www/htmland list the files:
cd /var/www/html ls -l
By default, there will be a single file named
index.html. This is the Apache2 Ubuntu Default Page we saw in the browser earlier.
The basic install of Apache is now complete. You can verify it by trying to print the version details again:
This command will show the server and build versions. My installed version is
This next step is not neccesary, but can be educational if you are new to Apache. Create a new file within
sudo gedit test.html
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.