Installing a free Let’s Encrypt SSL certificate on Server Pilot

I recently needed to create a live WooCommerce site for testing the API. But I needed SSL. And up until now, a proper SSL certificate cost money. Money I didn’t want to spend for a test site. But Let’s Encrypt recently entered public beta. And you know what’s cool about Let’s Encrypt? It’s a new certificate authority that is completely free – for anybody.

I couldn’t get the automated setup to run on my Server Pilot-powered Digital Ocean droplet (get $25 free credit with that link and I get $10 – win/win), so I had to do it manually. The good news is that it’s actually pretty easy. I’ll take you through it.

 

Screen Shot 2016-01-07 at 4.36.20 PM

Start by SSHing into your server. You may need to first ssh with the serverpilot user and then update the password for the root user, as at least in my case I needed to use root to create the certificate. So if you have any permission issues, try the root user.

Let’s say your server’s IP is 128.199.1.1.

ssh serverpilot@128.199.1.1

You then need to download Let’s Encrypt (instructions here updated in September 2016 based on this comment).

wget https://dl.eff.org/certbot-auto

If you’re using the serverpilot user, Let’s Encrypt will now be in the serverpilot user’s directory – /srv/users/serverpilot/.

You now need to stop nginx running.

sudo service nginx-sp stop

Time to create your free certificate!

./certbot-auto certonly

It’ll update itself and then ask you for the domain name(s).

 

Screen Shot 2016-01-07 at 4.48.23 PM

You could enter multiple domains, like if you wanted www and non-www certificates for your site, you’d enter: mysite.com, www.mysite.com.

It may also ask you some other info.

A moment later and you’ll be the proud owner of some new SSL certificates! Time to start nginx again:

sudo service nginx-sp start

You now need to modify your nginx configuration to use these certificates. First go to the folder that contains them.

cd /etc/nginx-sp/vhosts.d/

You then need to create a new file for it. If your app name is mysite for example, and when running ls in that folder you see a file called mysite.conf, you’ll want to type the following:

nano mysite.ssl.conf

Add the following to that file, changing mysite to your app name.

Save it, with ctrl + o and then exit with ctrl + x.

Restart nginx:

sudo service nginx-sp restart

And you’re done! Congratulations. You just beat the system. Sort of.

The one negative is that the SSL certificates expire every 3 months. I believe you’ll just need to follow the first couple steps and create a new SSL certificate with Let’s Encrypt. That should be all though, and I’m sure there will be auto-installation soon so it’s completely automated. You could also write a script and cron job to automate renewal. If you do, please let me know and I’ll share it here.

Renewing

Updated 21/03/2016 – Well, the original certificates that inspired this post were about to expire, and Let’s Encrypt kept emailing me to warn me, so I thought I better figure out how to renew them. Good news. It’s pretty easy and will take you just a moment.

Start by SSHing into your server. Go to where we installed Let’s Encrypt before, likely possibly by doing the following:

cd ~/srv/users/serverpilot/

You now need to stop nginx running.

sudo service nginx-sp stop

Then run through the certificate creation again. This will open up the Let’s Encrypt setup – just enter your domains like you did before.

./certbot-auto certonly

Once that’s done, your certificates are valid for another 3 months.

But wait! You need to restart nginx or nothing will work.

sudo service nginx-sp start

I still haven’t bothered to try write a script to auto renew it. There should be some floating around by now, so if you’re desperate / have a lot certificates, search around and you should find something.

Getting Started with WordPress Hooks – Actions & Filters

When I first started developing WordPress stuff years ago, I had no idea what ‘hooks’, ‘actions’ or ‘filters’ were. I saw them written about, used, discussed and explained countless times but I was afraid to try understand them. They scared me.

But I grew up. Like all good developers do, I eventually got over my fears and dedicated some time to really get my head around them. So I read a lot of guides, like this one, this one, and especially this one – it all started to make sense!

Continue reading

A Quick Look at the WordPress uninstall.php File

Creating a plugin for WordPress is a fun experience. You get to build something that eventually gets used by countless people, makes their lives easier, perhaps makes you a profit and in general just makes the world a better place.

But don’t be the jerk that overstays their welcome. When your plugin creates ‘data’ on a user’s site, like a post type, page or setting, you have a responsibility to remove that data when a user decides to delete your plugin. If you neglect to clean up after yourself, you’re imposing a lifetime of DB clutter on your (ex-)user and making the world a worse place.

Continue reading

Adding a Section to a Settings Tab in WooCommerce

I published this over in the WooCommerce Developer Docs the other day. Please keep it in mind if you’re developing an extension for WooCommerce – along with the Create a WooCommerce Plugin guide.

When you’re adding building an extension for WooCommerce that requires settings of some kind, it’s important to ask yourself: Where do they belong?

If your extension just has a couple of simple settings, do you really need to create a new tab specifically for it? Most likely the answer is no.

Continue reading

Open ‘Calculate Shipping’ Box on WooCommerce Cart Page Load

I’ve seen this request a couple times while helping out WooCommerce customers so I thought I’d share a quick CSS snippet that will do just that.

Add the following to your custom.css file or with a plugin like Simple Custom CSS:

.shipping-calculator-form {
    display: block !important;
}

This will make the Calculate Shipping box automatically open when the Cart page is loaded.

Add PDF to WooCommerce Order Email

Quick little snippet that will let you add a static PDF file (or in fact, any kind of file) to the WooCommerce Order Emails.

Just add the following code to the ‘custom functions’ area of your functions.php file:

Delete the php first line if you are having errors come up after saving the file.

Now simply edit the $your_pdf_path variable to be wherever your PDF (or other file) is located!

Too easy, right?

Reference: http://wordpress.org/support/topic/pdf-attach-terms-and-conditions-to-email

Order Products by ‘On Sale’ in WooCommerce

Have you ever wanted to place your on sale items at the top of your product listings? You can pretty easily do it in a couple of ways.

Screen Shot 2014-07-14 at 3.51.59 pm

If you would like to add a ‘On Sale’ option to the ‘orderby’ menu, so users can choose to order it themselves, add the following code to the ‘custom functions’ area of your functions.php file:

However, if you would like to make it the default order, add this:

I hope that helps you out!