
Apache is an open-source, high-performance web server for delivering web content. It integrates well with server-side scripting languages like PHP and databases like MySQL or PostgreSQL to serve dynamic web content.
In this article, you'll learn how to install apache on rocky linux 9, set up virtual hosts, and secure the webserver by configuring a firewall and generating an SSL certificate. For those migrating from an older version, you may also find our article on How to Upgrade from Rocky Linux 8 to Rocky Linux 9 helpful.
Before you begin:
app.example.com.Apache is available in the default repositories on Rocky Linux 9. Follow the steps below to install Apache using the DNF package manager.
Update the server's package information index.
Install httpd on Rocky Linux 9, the Apache webserver package.
Allow connections on the HTTP port 80 through the default firewall.
Reload the firewall configuration to apply the changes.
Access your server's public IP address (For example, 192.0.2.1) on a web browser such as Chrome.
Verify that Apache serves the default web application.
Apache runs under the httpd system service on Rockly Linux 9. Follow the steps below to manage and monitor the service using systemctl.
Enable Apache to start at system boot automatically.
Start the Apache webserver.
Check the Apache webserver status and verify it's running.
Stop the Apache webserver.
Restart the Apache webserver.
Apache webserver uses virtual host configurations to host web applications using separate domains and directories. Follow the steps below to create a new Apache virtual host configuration to deliver a sample web application for the app.example.com domain.
Navigate to the Apache configuration files directory.
Create a new app.example.com.conf configuration file using a text editor like nano.
Add the following contents to the file. Replace app.example.com with your actual domain.
Save and close the file.
The above Apache configuration creates a new virtual host that serves web application files from the /var/www/app.example.com directory for the app.example.com domain. Within the configuration:
<VirtualHost>: Creates a new Apache virtual host.*:80: Enables Apache to listen for incoming connections on the HTTP port 80.ServerAdmin: Specifies the server administrator's email address.ServerName: Sets the virtual host's domain or IP address.DocumentRoot: Sets the web root directory containing the virtual host's files.ErrorLog: Sets a custom log file location to store the virtual host's error logs.CustomLog: Sets a custom access log location to store the virtual host's error logs.Create a new web root directory to store your web application files.
Create a new index.html web application file.
Add the following contents to the index.html file.
Save and close the file.
The above HTML application displays a Greetings from Vultr! message when you access it using the virtual host's domain.
Test the Apache configuration for errors.
Output:
Restart the Apache service to apply the new changes.
Open your domain on a new web browser window to test access to the web application.
Firewalld is available and active by default on Vultr Rocky Linux 9 instances. Follow the steps below to set up new firewall rules using the firewall-cmd utility to allow network connections to the Apache webserver.
Allow HTTP connections through the firewall.
Allow HTTPS connections through the firewall.
Reload the firewall rules to apply the changes.
By default, Apache runs on the insecure HTTP port 80. To secure Apache with HTTPS, generate an SSL certificate using a trusted Certificate Authority (CA) like Let's Encrypt by following the steps below.
Install the Certbot Let's Encrypt client tool and plugin for Apache.
Restart the Apache service.
Generate a new SSL certificate for your virtual host domain. Replace app.example.com with your domain name and hello@example with your email address.
Test the Certbot automatic SSL certificate renewal process.
Access your domain on a web browser via HTTPS and verify that your web application displays.
You have installed the Apache webserver on Rocky Linux 9, created a virtual host, and secured the webserver with a firewall and an SSL certificate. You can configure multiple Apache virtual hosts to run different applications on the same server. You can also integrate Apache with server-side scripting languages like PHP and database systems like MySQL and PostgreSQL to run dynamic web applications. For more information, visit the Apache documentation.
0 Comments
Be the first to comment and share your perspective with the community.