How to install Apache on Ubuntu 20.04

Article Directory

Apache is one of the most popular web servers in the world. It is an open source and cross-platform HTTP server, which hosts a large number of websites on the Internet. Apache provides a lot of powerful functions, and can extend other modules.

This article describes how to install and manage Apache web server on Ubuntu 20.04.

1. Prerequisites##

Before starting this guide, make sure you are logged in as a sudo user.

Two, install Apache

Apache is included in the default Ubuntu software source.

Installation is very straightforward. In Ubuntu and Debian systems, Apache packages and services are called apache2.

Run the following command to update the package index and install Apache:

sudo apt update
sudo apt install apache2

When the installation process is complete, the Apache service will be automatically started.

You can verify that Apache is running by entering the following command:

sudo systemctl status apache2

The output will tell you that the service is running and started on boot.

● apache2.service - The Apache HTTP Server
  Loaded:loaded(/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Active:active(running) since Sat 2020-05-0919:28:40 UTC; 36min ago
...

That's it, you have successfully installed Apache on your Ubuntu 20.04, and you can start using it.

3. Open HTTP and HTTPS ports##

Apache is listening on ports 80 (HTTP) and 443 (HTTPS). You need to open those ports in the firewall so that the web server is accessible from the Internet.

Assuming you are using UFW, you can configure it by enabling Apache Full, which includes rules for these two ports:

sudo ufw allow 'Apache Full'

Verify changes:

sudo ufw status

The output is as follows:

Status: active

To                         Action      From
- - - - - - - - - - - - 22 /tcp                     ALLOW       Anywhere
Apache Full                ALLOW       Anywhere
22 /tcp(v6)                ALLOW       Anywhere(v6)
Apache Full(v6)           ALLOW       Anywhere(v6)

Fourth, verify the Apache installation##

To verify that everything is working smoothly, open your browser and enter the server IP address http://YOUR_IP_OR_DOMAIN/, you can see the default Ubuntu 20.04 Apache welcome page, like the following:

This page contains some basic information about Apache configuration files, help scripts, and folder locations.

Five, set up a virtual host##

A virtual host is an Apache configuration command that allows you to run multiple websites on a server. A typical example, a virtual host describes a website.

Apache starts a virtual host by default. All domain names point to the server IP address, matching the default virtual host. If you only host a simple website, you need to upload the website content to /var/www/html, and edit the virtual host configuration, /etc/apache2/sites-enabled/000-default.conf file.

If you want to host more websites, you need to create a virtual host configuration for each website. In this section, we will set up a website for a domain name "example.com". You may need to replace "example.com" with your own domain name.

The first step is to create a root directory folder, where the website files of the domain name will be stored and respond to user requests. Run the following command to create this folder:

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

For testing purposes, create an index.html file in the root folder of the domain name:

<! DOCTYPE html><html lang="en" dir="ltr"><head><meta charset="utf-8"><title>Welcome to example.com</title></head><body><h1>Success! example.com home page!</h1></body></html>

When you are done, save and close the file.

To avoid permission problems, the user who modifies the root folder of the domain name belongs to the apache user (www-data):

sudo chown -R www-data:/var/www/example.com

The next step is to create a virtual host configuration for the domain name "example.com". The best practice is to store each virtual host configuration as a separate file.

Apache virtual host configuration [file storage] (https://cloud.tencent.com/product/cfs?from=10680) is in the /etc/apache2/sites-available directory. Standard naming uses a domain name to name the configuration file.

Open your text editor and create the following file /etc/apache2/sites-available/example.com.conf:

< VirtualHost *:80>
 ServerName example.com
 ServerAlias www.example.com
 ServerAdmin [email protected]
 DocumentRoot /var/www/example.com/public_html

 < Directory /var/www/example.com/public_html>
  Options -Indexes +FollowSymLinks
  AllowOverride All
 < /Directory>

 ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
 CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
< /VirtualHost>

Apache will not read the configuration files in the /etc/apache2/sites-available folder unless they are linked to the /etc/apache2/sites-enabled folder.

To activate the virtual host configuration, create a link using a2ensite:

sudo a2ensite example.com

Test the configuration file for any syntax errors:

sudo apachectl configtest

If there are no errors, you will see the following output:

Syntax OK

Restart the Apache service to make the changes take effect:

sudo systemctl restart apache2

Finally, to verify that everything works as expected, open http://example.com in your browser, and you will see a picture similar to the following:

Six, summary##

We show you how to install Apache on Ubuntu 20.04. You are now ready to deploy your application and use Apache as a website or proxy server.

Original: https://linuxize.com/post/how-to-install-apache-on-ubuntu-20-04/

 Copyright notice: This work uses Creative Commons attribution-Share 4 in the same way.0 International license agreement for licensing.

If you have any questions, please contact us in the following ways:

WeChat: sn0wdr1am86

WeChat group: add the above WeChat, remark the WeChat group

QQ: 3217680847

QQ Group: 82695646

Recommended Posts

How to install Apache on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Maven on Ubuntu 20.04
How to install Apache Tomcat 8 on Ubuntu 16.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL 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 MySQL on Ubuntu 20.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 Python 3.8 on Ubuntu 18.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 Anaconda on Ubuntu 20.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 Zoom 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 Ubuntu on Raspberry Pi
How to install Bacula Server on Ubuntu 14.04
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7