In this post I’ll try to show you how to easily setup and run your WordPress blog on Google Compute Engine (GCE).
What is Google Compute Engine? Following the official website:
High-Performance, Scalable VMs
Google Compute Engine delivers virtual machines running in Google’s innovative data centers and worldwide fiber network. Compute Engine’s tooling and workflow support enable scaling from single instances to global, load-balanced cloud computing.
What it means is you get virtual machines (more or less powerful – it’s up to you) running on the Google infrastructure. You can think of the VM as a “dedicated server” you can SSH to and set up as you wish. It’s just a normal server but managed by Google and using all the goodies from them.
By default the blog will be running on 1 virtual machine with Apache, a local MySQL and phpMyAdmin and this is what you’ll end up in the end of this post.
I also want this post to be a beginning of the small posts series. In the future posts I plan to show you how to use CloudSQL as a database, Cloud Storage to store your files (already found 2 ways of doing it), how to set up a domain to serve your blog and anything else I find during configuring and running my blog.
Why Google Cloud Platform?
I decided to run my blog on Google Compute Engine (part of the Google Cloud Platform). I did it because I like the way GCP works, I like their interface and the simplicity and also wanted to try something new. I’m not expecting this blog to suffer from a high traffic so the scalability is none of my concern. I also read (not confirmed by myself) that it’s cheaper than AWS.
AWS is also a great solution, but I don’t like their interface at all. It’s just my personal preference. For small projects running on AWS I always use terraform to set up all my infrastructure, even the smallest one. I didn’t have to do it on GCP (I could do it as well).
I also wanted my blog to be set up quickly – I didn’t want to spend too much time on setting it up. With GCE it was a matter of few clicks to have the blog up and running.
Why Google Compute Engine?
Before I decided to run my blog on GCE I investigated the possible solutions. I found 3.
GAE is a PaaS solution which means you get all the possible goodies from Google. Easy autoscaling, DB, cache, user authentication, security scanning, traffic splitting any many more. Sound great right? The “problem” I found and which eliminated this solution very quickly was the way you deploy. You need to have a copy of the WordPress on your machine and for example every time you want to install a plugin – you install it on your local first. Then using gcloud command line tool you push the code. It’s because GAE doesn’t allow for writes to the storage the app runs on and you need to deploy each time you change something.
Google Container Engine
GKE on the other hand is an IaaS solution. You need to configure more by yourself, but instead you get more flexibility and “freedom”. It uses Docker which I like a lot (and also plan to write posts series about it, mainly for Django development) and it’s built on the global infrastructure that runs Google’s search engine, Gmail, YouTube and other services. I found it a bit more complicated and time consuming than GCE. You need to create clusters, pods, services and what I found is that setting up the CloudSQL to work with this wasn’t something obvious.
Google Compute Engine
GCE is also an IaaS solution. I found it extremely easy to set up the blog there. There are actually pre-built VMs you can use so there’s no need to do a server-side work. It’s also super easy to SSH to you VM – you can do it within Google Console in your browser. I still prefer doing it from a terminal but sometimes it might be handy.
Setting up the blog!
Now you know why I’ve chosen Google Compute Engine it’s time to actually start setting up the platform and the blog. As you’ll see it won’t take long and it’s not a rocket science at all. Let’s get started.
The first thing you need to do is to create an account on Google Cloud Platform. Then you need to set up the Billing for your account. It’s rather straightforward and doesn’t require further explanation. When you sign up for the first time you get $300 to spend on Google Cloud Platform over the next 60 days. Free technical support is included in your trial. It’s a great opportunity to play around with the platform.
Once you’ve got the account you need to create a new project. On a blue menu bar find a dropdown list, collapse and click “Create project”
Type the project name and click”CREATE“.
You’ll be redirected to the Project’s dashboard. It’s a very handy place with helpful information. You’ll see that when your blog is up and running
Launching a VM with WordPress
To start the new VM with our blog, we’ll use Cloud Launcher. It’s a place where you can find many pre-defined VMs with different applications. In our case, we’ll be looking for “WordPress” installation.
On the top-left corner click the menu hamburger and then go to “Cloud Launcher”
Now in a search box type “WordPress” and then select the “WordPress Google Click to Deploy” as shown below
And then “Launch on Compute Engine”
Don’t worry about the price – it won’t cost so much. This assumes you’ll be running a VM instance: 1 vCPU + 3.75 GB memory (n1-standard-1).
At this point you have created a new project and selected a pre-configured WordPress installation on GCE. Now it’s time to set the VM details and run it.
Configure the new VM
For a simple blog and especially for the demo purposes selecting “Machine Type: micro” is enough. Fill all the fields as you wish, I selected a 10GB SSD disk (in future posts I’ll show you how to store uploads on Google Storage). Let’s install phpMyAdmin for an easier DB export in future (to move to CloudSQL). Press the “Deploy” button when you’re ready and wait few minutes.
By clicking the button you create a new VM with Apache, MySQL, PHP and WordPress in it. Once it’s finished you’re done! You can access the blog with the IP. You’ll be also given the IP, DB and your blog admin credentials.
Now you can access your new blog using the IP. If you want to access the admin panel just go to http://<IP>/wp-admin/
phpMyAdmin is accessible here: http://<IP>/phpmyadmin/
You can leave this page now. Don’t worry, you can always go back here by going to: Menu -> Deployment Manager
Go to Menu -> Compute Engine and you will see your new VM. You can SSH into it from here, just click on the SSH button.
A new window with a ssh session will open. You can find your blog under the: /var/www/html/
Our blog is up and running at this point, however there’s 1 more thing we need to change. The IP you use to access your blog is not static but ephemeral. This means that it will change every time you restart your VM. It’s not good if you want to point your domain to that IP.
Let’s change it to be static. Go to Menu -> Networking -> External IP addresses
You’ll see your IP and the information that it’s in use by your VM. Simply select “Static” type, put a name and click “RESERVE“. You’re done. Now the IP won’t change when you stop/start the VM.
There’s 1 thing to keep in mind – the static IP is free of charge only if you use it. If you leave it unused, you’ll be charged.
As you can see starting a WordPress blog on Google Cloud Platform was very easy and took only few minutes. It’s not a rocket science and almost anyone could do it. Keep in mind that this is a very basic setup without an external DB, proper files storage and the VM instance is not powerful. It should be fine for a small traffic. The good thing is you can always stop the VM and change its type to something stronger.