Self-Hosting WordPress

, 8 min, 1401 words

Tags: web-dev

UPDATE (2 Feb 2021): I'm no longer running this site from wordpress, but these notes were super helpful to me – perhaps they can be for others as well.

As I may have mentioned before, I'm self-hosting WordPress on a virtual private server (droplet) from DigitalOcean. Given how much time and effort have gone into getting this up and running over the last month, I wanted to share how I did it and where I stumbled. In the minimal-impact case, it'll make it easier for myself next time. In the best case, maybe someone else will find it useful too.

As a fair warning, this site is actually my second attempt at self-hosting WordPress. My first was a standalone website with a URL that was way too long: questionsquestionseverywhere.com. That's a long enough URL that I started abbreviating it and referring simply to QQE, a bad sign. And I messed up enough on that first attempt that it's safe to say this is my first success at self-hosting. In the below discussion, I'll talk a little about the roadblocks I encountered on both installation attempts.

Finding a guide

I floundered around a bunch when I first tried to install WordPress. First I tried to follow WordPress' own instructions. Those didn't totally work for me, so I continued searching around. By the end of it all, my favorite guide was from my hosting service, which made it specific to my operating system (Ubuntu 14.04) and general setup. I also benefited tremendously from the wordpress.org support forums, where I asked those seemingly intractable questions and got help with self-hosting WordPress on my own server.

Before starting

I'm not going to discuss what I had to do to set up virtual hosts in apache, as it's not relevant for this site, though it was important to getting QQE up and running.

Based on the WordPress five-minute installation instructions, I needed to do some setup before getting started in earnest. See, self-hosting WordPress has a few requirements, and those required me to make friends with apt-get and play with some installation dependencies.

The above requirements also meant I had to get myself HTTPS support before I could start installing WordPress in earnest. I used certbot with LetsEncrypt as my certificate authority, following the certbot instructions. That seemed to work, for the most part, though I still have a small issue: if you go to QQE and manually enter http instead of https, it sends you to the directory structure of my web root. I have no idea what's going on there.

Getting started

From my favorite guide, setting up my MySQL database was a piece of cake. Everything just worked. Hooray! Note that unless you give your non-root MySQL user permission to create databases, you'll have to follow these instructions from your root user, which tripped me up briefly.

The download step is where I started to diverge from the instructions, because I elected to install php7 instead of php5. That was mostly because WordPress support for php5 is deprecated. It made for a few changes down the road in packages I installed, but for the most part was an easy switch.

Step three, configuration, was pretty straightforward in the end. I reconfigured and reinstalled enough times that I'm pretty sure I could customize wp-config.php in my sleep at this point. The instructions are spot on.

Step four: moving files. Yeah, that was alright. I got very good at using chown by the end of it all.

Step five was where things started to get tricky. The first few times I installed WordPress, all that I got at my blog's supposed URL was an "Index of /" page, and a boring and definitely-not-css-formatted list of files in the directory. I was stuck at this point for days before someone on the forums pointed out that I should change my apache configurations from DirectoryIndex index.html to also allow index.php its moment in the sun. The trick was that I had to do that in the apache config file that had been generated by certbot in the https-acquiring process above. That's the config file now in effect, rather than the pre-SSL one. After that, setting up WordPress was actually pretty straightforward.

It took me a long time to get to step six – making permalinks nice – but I eventually did. I followed slightly different instructions, but the upshot is that with some apache configuration changes, permalinks now work. Thank goodness.

Tricking out WordPress

With WordPress mostly set up, I decided it was time to install and activate some plugins. I originally decided on self-hosting WordPress from the recommendations of a bunch of travel bloggers, especially expertvagabond. From there, I knew I'd want to customize my theme, and suspected I'd want these plugins:

  • Yoast SEO helps with search engine optimization (SEO).

  • Akismet (which actually came with my initial install) helps catch comment spam.

  • Easy Social Share Buttons does exactly what you'd think: makes it easy to share your site on social media.

  • WP-Optimize helps keep a site's underlying database clean.

    • An affiliated plugin, UpdraftPlus, allows you to make backups of your database before trying to clean things up, which is generally a good plan.
  • WP Touch gives you a mobile-friendly site, which helps with SEO as well as being convenient.

To install them, I had to set FS_METHOD to 'direct' in my WordPress configuration, and then (temporarily) chown wp-content to www-data (the user running WordPress) so that WordPress can actually edit and create the relevant files. Here's some of the setup needed for the above plugins:

  • Akismet: seems to need an account. You can set one up attached you your wordpress.com (not wordpress.org??) account. If you're just getting started, you can choose to pay $0 per month, but that gives you a strictly noncommercial license, so if you're looking to make money from your blog you'll want to up that at some point down the road. There's an Upgrade button available in Settings -> Akismet Anti-Spam. Other than that, there's not much configuration needed!
  • Easy Social Share Buttons: seems to work out of the box, though I confess that I'm a total social media novice. It looks like you have to register a Facebook App Id if you want the share-on-facebook button to work, but I haven't tried that out yet.
  • UpdraftPlus: you'll want to authenticate it with some sort of backup site (I used google drive).
  • Yoast SEO has a whole setup/configuration wizard. Within that, it asks you to connect it to Google Search Console. Haven't set up Google Search Console yet? I hadn't either, but it's pretty straightforward. I authenticated by setting a DNS TXT record that Google could check. Connecting it to Yoast was also easy: Yoast provides a link that asks for permission to access Google Search Console data, which gives you an authentication code, and you enter that authentication code in the Yoast setup wizard. My setup wizard hung when I tried to sign up for the newsletter, so I recommend against doing that. If it happens to you, you can click on the numbered steps up at the top to go back, which will abort the spinning wheel of "subscribing to newsletter."

Once plugins were set up, I played around with themes a bit. I like the one I'm using now, but may change it in the future.

Wrapping up

And finally, it was time to actually start writing! Imagine my relief. Thanks for reading, and I hope this comes in handy!

Outstanding questions after this post

  • What is going on with manual http redirecting to a directory structure? Should I be concerned about security here?
  • How does Yoast know what is optimal/nonoptimal for SEO? Does Google publish a document or something?
  • Why is the WP Touch mobile theme so...bold-looking? And how do I just get my theme to manage mobile browsing? It looks like it just works, based on navigating to this blog on my phone and selecting "desktop" mode.
  • What's the deal with wordpress.com vs wordpress.org?