0% found this document useful (0 votes)
33 views

Apache

The document provides instructions for installing the Apache web server on Ubuntu 18.04 in 4 steps: 1) Installing Apache, 2) Adjusting the firewall to allow port 80 traffic, 3) Checking that Apache is running properly by accessing the default page, and 4) Setting up virtual hosts to host multiple domains from one server. The tutorial assumes prior setup of an Ubuntu 18.04 server and non-root user account.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Apache

The document provides instructions for installing the Apache web server on Ubuntu 18.04 in 4 steps: 1) Installing Apache, 2) Adjusting the firewall to allow port 80 traffic, 3) Checking that Apache is running properly by accessing the default page, and 4) Setting up virtual hosts to host multiple domains from one server. The tutorial assumes prior setup of an Ubuntu 18.04 server and non-root user account.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

24/12/2020 How To Install the Apache Web Server on Ubuntu 18.

04 [Quickstart] | DigitalOcean

NEW Join the DigitalOcean + DEV Hackathon. Build something awesome to end 2020.

TUTORIAL

How To Install the Apache Web Server on Ubuntu 18.04


[Quickstart]
Ubuntu Apache Quickstart Ubuntu 18.04

By Kathleen Juell
Published on July 23, 2018  English 
 470.3k

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

In this guide, we’ll explain how to install an Apache web server on your Ubuntu 18.04 server.
For a more detailed version of this tutorial, please refer to How To Install the Apache Web
Server on Ubuntu 18.04.

Prerequisites
Before you begin this guide, you should have the following:

An Ubuntu 18.04 server and a regular, non-root user with sudo privileges. Additionally, you
will need to enable a basic firewall to block non-essential ports. You can learn how to
configure a regular user account and set up a firewall for your server by following our initial
server setup guide for Ubuntu 18.04.

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

SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 1/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

Step 1 — Installing Apache


Apache is available within Ubuntu’s default software repositories, so you can install it using
conventional package management tools.

Update your local package index:

$ sudo apt update

Install the apache2 package:

$ sudo apt install apache2

Step 2 — Adjusting the Firewall


Check the available ufw application profiles:

$ sudo ufw app list

Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH

Let’s enable the most restrictive profile that will still allow the traffic you’ve configured,
permitting traffic on port 80 (normal, unencrypted web traffic):

$ sudo ufw allow 'Apache'

Verify the change:

$ sudo ufw status SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 2/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

Output
Status: active

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

Step 3 — Checking your Web Server


Check with the systemd init system to make sure the service is running by typing:

$ sudo systemctl status apache2

Output
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Tue 2018-04-24 20:14:39 UTC; 9min ago
Main PID: 2583 (apache2)
Tasks: 55 (limit: 1153)
CGroup: /system.slice/apache2.service
├─2583 /usr/sbin/apache2 -k start
├─2585 /usr/sbin/apache2 -k start
└─2586 /usr/sbin/apache2 -k start

Access the default Apache landing page to confirm that the software is running properly
through your IP address:

http:// your_server_ip

You should see the default Ubuntu 18.04 Apache web page:
SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 3/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 4/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

Step 4 — Setting Up Virtual Hosts (Recommended)


When using the Apache web server, you can use virtual hosts (similar to server blocks in
Nginx) to encapsulate configuration details and host more than one domain from a single
server. We will set up a domain called your_domain, but you should replace this with your
own domain name. To learn more about setting up a domain name with DigitalOcean, see
our introduction to DigitalOcean DNS.

Create the directory for your_domain :

sudo mkdir /var/www/ your_domain

Assign ownership of the directory:

$ sudo chown -R $USER:$USER /var/www/ your_domain

The permissions of your web roots should be correct if you haven’t modified your unmask
value, but you can make sure by typing:

$ sudo chmod -R 755 /var/www/ your_domain

Create a sample index.html page using nano or your favorite editor:

$ nano /var/www/ your_domain /index.html

Inside, add the following sample HTML:

/var/www/your_domain/index.html

<html>
<head>
<title>Welcome to Your_domain !</title>
</head>
<body>
SCROLL TO TOP
<h1>Success! The your_domain virtual host is working!</h1>

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 5/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

</body>
</html>

Save and close the file when you are finished.

