How to Add SSL Certificates to Custom PHP Sites

by Ahmed Khan  May 6, 2016

In this age of information insecurity, all websites, that handle sensitive customer information such as passwords, credit card numbers etc., must offer secure and encrypted communication channels. In the absence of such channels, intercepting and stealing customers’ information becomes quite easy for anyone.

A Secure Socket Layer (SSL) certificate encrypts the connection between the customer and your web server so that the information is rendered unreadable by all third parties (identity thieves and hackers).

ssl custom php site

Now that we know why SSL certificates are an essential necessity,  let’s get started on how you could add one to your site on Cloudways. If you don’t have an account, Sign Up Now. Now let’s get started with the following steps:

Step 1: Setup Certificate Signing Request(CSR):

Go to your SSL certificate under Application Management Tab and click on create CSR certificate. Fill the form and click Submit.

Certificate Signing Request

Once in the SSL Certificate window, change your slider to Paid Certificate and Click on Create CSR.

Let's Encrypt

image11

After submission, wait for the creation of the CSR. Once done, download it.

Create CSR

Step 2: Create SSL Certificate

Now go to this site to create your free SSL certificate, valid for 30 days. Follow the steps below:

  • Account Info: First connect to your SSH Terminal and run these commands to create your Public Key. OpenSSL comes preinstalled on Cloudways.

    Public Key

    Now type in the email that you used when you created CSR. Paste the generated key in the Account Public Key box and click on Validate Account Info button.

    Validate Account Info

  • Add Certificate Signing Request: Now open the CSR that you downloaded earlier and paste it in the relevant box. Click on Validate CSR button.Validate CSR
  • Sign API Requests: In this step, you will run all the commands in the terminal and paste the output in the text boxes. Click on Validate Signatures button.Validate Signatures
  • Verify Ownership: To verify ownership, follow these steps.

First, run the required command in terminal and click on File-based tab.

Next, in the terminal, type the following command to go to the public_html folder:

Now copy the highlighted URL from step 4 and replace with your URL in the code below.

Replace your URL

Now go to the terminal and type the following command:

Now press Insert Key from keyboard and paste the new code here.

Insert Key

Now press ESC key and type :w. This will save the .htaccess. Press ESC key and type :q. This will exit the viewer. Now create a index2.php by typing the following command:

Paste the following code. Replace serve this content between the single quote with your content provided in file based tab.

PHP Command
Now press ESC key and type :w. This will save the .htaccess. Press ESC key and type :q. This will exit the viewer.

Now click on I am serving this button. Wait for a second and your domain will be verified.

Serving on PHPStack

Another Method:

Some might find the above procedure too long. You can also accomplish the above result in two lines.

Once you are in your public_html directory, create a directory by typing the following command:

Now, serve the URL with the content. Type the following command and replace <file_name> with the name you are provided with.

Now copy and paste the content to be served in it by pressing insert key from your keyboard and then pasting it in. Now press ESC key and type :wq to save and exit the viewer. First check the URL yourself to make sure that URL is serving the content properly.

Your SSL certificate has been created. Install it on Cloudways.

Test Install

Step 3: Install SSL Certificate on Cloudways:

Go to the SSL Certificate on Cloudways Console and click on Install Certificate:

Install SSL

Copy the Signed Certificate and paste it in Certificate Code. Copy the Intermediate Code and paste it in CA Chain and click on the Submit button.

Install Certificate

Step 4: Testing HTTPS

Now copy your application URL and add https:// before the URL. Open it in the browser:

Testing HTTPS

If you see HTTPS working properly, you have successfully configured the SSL certificate on your site. You can also click Test My Install to check whether SSL is properly integrated. Remember this certificate is only valid for 30 days. In order to force your site to always use HTTPS, add the following line in your .htaccess file:

I hope you found this guide to install SSL certificates on your custom PHP sites helpful. If you’ve got any questions or concerns, leave a comment below and I’ll get back to you. Launch your free trial of the Cloudways PHP Managed Hosting Platform to test the amazingly fast cloud hosting experience.

Create PHP websites without the worry of server management.

Deploy your PHP app on optimized PHP hosting servers.

About Ahmed Khan

Ahmed was a PHP community expert at Cloudways - A Managed PHP Hosting Cloud Platform. He is a software engineer with extensive knowledge in PHP and SEO. He loves watching Game of Thrones is his free time. Follow Ahmed on Twitter to stay updated with his works. You can email him at ahmed.khan@cloudways.com

Stay Connected:

You Might Also Like...