Start and configure Apache in Ubuntu 19.10

Where is the physical location of apache2 in Ubuntu 19.10? I tried using to install Apache from the terminal. The response was that Apache has been installed already, but I can't find it in order to start it. I also don't know how to configure Apache now that I have installed it.

0

1 Answer

Before installing new software, it's a good idea to refresh your local software package database to make sure you are accessing the latest versions. This helps cut down on the time it takes to update after installation, and it also helps prevent zero-day exploits against outdated software.

Open the terminal and type:

sudo apt update
  1. Install Apache.

    To install the Apache package on Ubuntu, use the command:

    sudo apt install apache2

    When the system prompts for confirmation do so, and allow the system to complete the installation.

    enter image description here

  2. Verify the Apache installation.

    To verify Apache was installed correctly, open a web browser and type in the address bar:

    The web browser should open a page labeled Apache2 Ubuntu Default Page as shown in the below screenshot:

    enter image description here

    Note: Replace local.server.ip with the IP address of your server. If you are unsure what's the IP address, run the following terminal command:

    hostname -I | awk '{print $1}'

    The output will return your server's IP address.

  3. Configure your firewall.

    Although the Apache installation process is complete, there is one more additional step. Configure the default UFW firewall to allow traffic on port 80.

    Start by displaying available app profiles on UFW:

    sudo ufw show app list

    The terminal should respond by listing all available application profiles, as seen in the example below.

    Available applications: Apache Apache Full Apache Secure OpenSSH

    Use the following command to allow normal web traffic on port 80:

    sudo ufw allow 'Apache'

    enter image description here

    Verify the changes by checking UFW status:

    sudo ufw status

    enter image description here

    If you have other applications or services to allow, make sure you configure your firewall to allow traffic. For example, running the sudo ufw allow 'OpenSSH' command will enable secure, encrypted logins over the network.

    Note: At this point, your Apache service on Ubuntu is up and running. If you are familiar with Apache, a next common step is setting up Apache virtual hosts.


Apache Configuration

Apache Service Controls

When managing a web server, it's helpful to have some level of control over the service. You'll probably find yourself reloading or restarting Apache quite frequently, as you make configuration changes and test them. However, it's also helpful to be able to stop (and start) the Apache service as needed.

This operation uses the systemctl command, with a series of switches:

Stop Apache:

sudo systemctl stop apache2.service

Start Apache:

sudo systemctl start apache2.service

Restart Apache:

sudo systemctl restart apache2.service

Reload Apache:

sudo systemctl reload apache2.service

Apache Configuration Files, Directories and Modules

Now that you have Apache installed, there are a couple of other things you will need to be aware of to make content available online. Most of all, this means dealing with directories and configuration files.

Directories

After installing, Apache by default creates a document root directory at /var/www/html.

Any files that you place into this directory are available to Apache to distribute over the network. Which means, this is the place where you copy webpage files you want to publish. This is also where you would want to install content management systems, such as WordPress.

Configuration Files

As mentioned above, website content is stored in the /var/www/html/ directory. You can create subdirectories within this location for each different website hosted on your server.

Apache creates log files for any errors it generates in the /var/log/apache2/error.log file.

It also creates access logs for its interactions with clients in the /var/log/apache2/access.log file.

Like many Linux-based applications, Apache functions through the use of configuration files. They are all located in the /etc/apache2/ directory.

Here's a list of other essential directories:

  • /etc/apache2/apache2.conf – This is the main Apache configuration file and controls everything Apache does on your system. Changes here affect all the websites hosted on this machine.
  • /etc/apache2/ports.conf – The port configuration file. You can customize the ports Apache monitors using this file. By default, Port 80 is configured for http traffic.
  • /etc/apache2/sites-available – Storage for Apache virtual host files. A virtual host is a record of one of the websites hosted on the server.
  • /etc/apache2/sites-enabled – This directory holds websites that are ready to serve clients. The a2ensite command is used on a virtual host file in the sites-available directory to add sites to this location.

There are many directories and configuration files, which are detailed in the Apache Ubuntu documentation. These can be used to add modules to enhance Apache's functionality or to store additional configuration information.

Modules

If you intend to work with software modules – applications that expand or enhance the functionality of Apache – you can enable them by using:

sudo a2enmod name_of_module

To disable the module:

sudo a2dismod name_of_module

Source: revised from How to Install Apache on Ubuntu 18.04

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like