Install the Apache web server
- Summary
- This tutorial shows you how to install an Apache web server on Debian and RPM-based Linux distributions.
- Internet
- https://httpd.apache.org/
flowchart LR
A(Launch terminal and SSH the virtual machine) --> B(Update the OS)
B --> C(Install the Apache web server)
C --> D(Test functionality)
D --> E(Create content)
Prerequisites
- An existing virtual machine. Create a virtual machine in cPouta over the web/cli
- Security Groups and rules for SSH and HTTP defined. Connect your virtual machine to the Internet via the web/cli
- An active SSH connection to your virtual machine. Connect to your virtual machine
Procedure
Let's start by checking the Linux distribution you're using.
Type the command:
grep NAME /etc/os-release
Look at the output and check whether your distribution is Ubuntu, Almalinux, Centos or some other. Below is a sample output from Ubuntu Linux.
Based on your output, follow the appropriate instructions below.Ubuntu
First, let's make sure your computer is up to date:
sudo apt-get update && sudo apt-get upgrade
Check the possible updates to be installed and accept them with 'y'.
$ sudo apt-get update && sudo apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
...
9 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Need to get 5836 kB of archives.
After this operation, 9216 B of additional disk space will be used.
Do you want to continue? [Y/n] y
...
$ _
sudo apt-get install apache2
Again, check the changes and accept them with 'y'.
$ sudo apt-get install apache2
Reading package lists... Done
Building dependency tree... Done
...
0 upgraded, 13 newly installed, 0 to remove and 4 not upgraded.
Need to get 2139 kB of archives.
After this operation, 8518 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
...
$ _
That's it!
You have a web server running.
Almalinux and Centos
First, let's make sure your computer is up to date:
sudo dnf update
Check the possible updates to be installed and accept them with 'y'.
$ sudo dnf update
AlmaLinux 9 - AppStream 7.7 MB/s | 9.4 MB 00:01
AlmaLinux 9 - BaseOS 4.5 MB/s | 4.8 MB 00:01
...
Install 9 Packages
Upgrade 74 Packages
Total download size: 150 M
Is this ok [y/N]: y
...
$ _
Next, install the Apache web server using the following command:
sudo dnf install httpd
Again, check the changes and accept them with 'y'.
$ sudo dnf install httpd
Last metadata expiration check: 0:20:36 ago on Sun Dec 6 07:12:37 20xx.
Dependencies resolved.
...
Install 12 Packages
Total download size: 2.0 M
Installed size: 6.0 M
Is this ok [y/N]: y
...
$ _
Finally, we need to activate the Apache web server service:
sudo systemctl start httpd
sudo systemctl enable httpd
The systemctl enable
command ensures that the service is started with the server.
That's it!
You have a web server running.
Afterword
A newly installed web server can be tested from the virtual machine's command line with command:
curl localhost
It should print out the default index.html
of the Apache web server.
When accessing the page with a browser via the public Internet using the public ip, the view is something like this:
To start creating content, edit the /var/www/html/index.html
file with the following content, for example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>For those about to rock</title>
</head>
<body>
We salute you!
</body>
</html>
Refresh your index page. It should now look like this:
Further Learning
Here are some suggestions for what to read next: