Categories
Google Cloud Wordpress

Setting up WordPress with Bitnami on Google Cloud

I build my first WordPress “blog” in 2010 after being told by a random internet marketer that I could build a blog, create a bunch of content, do some SEO magic, and watch the affiliate income come in. I paid $10 a month to HostGator and built a handful of WordPress blogs over the next few years. The fact that I barely created any content – and SEO, what’s that? – should have been a sign, but that’s another story. Almost 10 years later, after learning A LOT more about this coding thing, I finally dropped HostGator in favor of using cheaper, more scalable, and possibly faster hosting options – in my case, Google Cloud.

Set up a Google Cloud Account

First thing you have to do is set up a Google Cloud account.

  1. Go to cloud.google.com
  2. Sign in to your google account
  3. Accept the terms and conditions
  4. And you are in

But, you aren’t ready to get started yet. You need to set up billing. This stuff may be cheap, but it isn’t free. Fortunately, if this is your first time, there is a $300 credit waiting for you – a free trial for your first $300 of hosting, or 1 year, depending on which comes first.

If you spend more than $300 on hosting, than you probably shouldn’t have been on the $10 HostGator plan anyways.

Open the hamburger menu on the left side, click on billing, follow the steps, and you should be all set up.

After setting up your billing, click the header to go back to the main dashboard.

Set up your domain

If you don’t already have a domain, this is the time where you should make sure you have a place you are going to direct your WordPress installation. This isn’t 100% necessary, but if you are doing this for more than fun, it’s probably a good idea

Pick your poison when it comes to purchasing a domain. I personally prefer Google Domains, just to keep all my stuff at the same place, but you can choose other options, like GoDaddy, Namecheap, or others.

Install WordPress on Google Cloud

You are going to set your WordPress installation up on a VM instance on your Google Cloud account. If you don’t know what that means, that’s okay. Fortunately, there are preconfigured templates that make this super easy.

First, you need to create a project.

On the upper left, click on Select a project.

Click on New Project

If you don’t like the default name Google assigns you, come up with a name of your own.

Click CREATE and it will create the project and navigate back to the dashboard.

Click on the hamburger icon on the upper left. In the side menu, click on the link to the Marketplace.

Once you navigate to the Marketplace, search for “wordpress nginx ssl.”

Select the Bitnami installation of WordPress, and on the next screen, select LAUNCH.

Further down on the screen you will see a section on pricing. As you can see, at the time of writing this Google says it will cost you $13.61/month to run your blog on Google Cloud. There will be a few settings that you will change on a later screen to reduce that.

After clicking on LAUNCH you will be redirected to the setup page for your new blog.

Name your deployment, change your zone (if desired), and switch the machine type from small to micro. As you can see, the cost has gone down to an estimated $5.13/month.

After setting things up, scroll down to the bottom, accept the terms of service, click Deploy, and sit back while your blog gets set up for you.

At this point, you can visit your WordPress blog with the IP address provided, and log into the dashboard with the username and password.

This would also be a good time to log in and set up your own username and password via the WordPress dashboard. It can be a pain trying to find the Admin user and Admin password after you leave this screen.

Reserve your IP address

This isn’t completely necessary, but definitely a good idea. Reserving your IP address makes it so your IP address won’t randomly change.

Click on the hamburger icon to open the side menu, and scroll down to Networking. Click External IP addresses.

Switch your IP address from Ephemeral to Static, follow the steps, and your IP address is reserved.

Something to note about reserved IP addresses – If you delete your VM instance, you may still be charged for the IP address. It’s a good idea to release the static address when you are done with it.

Point your domain at your IP Address

Now that you have your IP address reserved, head over to your domains. The following examples are done with Google Domains. Your mileage may vary.

On the side menu, select DNS

Scroll down to Custom resource records, and either create an A record, or change your A record, to the IP address of your new blog.

Also, if you haven’t set up www, do that as well by putting www in the box on the left, switching the dropdown to cname and putting your domain.

Once you have changed the A record, it may take awhile for the site to populate on your domain name.

Setting up SSL

It’s definitely a good idea to set up SSL for your site. Not only does Google like sites that are https for SEO, but it also keeps users from getting a “this site is not secure” message when they arrive at your site.

Head back to your VM instance in the Google Cloud Console (hamburger menu => Compute Engine => VM instances), and select “SSH”

This opens up a terminal window connected to your WordPress installation. You will see something like this:

Bitnami’s documentation on setting up SSL is terrible. I’ve spent hours trying to get SSL working by following their documentation, and was only able to get SSL to work when I stumbled upon this line of code after scouring Google:

sudo /opt/bitnami/letsencrypt/scripts/generate-certificate.sh -m EMAIL@EMAIL.COM -d DOMAIN -d www.DOMAIN

Turns out there’s a script that Bitnami has that uses letsencrypt to install a free SSL certificate for you. Run the script, replacing the email and domain with your email and domain, and when it asks you if you want to automatically schedule renewals, key Yes, so you don’t have to redo this step every 3 months.

Set up site domain name

When you go into the settings on your WordPress dashboard, you want to see the HTTPS address instead of the HTTP address. While you are already in the terminal, you might as well make this change as well

Run the code:

sudo vi /opt/bitnami/apps/wordpress/htdocs/wp-config.php

This opens up the wp-config.php file in the editor. Scroll down until you see define('WP_SITEURL'...

If it says 'http://' change it to 'https://'. If you can’t change it, press i, which will allow you to insert. Once you are done making changes, press ESC to escape insert mode. To save and quit, type :wq, and press enter. If you don’t use sudo you might not be able to save. For more information on what you can do in the editor, see VI Text Editor with Commands

Force HTTPS Redirect

One last thing to do while you are in the Cloud Shell is to force HTTPS redirect. That way, if somebody goes to http://yoursite.com, they will be redirected to https://yoursite.com. This is a pretty big deal for SEO, because, as we said earlier, Google, and other search engines, don’t like http.

In the Shell terminal, enter

sudo vi /opt/bitnami/nginx/conf/bitnami/bitnami.conf

This opens up the configuration file for bitnami. Remember, i to insert.

You can either switch localhost out for your domain (normal and www) or leave it, and add the 301 line. :wq to save and quit.

Removing the Bitnami Banner

One last thing you should probably do is remove the Bitnami banner from your site. Run this line to get rid of the banner from your site (it will still show up in the admin dashboard)

sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1

Restart NGINX

In order for your changes to take effect, you need to restart NGINX. Bitnami has a script that handles all of it for you. Enter:

sudo /opt/bitnami/ctlscript.sh restart

Once you restart your server, you should be able to log into your new WordPress Blog and start writing.

Logging in

Bitnami creates your site with the username of User and a random password. If you didn’t log in and add a new User before, you will want to do it now. To find your password, click in to the VM instance for your WordPress installation. Scroll down. Under Custom metadata you will see bitnami-base-password. That is the password you can use to log in to WordPress. Once you are in, set up your own username and password.

Conclusion

WordPress isn’t my first choice for web development, but for other people, it’s their bread and butter. Setting up your WordPress installation on Google Cloud is a great alternative to using other paid hosting options.