What is Apache?
Users can upload webpages to the internet using the free and open source web server software Apache. This server, officially known as the Apache HTTP Server, now serves as the foundation for 33% of websites globally. The Apache Software Foundation oversees and develops Apache, one of the most experienced and effective web servers, which was originally made available in 1995.
How it works?
Instead of existing as a physical server, Apache exists as server-operating software. Its purpose is to create a connection between the website visitor's browser (such as Firefox, Google Chrome, Safari, etc.) and the server so that files can be sent back and forth (between client-server). Because Apache is cross-platform software, it can run on both Windows and Unix servers.
The visitor's browser sends a request to your server when they load a certain page on your website, like the home page or "About Us," and Apache responds by loading all the files requested (text, images, etc.). HTTP protocol is used by the server and client for communication, and Apache is in charge of ensuring a quick and secure connection between them.
Because it has a module-based structure, Apache is simple to maintain. Server administrators can enable and disable extra features or services using modules. For security, caching, URL rewriting, password authentication, and many more purposes, Apache offers modules.
Advantages and disadvantages of Apache
In addition to Apache, there are numerous additional web servers. These web server programs were created for various uses. Although frequently used, Apache undoubtedly has many competitors.
On the one hand, running websites on a complex and reliable platform requires the Apache web server, which is the finest option. However, Apache also has some disadvantages that you need to be aware of.
Advantages:
- Free and open-source, even for commercial use.
- solid and dependable software
- security patches that are regularly updated.
- It is adaptable because to its module-based architecture.
- Simple configuration and not too challenging for beginners.
- Between platforms (works on both Unix and Windows servers).
- It can be applied to a WordPress website as well.
- The size of the community makes it simple for users to identify issues.
Deficiency:
- When a website has a lot of traffic, its performance is affected.
- There may be security flaws if there are too many setting options.
How to install Apache?
The steps that we provide below can be use for your windows or linux. Here we provide video tutorials to make it easier for you to understand;
If you don't have everything, please visit the link below to have it, Remember that actually just using ubuntu will suffice because that is the default. You can skip this download if you don't want to install it automatically:
NOTABLE! :
Pre-condition
Before you start this guide, you should have a regular non-root user with sudo privileges configured on your server. Additionally, you will need to enable a basic firewall to block non-essential ports. When you already have an account, log in as a non-root user to get started.
1. Installing Apache
Apache is available in the default Ubuntu software repositories, which allows Apache to be installed using conventional package management tools.
Let's start by updating the local package index to reflect the latest upstream changes:
sudo apt update
Then, install the apache2 package:
sudo apt install apache2
After confirming the installation, apt will install Apache and all required dependencies.
2. Customizing Firewall
You need to modify your firewall settings to allow outside access to the default web port. Followed the instructions in the prerequisites, you should have a UFW firewall configured to restrict access to your server.
During installation, Apache registers itself with UFW to provide several application profiles that can be used to enable or disable access to Apache through the firewall.
Create a list of ufw application profiles by typing:
sudo ufw app list
You will receive a list of application profiles:
Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
As the output shows:
- Apache: This profile only opens port 80 (normal and unencrypted web traffic)
- Apache Full: This profile opens both port 80 (normal and unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
- Apache Secure: This profile only opens port 443 (TLS/SSL encrypted traffic)
It is recommended that you enable the most restrictive profile that will still allow the traffic you have configured. Since we haven't configured SSL for our server in this guide, we only need to allow traffic on port 80:
sudo ufw allow 'Apache'
Verify the changes by typing:
sudo ufw status
The output will give 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)
That profile has been enabled to allow access to the Apache web server.
3. Checking Your Web Server
At the end of the installation process, Ubuntu 20.04 starts Apache. The web server should be up and running.
Check with 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)
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. The best way to test this is to request a single page from Apache.
You can access the default Apache landing page to confirm that the software is running properly via your IP address. If you don't know your server's IP address, you can get it a few different ways from the command line.
Try typing this in your server's command prompt:
hostname -I
You will get several addresses separated by spaces. You can try each address in your web browser to see if it works.
Another option is to use the Icanhazip tool:
curl -4 icanhazip.com
When you have the IP address of your server, enter it into your browser's address bar:
http://your_server_ip
You should see the default Apache Ubuntu 20.04 webpage:
This page
indicates that Apache is working properly. It also includes some basic information about Apache's important files and directory locations.
4. Managing Apache Process
Now that your web server is up and running, let's cover some basic management commands using systemctl.
To stop your web server, type:
sudo systemctl stop apache2
To start the web server when it stops, type:
sudo systemctl start apache2
To stop and then start the service again, type:
sudo systemctl restart apache2
if you only make configuration changes, Apache can often reload without breaking the connection. To do this, use this command:
sudo systemctl reload apache2
By default, Apache is configured to start automatically when the server boots. If this is not what you want, you can disable this behavior by typing:
sudo systemctl disable apache2
To re-enable the service to start at boot, type:
sudo systemctl enable apache2
Apache will now start automatically when the server reboots.
5. Setting Up a Virtual Host
When using Apache web servers, recomended for you to use virtual hosts to encapsulate configuration details and host multiple domains from a single server. We will set up a domain named your_domain, you will need to replace it with your own domain name.
Apache on Ubuntu 20.04 has a server block active by default, which is configured to serve documents from the /var/www/html directory. While this works great for single sites, it can be difficult to run if you're hosting multiple sites. Instead of modifying /var/www/html, let's create a directory structure inside /var/www for your_domain site, leaving /var/www/html in its place as the default directory to serve if client requests don't match other sites any.
Create a directory for your_domain as follows:
sudo mkdir /var/www/your_domain
Next, specify directory ownership with the $USER environment variable:
sudo chown -R $USER:$USER /var/www/your_domain
The permissions of your web root should be correct if you haven't changed your umask value, which sets the default file permissions. To make sure your permissions are correct and allow the owner to read, write, and execute the file, while granting read-only permissions to the group and others, you can enter the following command:
sudo chmod -R 755 /var/www/your_domain
Next, create an index.html page using nano or your favorite editor:
sudo 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>
<h1>Success! The your_domain virtual host is working!</h1>
</body>
Save and close the file when you're done.
In order for Apache to serve this content, we need to create a virtual hosts file with the correct directions. Instead of modifying the default configuration file located in /etc/apache2/sites-available/000-default.conf directly, let's create a new one in /etc/apache2/sites-available/your_domain.conf:``
sudo nano /etc/apache2/sites-available/your_domain.conf
Paste in the following configuration block, which is similar to the default, but updated for our new domain name and directory:
/etc/apache2/sites-available/your_domain.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Notice that we've updated DocumentRoot to our new directory and ServerAdmin to an email that your_domain site administrator can access. We've also added two directives: ServerName, which defines the base domain that should match this virtual host definition, and ServerAlias, which defines a further name that should match, as if it were the base name.
Save and close the file when you're done.
Let's activate the file with the a2ensite tool:
sudo a2ensite your_domain.conf
Disable the default site set in 000-default.conf:
sudo a2dissite 000-default.conf
Next, let's test for configuration errors:
sudo apache2ctl configtest
You will receive the following output:
Output
Syntax OK
Restart Apache to apply your changes:
sudo systemctl restart apache2
Apache should now serve your domain name. You can test this by navigating to http://your_domain, where you should see something like this:
Success! The your_domain virtual host is working.
6. Familiarize yourself with Apache's Important Files and Directories
Now that you know how to manage your own Apache service, it should take you a few minutes to familiarize yourself with some of the important directories and files.
Contents
- /var/www/html: The actual web content, which by default consists only of the default Apache page you saw earlier, served from the /var/www/html directory. This can be changed by changing the Apache configuration file.
Server Configuration
- /etc/apache2: Apache configuration directory. All Apache configuration files are here.
- /etc/apache2/apache2.conf: Apache's main configuration file. This can be modified to make changes to the Apache global configuration. This file is responsible for loading many other files in the configuration directory.
- /etc/apache2/port.conf: This file specifies the ports that Apache will listen to. By default, Apache listens for port 80 and additionally listens for port 443 when the module providing SSL capabilities is enabled.
- /etc/apache2/sites-available/: Directory where virtual hosts per site can be stored. Apache will not use the configuration files found in this directory unless they are linked to the sites-enabled directory. Usually, all server block configuration is done in this directory, then activated by connecting to another directory with the a2ensite command.
- /etc/apache2/sites-enabled/: The directory where virtual hosts are stored per enabled site. Typically, these are created by linking to a configuration file found in the sites-available directory with a2ensite. Apache reads the configuration files and links found in this directory during startup or reloading to compile the complete configuration.
- /etc/apache2/conf-available/, /etc/apache2/conf-enabled: This directory has the same relationship as the sites-available and sites-enabled directories, but is used to store configuration fragments that are not supposed to reside on the virtual host. Files in the conf-available directory can be enabled with the a2enconf command and disabled with the a2disconf command.
- /etc/apache2/mods-available/, /etc/apache2/mods-enabled/: These directories contain available and enabled modules, respectively. Files ending in .load contain fragments for loading a particular module, while files ending in .conf contain configurations for that module. Modules can be enabled and disabled using the a2enmod and a2dismod commands.
Server Logs
- /var/log/apache2/access.log: By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise.
- /var/log/apache2/error.log: By default, all errors are recorded in this file. The LogLevel directive in the Apache configuration specifies how much detail will be logged in the error log.
All is done and you can enjoy this all easily if you do the steps correctly. Once your web server is installed, you have many options for the types of content you can serve and the technologies you can use to create richer experiences.
ubuntu web server
apache linux
virtual host apache2
apache server linux
apache install linux
Post a Comment for "Virtual Host Apache2 - How to Install"