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

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.

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

Requirements:

  • 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.

After that, execute the below command to install apache.

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.

You will get the following output.

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.

Then, check the firewall status.

The output will look like below.

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

Then, check the web server using below command.

You will see the following output

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 domain name pointing to the server, or if you know 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 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.

To start the Apache again, use the below command.

To restart the service, execute the below command.

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

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

But:

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

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 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 files contains the information about ports. Apache by default listens on port 80. This is 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 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 sites-available directory. Both 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 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.

Conclusion

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.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *