Prepared by: Anwer Sadath Abdul Muttaliff
sudo yum update -y
to update the system.$ sudo yum install httpd -y
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
$ 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
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
.
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.
$ 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
Set the appropriate SELinux file contexts:
$ sudo semanage fcontext -a -t cert_t "/etc/ssl/mycerts(/.*)?"
$ sudo restorecon -Rv /etc/ssl/mycerts
$ sudo systemctl restart httpd
$ sudo systemctl status httpd
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.