Personal Web Server Setup

Prepared by: Anwer Sadath Abdul Muttaliff

Step 1: Install CentOS 9 Stream

Step 2: Install and Configure Apache Web Server

Install Apache
$ sudo yum install httpd -y
Install Apache
Start and Enable Apache
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
Create a Simple HTML Page
$ echo "<html><h1>Welcome to My Web Server!</h1></html>" | sudo tee /var/www/html/index.html
$ echo "<html><h2>By Anwer Sadath</h2></html>" | sudo tee -a /var/www/html/index.html
$ sudo systemctl restart httpd
Apache Running

Step 3: Generate SSL Certificates using OpenSSL

Generate Private Key and Self-Signed Certificate

Create a directory to store your SSL certificates:

$ sudo mkdir -p /etc/ssl/mycerts

Generate a private key and self-signed certificate:

$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/mycerts/localhost.key -out /etc/ssl/mycerts/localhost.crt

When prompted, fill in the certificate details. For Common Name, enter localhost.

Step 4: Configure Apache to Use SSL

Update Apache SSL Configuration

Edit the Apache SSL configuration file:

$ sudo vi /etc/httpd/conf.d/ssl.conf

Find and update the following lines to point to your certificate and key files:

SSLCertificateFile /etc/ssl/mycerts/localhost.crt
SSLCertificateKeyFile /etc/ssl/mycerts/localhost.key

Add or update the ServerName directive:

ServerName localhost:443

Save and exit the file.

Step 5: Set Permissions and Ownership

Apply Correct Permissions
$ sudo chown root:root /etc/ssl/mycerts/localhost.crt
$ sudo chown root:root /etc/ssl/mycerts/localhost.key
$ sudo chmod 600 /etc/ssl/mycerts/localhost.key
$ sudo chmod 644 /etc/ssl/mycerts/localhost.crt

Step 6: Adjust SELinux Permissions

Set SELinux Contexts

Set the appropriate SELinux file contexts:

$ sudo semanage fcontext -a -t cert_t "/etc/ssl/mycerts(/.*)?"
$ sudo restorecon -Rv /etc/ssl/mycerts

Step 7: Start Apache Service

Restart Apache
$ sudo systemctl restart httpd
$ sudo systemctl status httpd
Web Server Running

Step 8: Test HTTPS Access

Verify the Web Server is Running with SSL

Open a web browser and navigate to https://localhost/. You may receive a security warning due to the self-signed certificate. Proceed past the warning to view the site.

Back to Top Back to Home