How to Install Apache Web Server on Ubuntu 22.04

install apache web server on ubuntu 22.04

Apache HTTP Server is an open-source and free service that is utilized to provide static and dynamic web pages. It’s extremely utilized and is extensively employed by hosting firms. Based on research by W3techs.com, Apache powers 31% of websites.

It’s one of the most popular web servers for Linux VPS hosting that is continuously maintained by the Apache Software Foundation. It’s used by many prominent companies and cPanel servers. It works with Operating platforms like Linux, Windows, and macOS, as well as others.

In this tutorial, we’ll discuss how to install the Apache server in Linux step by step.

 

How to Start Apache Server in Ubuntu

The current version of the Apache HTTP Server is 2.4.54. This new generation branch is likely to utilize lesser memory compared to the 2.2.x branch. It can also allow users to create variables inside Apache in the configuration file.

The following are the necessary prerequisites to configure the Apache web server on Ubuntu:

  • Minimum of 4GB RAM and at least 5GB in storage.
  • Java version 8 and later. For a quick check to see if Java is present, You can run the Java version command to check the version of Java on your device.
  • Installation of the Apache web server may be accomplished by using a non-root account with sudo rights.

 

Step 1: Install Apache on Ubuntu 22.04

When you buy Linux VPS hosting, by default, Apache is included in repositories for software and allows you to install the software using standard toolboxes for managing packages.

Make sure to update your local package index to reflect the most recent downstream changes:

sudo apt update

After that, install your apache2 package.

sudo apt install apache2

Once the installation is confirmed, apt will start installing Apache as well as all dependencies that are required.

 

Step 2: Adjusting the Firewall

Prior to testing Apache, you must alter the firewall settings order so that it is accessible from the web. If you’ve followed the steps in the requirements, you have the UFW firewall that is configured to block access to the server.

In the course of installation, Apache registers itself with UFW and provides a couple of app profiles that can be utilized to allow or de-block access to Apache via the firewall.

Check the profiles of the UFW of the application by doing these commands:

sudo ufw app list

According to the output you normally get when you configure the Apache web server on Ubuntu, there are three Apache profiles offered by Apache:

  • Apache profile opens just port 80 (normal internet traffic that is unencrypted)
  • Apache full allows access to both ports 80 as well as port 443 (TLS/SSL encrypted web traffic)
  • Apache secure profile, this one is only available on port 443 (TLS/SSL encrypted traffic)

It’s recommended to set the profile with the lowest restrictions, which will allow traffic that you’ve set up. As you’ve not yet set up SSL for your server, however, nowadays, when you buy a Linux VPS hosting, it automatically comes with a free SSL certificate; for the sake of this article, you’ll need to permit traffic through port 80:

sudo ufw allow ‘Apache’

It is possible to verify that the changes have occurred by checking the status:

sudo ufw status

 

Step 3: Checking your Web Server

Once you configure the Apache web server on Ubuntu and finish the installation process, Ubuntu 22.04 begins Apache. The server should start up.

Verify that you are running the service using the following command:

sudo systemctl status apache2

The standard Apache landing page will be displayed in order to ensure that the program is operating in a proper manner via the IP address of your server. If you aren’t sure of the server’s IP address, you’ll be able to find it in a number of ways using the command line.

Write the following in the command prompt on your server:

hostname -I

It is possible to receive several addresses that are separated by spaces. You can test each of them within your browser to test the effectiveness of these addresses and find the proper IP that is connected to your Apache server.

An alternative is to utilize the cost-free icanhazip.com tool. It is a site that, upon being accessed, will display your computer’s public IP address as it is read by a different location via the web:

curl -4 icanhazip.com

Once you’ve got the IP address of your server, paste it into the internet browser’s address bar. If you buy Ubuntu VPS hosting from a reliable hosting provider, they’ll be able to tell you your IP address that is connected to the Apache server you’ve just installed.

 

Step 4: Managing the Apache Process

After you’ve got your website server set up and up, let’s go over some of the basic management tools that you can execute using systemctl.

To stop your web server, run the following:

sudo systemctl stop apache2

To restart the server after it has been shut down, start:

sudo systemctl start apache2

To stop the service and start service over again, do the following:

sudo systemctl restart apache2

If you’re changing configurations, Apache can often reload without losing connections. In order to do this, run the below command:

sudo systemctl reload apache2

By default, Apache will begin automatically the moment it starts. If you don’t think this is the way you would like to go, then deactivate this feature by running the following:

sudo systemctl disable apache2

To reenable the service to run on boot, you must type the following:

sudo systemctl enable apache2

Apache will start up automatically as soon as the server starts up once more.

 

Step 5: Setting Up Virtual Hosts

In the case of you using an Apache web server, it is possible to make use of virtual hostnames (similar to the server blocks that are part of Nginx) to store configuration information and host multiple domains on the same server. You will be able to set up the domain as your_domain, and you need to change this to the name of your domain.

Once you install Apache on Ubuntu 22.04, it comes with a single server block, which is activated by default and is set to provide documents via the  /var/www/html directory. This is fine when hosting a single site. It could become cumbersome if you host multiple websites. Instead of changing the structure of /var/www/html to create an organization of directories within the directory /var/www to host your domain site. Leave the directory /var/www/html to be the default directory that will be used if the client request is not compatible with the other websites.

Make your directory on your domain in the following manner:

sudo mkdir /var/www/your_domain

After that, give control of the directory to the account that you’re currently logged in as using an “$USER” Environment variable:

sudo chown -R $USER:$USER /var/www/your_domain

The permissions for your web root must be in order in the event that you’ve not altered the value of your umask, which determines default permissions for files. To make sure that your permissions are accurate and allow the user to write, read and run the files while giving only read and execute permissions to groups, as well as others, you can enter this command:

sudo chmod -R 755 /var/www/your_domain

Then, you can create an example index.html page using nano or another editor of your choice:

sudo nano /var/www/your_domain/index.html

For Apache to provide this service, you must build a virtual host file that contains the appropriate directives. Instead of changing this default file, you can modify the configuration that is found at /etc/apache2/sites-available/000-default.conf, create a brand-new one. /etc/apache2/sites-available/your_domain .conf:

sudo nano /etc/apache2/sites-available/your_domain.conf

Files are saved and closed once you’ve finished.

You can now enable the file by using the tool a2ensite tool:

sudo a2ensite your_domain.conf

Delete the default website as defined by 000-default.conf:

sudo a2dissite 000-default.conf

Next, test for configuration errors:

sudo apache2ctl configtest

Restart Apache to make the changes you made:

sudo systemctl restart apache2

 

Conclusion

When you buy Ubuntu VPS hosting, you can start installing the Apache server on it. In this guide, we tried to answer your “how to start Apache server in Ubuntu” and “how to install Apache server in Linux step by step”. Once you’ve installed the web server and it’s running, you have a wide range of choices in terms of the kind of content that you are able to serve and the tools you are able to make use of to enhance your user experience.

Leave a Reply

Your email address will not be published.