Install Apache on Ubuntu 16.04 [Simple Steps] – Beginner Guide

Apache is one of the most powerful Web Server till the date. Many people are using apache in combine with other web servers.

Especially Most of the wordpress sites are powered by Apache. In previous article, we have seen how to install Apache along with PHP and MySQL.

Here, in this article, we will see how to install Apache on Ubuntu. Especially you will learn the basics of Apache web server.


  • If you have got a new ubuntu server, then you have to configure the server according to this server setup guide.

1. Install Apache on Ubuntu

Ubuntu has it’s default repositories from where you can install the required software. All the installation can be done just by using simple commands.

We will use the apt-get utility to update the package index on the ubuntu server.

$ sudo apt-get update

After that, execute the below command to install apache.

$ sudo apt-get install apache2

It will show all the package details and disk space requirements.

Just, Press Y and hit enter to finish the installation process.

2. Firewall Setup For Apache

When you install the application on Ubuntu, Apache itself registered as service so that it can work.

But, Apache web server cannot be accessed from outside the server. That is because we have configured the firewall to block traffic from outside.

Apache will have few profiles on UFW. We will work on those profiles to allow outside access to the web server.

To see the application list in UFW, use the below command.

$ sudo ufw app list

You will get the following output.

Available applications:
  Apache Full
  Apache Secure

In the above output, you can see three profiles for Apache.

They are

Apache: This is the http profile opens the port 80.

Apache Full: It opens both port 80 and port 443. i.e unencrypted and encrypted traffic.

Apache Secure: The name itself says it’s secure. As mentioned, it only opens port 443.

Now, let us allow Apache Full to allow traffic at both port 80 and 443.

$ sudo ufw allow 'Apache Full'

Then, check the firewall status.

$ sudo ufw status

The output will look like below.

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
Apache Full                ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Apache Full (v6)           ALLOW       Anywhere (v6)

Now, traffic is allowed at two of these ports from outside the server.

Then, check the web server using the below command.

$ sudo systemctl status apache2

You will see the following output

● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: active (running) since Tue 2018-07-21 15:20:07 UTC; 1h 9min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 4336 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 4359 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
    Tasks: 55
   Memory: 2.3M
      CPU: 4.094s
   CGroup: /system.slice/apache2.service
           ├─4374 /usr/sbin/apache2 -k start
           ├─4377 /usr/sbin/apache2 -k start
           └─4378 /usr/sbin/apache2 -k start

Here, the status “active” is indicating that Apache web server is up and running.

You can check that, in another way also. If you have a domain name pointing to the server, or if you know the public IP address of your server, then visit that in your browser.


You should see the Apache web page on the browser.

It indicates that a web server is up and running.

Now, let us see how to manage the web server.

Apache Server Management

To stop the Apache server, use the below command.

$ sudo systemctl stop apache2

To start the Apache again, use the below command.

$ sudo systemctl start apache2

To restart the service, execute the below command.

$ sudo systemctl restart apache2

If you have made any changes inside the Apache, then use the below command, reload the Apache. It will not abort an existing connection.

$ sudo systemctl reload apache2

When you restart the server, Apache will automatically start at the system boot. To stop that, use the disable command.

$ sudo systemctl disable apache2


If you want to start the apache at the system boot, use the below command.

$ sudo systemctl enable apache2

Now, let us look at the Apache main configuration files and directories.

When you work on the Apache for the first time, you should know the basics.

/var/www/html : Apache web content will be stored on this location. By default, it will have the Apache web page. You can remove that and your web content to serve. 

/etc/apache2This is the apache configuration directory. All the configuration files will be stored on this location.

/etc/apache2/apache2.conf : This is the main configuration file. When you make changes, it will reflect globally. Many of the other configuration files can be controlled by this file.

/etc/apache2/ports.conf : This configuration file contains the information about ports. Apache by default listens on port 80. This is the unencrypted port. Apache also listens on port 443. This can be used when using SSL for the encrypted connection.

/etc/apache2/sites-available/ : This directory contains the virtual hosts. If you want apache to serve more than one website, you can make that changes here.

But, the sites here will not be served unless they are linked to the sites-enabled directory.

/etc/apache2/sites-enabled/ : Here, this directory consists the virtual hosts found in the sites-available directory. This is created by linking to the configuration files in the sites-available directory. Both the sites-enabled and sites-available directory can be enabled using a2ensite.

/etc/apache2/mods-available/, /etc/apache2/mods-enabled/: 

Both of these directories consist of modules and configuration files for those modules. These modules can be enabled by a2nemod and a2dismod.

/etc/apache2/conf-available/, /etc/apache2/conf-enabled/: These both files are similar to the above mentioned one. But. they consist of configuration fragments.

The command to enable and disable the conf-available directory can be enabled and disabled with a2enconf and a2disconf.

/var/log/apache2/access.log : This log file records every access request made to the web server. It can be enabled and disabled.

/var/log/apache2/error.log: This log file stores all the error logs in the web server.


If you have configured apache, then next step would be installing PHP and MySQL on the server.
After that, your Apache server will be ready to serve the web.


Share on facebook
Share on twitter
Share on linkedin

Leave a Comment