<\/span><\/h2>\r\n\r\n\r\n\r\nWe need to create a new Apache configuration file. We can create it with the following command:<\/p>\r\n\r\n\r\n\r\n
nano \/etc\/httpd\/conf.d\/domain.com.conf<\/pre>\r\n\r\n\r\n\r\nAdd the following lines:<\/p>\r\n\r\n\r\n\r\n
<VirtualHost *:80>\r\n ServerAdmin admin@domain.com<\/span>\r\n DocumentRoot \"\/var\/www\/html\"\r\n DirectoryIndex index.html\r\n ServerName domain.com<\/span>\r\n ErrorLog \"\/var\/log\/httpd\/domain.com.error_log\"\r\n CustomLog \"\/var\/log\/httpd\/domain.com.access_log\" common\r\n<\/VirtualHost><\/pre>\r\n\r\n\r\n\r\nSave and close the file.<\/p>\r\n\r\n\r\n\r\n
Then, create an index.html<\/code> file for testing purposes with the following command:<\/p>\r\n\r\n\r\n\r\nnano \/var\/www\/html\/index.html<\/pre>\r\n\r\n\r\n\r\nAdd the following lines:<\/p>\r\n\r\n\r\n\r\n
<html>\r\nTest - Welcome to The Apache Web Server.\r\n<\/html><\/pre>\r\n\r\n\r\n\r\nSave the file and change owner of the ‘\/var\/www\/html\/index.html’ file to the Apache user so Apache can read the file:<\/p>\r\n\r\n\r\n\r\n
chown -R apache:apache \/var\/www\/html\/index.html<\/pre>\r\n\r\n\r\n\r\nRemember to change domain.com<\/code> with your actual domain name.
Now that we have Apache installed we can continue and install certbot<\/code>.<\/p>\r\n\r\n\r\n\r\n<\/span>Step 4: Install Certbot<\/span><\/h2>\r\n\r\n\r\n\r\nWe need to install Certbot and enable the mod_ssl<\/code> Apache module on the server. Certbot is a simple and easy to use tool that simplifies server management by automating obtaining certificates and configuring web services to use them.<\/p>\r\n\r\n\r\n\r\nBy default, Certbot package is not available in the CentOS 7 default OS repository. We need to enable the EPEL repository, then install Certbot.<\/p>\r\n\r\n\r\n\r\n
To add the EPEL repository run the following command:<\/p>\r\n\r\n\r\n\r\n
yum install epel-release<\/pre>\r\n\r\n\r\n\r\nOnce enabled, install all the required packages with the following command:<\/p>\r\n\r\n\r\n\r\n
yum install certbot python2-certbot-apache mod_ssl<\/pre>\r\n\r\n\r\n\r\nOnce installed, we can proceed to the next step.<\/p>\r\n\r\n\r\n\r\n
<\/span>Step 5: Obtain and Install SSL for Your Domain<\/span><\/h2>\r\n\r\n\r\n\r\nNow that Certbot is installed, you can use it to obtain and install an SSL certificate for your domain.<\/p>\r\n\r\n\r\n\r\n
Simply run the following command to obtain and install an SSL certificate for your domain:<\/p>\r\n\r\n\r\n\r\n
certbot --apache -d domain.com<\/span><\/pre>\r\n\r\n\r\n\r\nWe can also install a single certificate for multiple domains and subdomains hosted on the server with the ‘-d’ flag, e.g.:<\/p>\r\n\r\n\r\n\r\n
certbot --apache -d domain.com<\/span> -d www.domain.com<\/span> -d domain2.com<\/span> -d test.domain2.com<\/span><\/pre>\r\n\r\n\r\n\r\nWe will be asked to provide an email address and agree to the terms of service.<\/p>\r\n\r\n\r\n\r\n
Saving debug log to \/var\/log\/letsencrypt\/letsencrypt.log\r\nPlugins selected: Authenticator apache, Installer apache\r\nEnter email address (used for urgent renewal and security notices) (Enter 'c' to\r\ncancel): admin@domain.com\r\nStarting new HTTPS connection (1): acme-v02.api.letsencrypt.org\r\n\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\nPlease read the Terms of Service at\r\nhttps:\/\/letsencrypt.org\/documents\/LE-SA-v1.2-November-15-2017.pdf. You must\r\nagree in order to register with the ACME server at\r\nhttps:\/\/acme-v02.api.letsencrypt.org\/directory\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n(A)gree\/(C)ancel: A\r\n\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\nWould you be willing to share your email address with the Electronic Frontier\r\nFoundation, a founding partner of the Let's Encrypt project and the non-profit\r\norganization that develops Certbot? We'd like to send you email about our work\r\nencrypting the web, EFF news, campaigns, and ways to support digital freedom.\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n(Y)es\/(N)o: N\r\nStarting new HTTPS connection (1): supporters.eff.org\r\nObtaining a new certificate\r\nPerforming the following challenges:\r\nhttp-01 challenge for domain.com\r\nWaiting for verification...\r\nCleaning up challenges\r\nCreated an SSL vhost at \/etc\/httpd\/conf.d\/domain.com-le-ssl.conf\r\nDeploying Certificate to VirtualHost \/etc\/httpd\/conf.d\/domain.com-le-ssl.conf<\/pre>\r\n\r\n\r\n\r\nType Y and hit [Enter], and you should see the following output:<\/p>\r\n\r\n\r\n\r\n
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n1: No redirect - Make no further changes to the webserver configuration.\r\n2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for\r\nnew sites, or if you're confident your site works on HTTPS. You can undo this\r\nchange by editing your web server's configuration.\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\nSelect the appropriate number [1-2] then [enter] (press 'c' to cancel): 2<\/pre>\r\n\r\n\r\n\r\nHere, you need to choose any one option to continue. If you choose option 1, it will only download an SSL certificate and you need to configure Apache manually to use SSL certificate. If you choose option 2, it will automatically download and configure Apache to use SSL certificate. In this case, choose option 2 and hit [Enter]. When the installation is successfully finished, you will see a message similar to this:<\/p>\r\n\r\n\r\n\r\n
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\nCongratulations! You have successfully enabled https:\/\/domain.com<\/pre>\r\n\r\n\r\n\r\nIMPORTANT NOTES:\r\n- Congratulations! Your certificate and chain have been saved at:\r\n\/etc\/letsencrypt\/live\/domain.com-0001\/fullchain.pem\r\nYour key file has been saved at:\r\n\/etc\/letsencrypt\/live\/domain.com-0001\/privkey.pem\r\nYour cert will expire on 2019-10-22. To obtain a new or tweaked\r\nversion of this certificate in the future, simply run certbot again\r\nwith the \"certonly\" option. To non-interactively renew *all* of\r\nyour certificates, run \"certbot renew\"\r\n- If you like Certbot, please consider supporting our work by:\r\n\r\nDonating to ISRG \/ Let's Encrypt: https:\/\/letsencrypt.org\/donate\r\nDonating to EFF: https:\/\/eff.org\/donate-le<\/pre>\r\n\r\n\r\n\r\nThe generated certificate files are available in the \/etc\/letsencrypt\/live\/domain.com<\/code> directory. You can check the newly created SSL certificate with the following command:<\/p>\r\n\r\n\r\n\r\nls \/etc\/letsencrypt\/live\/domain.com<\/span>\/<\/pre>\r\n\r\n\r\n\r\nYou should see the following output:<\/p>\r\n\r\n\r\n\r\n
cert.pem chain.pem fullchain.pem privkey.pem<\/pre>\r\n\r\n\r\n\r\n