The Apache HTTP server is the most popular web server on the globe. It has a wide range of powerful features, such as dynamically loadable modules, robust media support, and extensive integration with other popular software.
Requirements:
A system running Ubuntu
An internet connection
Access to a user account with sudo privileges
Installation Process of Apache Server:
Here, in this document, I have included a step-by-step method to install Apache HTTP web server on an Ubuntu machine.
STEP-1: Apache Package Installation
To begin, let us update the local package index to reflect the most recent upstream changes:
$ sudo apt update
Install the apache2 package next:
$ sudo apt install apache2
apt will install Apache and all required dependencies after you confirm the installation.
STEP-2: Firewall Configuration
Before running Apache, we must change the firewall settings to allow outside access to the default web ports.
List the ufw application profiles by typing:
$ sudo ufw app list
We will receive a list of the application profiles:
Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
Since we haven’t configured SSL for our server yet in this document, we will only need to allow traffic on port 80:
$ sudo ufw allow 'Apache'
You can verify the change by typing:
$ sudo ufw status
The output will provide a list of allowed HTTP traffic:
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Apache ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Apache (v6) ALLOW Anywhere (v6)
The profile has been activated to allow access to the Apache web server, as indicated by the output.
STEP-3: Checking the Web Server
Ubuntu starts Apache at the end of the installation process. The web server should already be operational.
Check the service's status with the systemd init system by typing:
$ sudo systemctl status apache2
Output
apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-04-23 22:36:30 UTC; 20h ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 29435 (apache2)
Tasks: 55 (limit: 1137)
Memory: 8.0M
CGroup: /system.slice/apache2.service
├─29435 /usr/sbin/apache2 -k start
├─29437 /usr/sbin/apache2 -k start
└─29438 /usr/sbin/apache2 -k start
The service has started successfully, as evidenced by this output. However, requesting a page from Apache is the best way to test this.
STEP-4: Managing the Apache Process
Now that our web server is up and running, let's go over some basic systemctl management commands.
To stop your web server, 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
STEP-5: Setting Up Our Virtual Hosts
When using the Apache web server, we can encapsulate configuration details and host multiple domains from a single server by using virtual hosts (similar to server blocks in Nginx). We will register the domain prosaugat.com.
Create the directory for prosaugat.com as follows:
$ sudo mkdir /var/www/prosaugat.com
Next, assign ownership of the directory with the $USER environment variable:
$ sudo chown -R $USER:$USER /var/www/prosaugat.com
To ensure that our permissions are correct and that the owner has permission to read, write, and execute files while granting only read and execute permissions to groups and others, we can run the following command:
$ sudo chmod -R 755 /var/www/prosaugat.com
Next, create a sample index.html page using Nano or Vim editor:
$ sudo nano /var/www/prosaugat.com/index.html
Inside this directory, add the following sample HTML:
/var/www/prosaugat.com/index.html
<html>
<head>
<title>Welcome ProSaugat's Test Site!</title>
</head>
<body>
<h1>Hey! Bro Configuration Successful.</h1>
</body>
</html>
Save and close the file when you are finished.
To enable Apache to serve this content, a virtual host file containing the necessary directives must be created. Rather than directly modifying the default configuration file at /etc/apache2/sites-available/000-default.conf, let's create a new one at /etc/apache2/sites-available/prosaugat.com.conf
$ sudo nano /etc/apache2/sites-available/prosaugat.com.conf
Copy and paste the following configuration block, which is similar to the default but has been updated to reflect our new directory and domain name:
<VirtualHost *:80>
ServerAdmin admin@prosaugat.com
ServerName prosaugat.com
ServerAlias prosaugat.com
DocumentRoot /var/www/prosaugat.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file.
Let’s enable the file with the a2ensite tool:
$ sudo a2ensite prosaugat.com.conf
Disable the default site defined in 000-default.conf:
$ sudo a2dissite 000-default.conf
Next, let’s test for configuration errors:
$ sudo apache2ctl configtest
You should receive the following output:
Output
Syntax OK
Restart Apache to implement your changes:
$ sudo systemctl restart apache2
Apache should now be serving our domain name. We can test this by navigating to http://prosaugat.com.
1 Comments
informative content mate.
ReplyDelete