Linux Web Server Set Up

The Apache HTTP server is the most widely-used web server in the world. It provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.

Prerequisites

Before you begin this guide, you should have a regular, non-root user withsudoprivileges configured on your server. Additionally, you will need to configure a basic firewall to block non-essential ports.

When you have an account available, log in as your non-root user to begin.

Install Apache

Apache is available within Ubuntu's default software repositories, so we will install it using conventional package management tools. We will begin by updating the local package index to reflect the latest upstream changes.

~$ sudo apt-get update
~$ apt-get install apache2

After confirming the installation,apt-getwill install Apache and all required dependencies.

Check your Web Server

At the end of the installation process, Ubuntu 16.04 starts Apache. The web server should already be up and running.

We can check with thesystemdinit system to make sure the service is running by typing:

~$ sudo systemctl status apache2

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
           └─apache2-systemd.conf
   Active: active (running) since Fri 2017-05-19 18:30:10 UTC; 1h 5min 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

May 19 18:30:09 ubuntu-512mb-nyc3-01 systemd[1]: Stopped LSB: Apache2 web server.
May 19 18:30:09 ubuntu-512mb-nyc3-01 systemd[1]: Starting LSB: Apache2 web server...
May 19 18:30:09 ubuntu-512mb-nyc3-01 apache2[4359]:  * Starting Apache httpd web server apache2
May 19 18:30:09 ubuntu-512mb-nyc3-01 apache2[4359]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
May 19 18:30:10 ubuntu-512mb-nyc3-01 apache2[4359]:  *
May 19 18:30:10 ubuntu-512mb-nyc3-01 systemd[1]: Started LSB: Apache2 web server.

As you can see above, the service appears to have started successfully. However, the best way to test this is to actually request a page from Apache.

You can access the default Apache landing page to confirm that the software is running properly. You can access this through your server's domain name or IP address.

When you have your server's IP address or domain, enter it into your browser's address bar:

http://server_domain_or_IP

This page is simply included to show that Apache is working correctly. It also includes some basic information about important Apache files and directory locations

Manage the Apache Process

Now that you have your web server up and running, we can go over some basic management commands.

To stop your web server, you can type:

~$ sudo systemctl stop apache2

To start the web server when it is stopped, type:

~$ sudo systemctl start apache2

To stop and then start the service again, type:

~$ sudo systemctl restart apache2

If you are simply making configuration changes, Apache can often reload without dropping connections. To do this, you can use this command:

~$ sudo systemctl reload apache2

Last updated

Was this helpful?