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.
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.
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
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)
Check the systemd
init 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:
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:
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