[Quick Start] How to install Apache web server on Ubuntu 18.04

Introduction

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

In this tutorial, we will explain how to install Apache web server on Ubuntu 18.04 server.

Preparation

Before starting this tutorial, you should have the following conditions:

If you have an account available, please log in as a non-root user to get started.

Step 1-Install Apache

Apache is available in Ubuntu's default software repository, so you can install it using traditional package management tools.

Update the local package index:

sudo apt update

Install the apache2 package:

sudo apt install apache2

Step 2-Adjust the firewall

Check available ufw application configuration

sudo ufw app list
Available applications:
 Apache
 Apache Full
 Apache Secure
 OpenSSH

Let's enable the most restrictive configuration file, which still allows you to configure traffic, allowing traffic on port 80 (normal, unencrypted network traffic):

sudo ufw allow 'Apache'

Verify changes:

sudo ufw status
Status: active
​
To                         Action      From
------------
OpenSSH                    ALLOW       Anywhere                  
Apache                     ALLOW       Anywhere                  
OpenSSH(v6)               ALLOW       Anywhere(v6)Apache(v6)                ALLOW       Anywhere(v6)

Step 3-Check the web server

Check the systemdinit system to make sure the service is running by typing the following command:

sudo systemctl status apache2
● 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-2420: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

Visit the default Apache login page to confirm whether the software is running normally with your IP address:

http://your_server_ip

You should see the default Ubuntu 18.04 Apache web page:

Step 4-Set up virtual host (recommended)

When using the Apache web server, you can use virtual hosts (similar to the server block in Nginx) to encapsulate configuration details and host multiple domains from a single server. We will set up a domain name called example.com, but you should replace it with your own domain name.

Create a directory for example.com to use the -p flag to create any necessary parent directories:

sudo mkdir -p /var/www/example.com/html

Assign ownership of the directory:

sudo chown -R $USER:$USER /var/www/example.com/html

If you have not modified your unmask value, the permissions of your web root directory should be correct, but you can make sure by typing the following:

sudo chmod -R 755/var/www/example.com

Use nano or your favorite editor to create a sample index.html page:

nano /var/www/example.com/html/index.html

Inside, add the following sample HTML:

< html><head><title>Welcome to Example.com!</title></head><body><h1>Success!  The example.com server block is working!</h1></body></html>

Save and close the file when you are done.

Create a new virtual host file in /etc/apache2/sites-available/example.com.conf:

sudo nano /etc/apache2/sites-available/example.com.conf

Paste it in the following configuration block to update for our new directory and domain name:

< VirtualHost *:80>
 ServerAdmin [email protected]
 ServerName example.com
 ServerAlias www.example.com
 DocumentRoot /var/www/example.com/html
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
< /VirtualHost>

Save and close the file when you are done.

Enable the a2ensite file:

sudo a2ensite example.com.conf

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

sudo a2dissite 000-default.conf

Test configuration error:

sudo apache2ctl configtest

You should see the following output:

Syntax OK

Restart Apache to implement the changes:

sudo systemctl restart apache2

Apache should now serve your domain name. You can test this by navigating to http://example.com, you should see something like this:

in conclusion

Now that you have installed a web server, you can choose the type of content you want to provide and the technology you want to use to create a richer experience.

To learn more about the installation of Apache web server related tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.


Reference: "How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart]"

Recommended Posts

[Quick Start] How to install Apache web server on Ubuntu 18.04
How to install R on Ubuntu 18.04 [Quick Start]
How to install Git on Ubuntu 18.04 [Quick Start]
How to install Anaconda on Ubuntu 18.04 [Quick Start]
How to install Apache on Ubuntu 20.04
How to install Bacula Server on Ubuntu 14.04
How to install Apache Maven on Ubuntu 20.04
How to install Zabbix on Ubuntu 16.04 Server
How to install Opera web browser on Ubuntu 18.04
How to install Squid proxy server on Ubuntu 18.04
How to install Chromium web browser on Ubuntu 18.04
How to install Django Web Framework on Ubuntu 18.04
How to install Ruby on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install Apache on CentOS 8
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi