22.2 F
Nashville
Friday, December 6, 2024

How to Install the Apache Web Server on CentOS Stream 9

Apache is available within CentOS's default software repositories, which means you can install it with yum.

How to Create Users in Linux

Linux is a multi-user system, meaning that more than one person can interact with the same system simultaneously.

How to Create Bash Aliases

This tutorial demonstrates how to use the alias command to create personalized shortcuts, which can help you save time and feel less frustrated.

How to Create Apache Virtual Hosts on CentOS Stream 9

First, ensure that Apache is installed on your CentOS Stream 9 system. 

Virtual Hosts are defined within configuration files with a .conf extension

Create a new file with your text editor

vim /etc/httpd/conf.d/mydomain.com.conf

It’s recommended to create a new file for each domain to keep things organized.

Port 80 is the default HTTP port
Port 443 is the default HTTPS port

In this file, you’ll set up a block for your domain:

<VirtualHost *:80>
    ServerName mydomain.com 
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/mydomain 
    ErrorLog /var/log/httpd/mydomain-error.log
</VirtualHost>

<VirtualHost *:443>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/domain
        SSLEngine On
        SSLCertificateFile /path/to/ssl/cert.crt
        SSLCertificateKeyFile /path/to/ssl/key.key
</VirtualHost>

Check for syntax errors after configuring your virtual hosts

apachectl configtest

If you get a ‘Syntax OK’ output, restart apache to apply the changes:

systemctl restart httpd

Setup local hosts file

If you’re testing your configuration locally, edit your /etc/hosts file to point the domain to your local server

127.0.0.1 mydomain.com www.mydomain.com

Let’s Encrypt is a Certificate Authority (CA) and provides a free way to obtain certificates.

For more information on securing your virtual host with an SSL certificate from Let’s Encrypt

https://letsencrypt.org/getting-started

https://certbot.eff.org

If you’re on a Mac or Linux computer, with administrative privileges you can easily preview your website on the local network. This helps if your domain is not yet registered, not pointed to a hosting account, or is still propagating.

vim /etc/hosts

Your_Server_IP domain.com

Similar Articles

- A word from our sponsors -

Follow Us

Most Popular