Make a new virtual host file at /etc/apache2/sites-available/ your_domain .conf :

$ sudo nano /etc/apache2/sites-available/ your_domain .conf

Paste in the following configuration block, updated for our new directory and domain name:

/etc/apache2/sites-available/your_domain.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias your_domain
DocumentRoot /var/www/ your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file when you are finished.

Enable the file with a2ensite :

$ sudo a2ensite your_domain .conf

Disable the default site defined in 000-default.conf :

$ sudo a2dissite 000-default.conf

Test for configuration errors:

$ sudo apache2ctl configtest

You should see the following output: SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 6/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

Output
Syntax OK

Restart Apache to implement your changes:

$ sudo systemctl restart apache2

Apache should now be serving your domain name. You can test this by navigating to
http:// your_domain , where you should see something like this:

Conclusion
Now that you have your web server installed, you have many options for the type of content
to serve and the technologies you want to use to create a richer experience.

If you’d like to build out a more complete application stack, check out this article on how to
configure a LAMP stack on Ubuntu 18.04.

Was this helpful? Yes No    


4

Report an issue

About the authors

Kathleen Juell
Developer @digitalocean/community SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 7/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

Still looking for an answer?

 Ask a question  Search for more help

RELATED

What is Apache?
Tutorial

How To Set Up Multi-Factor Authentication for SSH on Ubuntu 18.04


Tutorial

Comments

4 Comments

Leave a comment...

Sign In to Comment

SCROLL TO TOP
skylarkrieger July 1, 2019

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 8/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

I used this to set up a web server, walked away from my laptop. My laptop restarted when I was
0 away (blame Windows). Anyways, now I can no longer ssh into the web server I just set up. Any
troubleshoot?
Reply Report

anjanesh July 10, 2019

1 Somehow I am getting a 403 Forbidden.

sudo chown -R $USER:$USER /home/username/www


sudo chmod -R 755 /home/username/www

ls -la /home/username/www
total 12
drwxr-xr-x 2 username username 4096 Jul 10 10:32 .
drwxr-xr-x 5 username username 4096 Jul 10 10:48 ..
-rwxr-xr-x 1 username username 11 Jul 10 10:32 index.html

Reply Report

Axcurate August 28, 2020

0
You’re using users home directory and it’s forbidden for outsiders, your path should be
/var/www/your_domain
Reply Report

Axcurate August 28, 2020

0 That’s a nice article. For non tech people check out EasyApacheServer
(https://github.com/realpvn/EasyApacheServer) it basically sets up everything for you, just ssh
to the server and run this script
Reply Report

SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 9/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

This work is licensed under a Creative


Commons Attribution-NonCommercial-
ShareAlike 4.0 International License.

GET OUR BIWEEKLY NEWSLETTER

Sign up for Infrastructure as a


Newsletter.

HUB FOR GOOD

Working on improving health


and education, reducing
inequality, and spurring
economic growth? We'd like to
help.

SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 10/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean

BECOME A CONTRIBUTOR

You get paid; we donate to tech


nonprofits.

Featured on Community Kubernetes Course Learn Python 3 Machine Learning in Python


Getting started with Go Intro to Kubernetes

DigitalOcean Products Virtual Machines Managed Databases Managed Kubernetes Block Storage
Object Storage Marketplace VPC Load Balancers

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the


cloud and scale up as you grow – whether you’re
running one virtual machine or ten thousand.

Learn More

Company
SCROLL TO TOP
About
L d hi
https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 11/12
24/12/2020 How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart] | DigitalOcean
Leadership
© 2020 DigitalOcean, LLC. All rights reserved. Blog
Careers

Partners
Referral Program
Press
Legal
Security & Trust Center

Products Community Contact

Pricing Tutorials Get Support


Products Overview Q&A Trouble Signing In?
Droplets Tools and Integrations Sales
Kubernetes Tags Report Abuse
System Status
Managed Databases Product Ideas
Spaces Write for DigitalOcean
Marketplace Presentation Grants
Load Balancers Hatch Startup Program
Block Storage Shop Swag
API Documentation Research Program
Documentation Open Source
Release Notes Code of Conduct

SCROLL TO TOP

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart 12/12

You might also like