Over the last couple of months, my wife Katie and I put together and launched her new site, Katie Crafts. It’s a blog built on WordPress where she posts all manner of things related to DIY (crafting, sewing, recipes, etc); some of the more popular posts she ends up selling on Etsy. If you or anyone you know is in to that sort of thing, I definitely recommend checking it out.
As a developer, I was really excited because this gave me a fantastic chance to implement and try all sorts of things I wouldn’t normally do on a client’s website. As long as the site worked and was relatively fast she didn’t care what sort of wizardry I worked on it!
First stop, finding a home
I’ve mentioned it before, and I’ll no doubt say it again — I really, really love Digital Ocean. Considering how cheap it is, I immediately spun up a $5 droplet and tried my luck with a LEMP stack, something I don’t have much experience with.
I opted to build out my own server image rather than using one of their prebuilt packages. After all, I wanted to use this as a learning tool. I’ll be the first the admit that it didn’t work right away but after some trial and error (read: a whole night), it worked beautifully. WordPress is fast, responsive and I have full control over the entire backbone of it all.
I’ll definitely make a post on how to spin up your own LEMP stack in the future, so keep an eye out for it!
Congratulations, the server is working — now what?
Well, now we need to actually get the files from our computer up to our new, working server. Should we FTP them? Probably not.
Manually FTPing things is a recipe for disaster. While a lot of the newer FTP applications support syncing (love you Transmit) it still leaves a lot of room for error. What if you somehow miss a file or dependency or need to clear a cache directory with hundreds of files?
I decided on Capistro for deployments so I could write my own custom tasks. This allows me to easily push up all the required files from my master git branch to a directory structure that easily allows rollbacks in the event that something horrible happens. I even wrote custom tasks to fix permissions and clear the cache directories on deployment.
In a nutshell, here’s what happens when I do a cap deploy to my droplet:
- The data from the git branch is pushed out to the droplet
- All folder permissions are fixed (making sure that cache directories writable by the site, etc)
- All cache directories are cleared so the changes are visible immediately
This process really makes things much, much easier which means less stress for me. Win win!
All aboard the optimization express!
Now that the server is working and everything is stable, I spent some time fine tuning everything. Using various resources on the web I went through and did the following (in no particular order):
- Disabled hotlinking of the images to prevent wasted bandwidth
- Made sure that www/no-www pointed to the same place and that the non-primary was using a 301 redirect to prevent duplicate content
- Enabled gzip compression to speed up page requests
- Enabled swap on the VPS
These steps made sure that the site was fast, responsive and a little more future proof than when I started. I’m incredibly happy with the way things turned out and I’m really looking forward to further optimizing things on the server as she gets more and more followers.
If you have any suggestions on other ways I can approve or tips and tricks that you like to use on your own servers, let me know in the comments!
Over the weekend, I was running in to an issue on one of my Digital Ocean droplets that was causing the MySQL service to stop running. After some back and forth with support we boiled it down to a singular…
To help make things a bit speedier on your site, you should try enabling gzip compression. At a really high level it temporarily replaces similar strings in the files being sent out to compress the file size. Google has a…
When setting up a domain on a web server, you want to make sure that you prevent duplicate content on your non-primary domain. As a personal preference, I usually strip the www and use the no-www as my primary (in…