Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Let’s install Apache Web Server on Ubuntu

How to install Apache Web Server on Ubuntu and create a custom web page

Hello, Everyone! Welcome to my Medium page; this article will illustrate configuring an Ubuntu terminal with an Apache2 web server.

Here's a brief rundown of what we will accomplish.

  1. Create an Ubuntu server.
  2. Update all packages on the server.
  3. Install an Apache HTTP Web Server.
  4. Next, enable the Apache Web Server.
  5. Test the Apache Web Server using the public IP address.
  6. Create an HTML page “Welcome to LUIT — .”
  7. Create and execute a bash script to automate this process.

We will first use the A Cloud Guru website to build a server for the virtual environment.

How to configure a server:

Creates Ubuntu Server with AWS using A Cloud Guru

Once the server is up and running, use your terminal of choice ( I am using a terminal on my Mac) or PowerShell for (Windows users) to ssh into the Ubuntu server with your generated username and public IP address.

Use the Command ssh to access your newly created server remotely.

A successful login screen with information on available updates will greet you after signing in and creating a new password. Maintaining your system's updates is essential for security reasons; therefore, we will cover how to accomplish that below.

The command above shows updates available for this server.

How to Update all packages on the server:

To begin the update process, use the command sudo apt update to update the latest packages. After typing the above command, you will be asked for your password.

This command does not update your system despite what the general public thinks. Instead, Ubuntu repositories are updated in their place. As a result, your system does a repository check. It checks to see whether any updated program versions are already installed. It won't immediately update the packages you already have. But, it will update the details about those packages and the versions that are currently accessible.

How to install the Apache2 Web Server to create a website:

Use the command sudo apt install apache2 to begin the installation process or the Apache2 software.

Command for installing Apache2 Web Server

Before testing Apache, it is crucial to change the firewall settings to allow external access to the default web ports. The following command will list out the ufw application profiles: sudo ufw app list

This command will return a list of the application profiles.

Use the sudo ufw allow 'Apache' command.

This command will verify the changes by checking the status.

Use the sudo ufw status command to check your status.

Now the allowed HTTP traffic will be displayed in the output.

Use the sudo ufw enable command to activate and enable the firewall.

The firewall is active and enabled on the system startup.

Use the sudo ufw status command again to check the status, and now it should be 'Active.'

Let's check the systemd init system to ensure the service is running. Use the following command to check the service, sudo systemctl status apache2

This command illustrates that the service has started successfully.

The service has started successfully, as illustrated by this output. However, requesting a page from Apache is the most effective approach to confirm this. There are several ways to obtain your server's IP address from the command line if you are uncertain. Enter the following commands on the command prompt of your server: hostname -I

You will receive a few IP addresses separated by spaces. You can try each in your web browser to check if they work. An alternative is by running the following command, which should give you your public IP address: curl -4 icanhazip.com

The following commands give you your Public IP address.

Now that you have your IP address, enter it into your browser's address bar: http://your_server_ip

You should receive the default Ubuntu 18.04 Apache web page:

Apache2 confirmation page.

This web page indicates that Apache is working correctly. It also includes some basic information about important Apache files and directory locations.

You have now finished setting up your Apache2 web server and upgrading Ubuntu!

Next, we will edit the web page.

Begin by changing directories and navigate to the index page of your newly installed web server by using the command cd /var/www/html

Once you are in that directory, you can use the command ls to view its contents (the index page/index.html)

Use the command sudo nano index.html to edit the index page (currently, the index page contains the Apache2 welcome page in the above image).

Once you execute the nano command, you can see the Apache2 welcome page's source code.

Let's obliterate all the contents of the index page to start with a blank space to create your custom content for the page. The easiest way to delete all content is by placing a marker with CTRL+6 and deleting it with CTRL+K.

Once the content has been removed, you can create the HTML code for the page's content.

For this project, I decided to insert an image as well. To do so, use the command scp from your local machine and send the picture to your cloud server. Once you have completed, move the image to the /var/www/html folder using the cp command.

This command will copy the image from your local machine to the cloud server.
This command will copy the image to your /var subdirectory of the root directory.

Once you move the image to the correct folder, you can begin writing your HTML code for the preferred look of your page by using the sudo nano index.html command to open the nano text editor to write your code.

HTML code for the web server page.
The final outcome of the HTML code

You have now completed creating a web page on Ubuntu using an Apache2 web cloud server!

Now, we will write and execute a bash script to automate this process.

Let's use the command nano script.sh to go back into the nano text editor to create a script.

Once the nano editor opens, we can start writing the script's text. "#!/bin/bash" will be the first line of our script, followed by the commands used in previous steps to automate the process.

Script to automate

Once you are done writing the script, save it and exit the Text Editor by pressing CTRL+X. Lastly, let's run the bash script.sh command to see our automated process.

Thank you, everyone, for reading my blog!

If you find this helpful, please click the clap 👏 button below a few times to show your support for the author 👇

🚀Join FAUN & get similar stories in your inbox each week


Let’s install Apache Web Server on Ubuntu was originally published in FAUN Publication on Medium, where people are continuing the conversation by highlighting and responding to this story.

Share the post

Let’s install Apache Web Server on Ubuntu

×

Subscribe to Top Digital Transformation Strategies For Business Development: How To Effectively Grow Your Business In The Digital Age

Get updates delivered right to your inbox!

Thank you for your subscription

×