Introduction

Apache HTTP server is the most used in the world. It offers many powerful features, including dynamically loaded modules, strong media compatibility, and extensive integration with other popular software tools.

Through this guide, you will install an Apache web server with virtual hosts on your CentOS 8 server.

Previous requirements

You will need the following to complete this guide:

Step 1: Install Apache

Apache is available within the default CentOS software repositories, which means you can install it with the package manager dnf.

Since we configured a non-root sudo user in the prerequisites, install the Apache package:

sudo dnf install httpd

Once the installation is confirmed, it will dnfinstall Apache and all the necessary dependencies.

By completing step 4 of the Initial Server Configuration with CentOS 8 guide mentioned in the prerequisites section, you have already installed firewalldon your server to supply requests via HTTP.

If you are also planning to configure Apache to provide content over HTTPS, you may also want to open the port 443by enabling the service https:

sudo firewall-cmd --permanent --add-service=https

Then reload the firewall for these new rules to take effect:

sudo firewall-cmd --reload

Once the firewall is reloaded, you are ready to start the service and check the web server.

Step 2: Check your web server

Once the installation is complete, Apache does not start automatically in CentOS, so you will have to start the Apache process manually:

sudo systemctl start httpd

Verify that the service works with the following command:

sudo systemctl status httpd

You will get a status activewhen the service is running:

Output

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disa>
   Active: active (running) since Thu 2020-04-23 22:25:33 UTC; 11s ago
     Docs: man:httpd.service(8)
 Main PID: 14219 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 5059)
   Memory: 24.9M
   CGroup: /system.slice/httpd.service
           ├─14219 /usr/sbin/httpd -DFOREGROUND
           ├─14220 /usr/sbin/httpd -DFOREGROUND
           ├─14221 /usr/sbin/httpd -DFOREGROUND
           ├─14222 /usr/sbin/httpd -DFOREGROUND
           └─14223 /usr/sbin/httpd -DFOREGROUND

...

As this result indicates, the service started successfully. However, the best way to check this is to request an Apache page.

You can access Apache’s default landing page to confirm that the software is working properly using its IP address: If you don’t know your server’s IP address, you can obtain it in several ways from the command line.

Type qto return to the command line, and then type:

hostname -I

This command will display all the network addresses of the host, so you will get some IP addresses separated by spaces. You can test each one in the web browser to determine if they work.

Alternatively, you can use curlto request your IP at icanhazip.com, which will provide you with your public IPv4 address as it appears in another location on the Internet:

curl -4 icanhazip.com

When you have the IP address of your server, enter it in the address bar of your browser:

http://your_server_ip

It will display the default Apache web page in CentOS 8:

Apache default page for CentOS 8

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

#centos #apache #centos 8

How to install Apache web server on CentOS 8
1.50 GEEK