DEV Community

Cover image for Deploy a Wordpress to Google Cloud for free
martin2844
martin2844

Posted on

Deploy a Wordpress to Google Cloud for free

So, after reading for a bit, there arent any really good free hosting solutions for wordpress sites. Really, all of them have a tradeoff. Either no SSL, or no custom domain etc.

Well, there is an answer to this. Since there are free VM instances available, you can launch a wordpress site via an instance. You can use whichever you like. Both google and amazon provide free tier VM machines for a year. And they are both really good.

Where to get a VM

Now, in both AWS and Google Compute you can launch a Virtual Machine (VM) with a custom image already set for wordpress, but its more expensive than a normal ubuntu image, and of course you wont be able to customize it as much.

So I'll guide you through setting your own wordpress site from the terminal of your VM, that is to say your SSH connection.

Now, I wont go into much detail about what does what, but if you follow it along it will go well. It helps knowing a bit of bash commands.

Creating the VM Instance

  1. First make a google cloud account, they'll ask for your credit card and they'll charge you a dollar, but thats it. Its just to prevent spam.
  2. Go to google compute and launch new instance - The size depends on various factors, but basically it will depend on the size of your website - traffic, amount of storage needed, processing power. etc.

Also allow HTTPS and HTTP traffic.

Once you decided on your instance size, I chose Micro, wait for your instance to finish creating itself.

Now it might be the time to clarify that you might get a money limit with your free usage, this should be good for the micro instance for about a year

  1. Press SSH, this I love about google cloud computing. Its not necessary to donwload your keys and putty if your on windows in order to ssh to the VM.
    (Image of SSH button)
    html
    Once it finishes connecting it will be like so:
    html

  2. After that, let the fun begin! In order to make a wordpress site we need to set our VM with the correct packages.

First update and upgrade the VM's apt.

    sudo apt update -y
    sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Then we need to set up apache! or the famous LAMP

Linux, Apache, MySQL and PHP

Setting up the LAMP Stack

    sudo apt install apache2

Enter fullscreen mode Exit fullscreen mode

Once its done, apache2 should be running, you can check it by doing the following:

    sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

It should say, its active and running.

if its not running do the following:

    sudo systemctl start apache2
Enter fullscreen mode Exit fullscreen mode

You should be able to check it by copying the VM IP adress and pasting it to your browser's nav bar, it should show you the default LAMP page.

*Make sure you are not forcing HTTPS on the IP adress. That is not yet set, so it wont work if you do that. *

This is your IP adress:
html
This is the stock LAMP page:
html

In order to guarantee that the service will be always execute the following command:

    sudo systemctl enable apache2
Enter fullscreen mode Exit fullscreen mode

If the VM is restarted, it should start apache2 right away.

Installing the Wordpress Database (MariaDb)

Now we are going to install the DB. We are going with MARIADB this time.

    sudo apt install mariadb-server mariadb-client
Enter fullscreen mode Exit fullscreen mode

We are installing both client and server, the mariadb-server is to setup our DB server, and the client we needed to be able to connect to it.

Now start the DB server

    sudo systemctl start mariadb
Enter fullscreen mode Exit fullscreen mode

Again, check it with status

    sudo systemctl status mariadb
Enter fullscreen mode Exit fullscreen mode

Should be up and running.

Configuring the DB

Go for the following command:

    sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

Hit enter for the prompt that says enter current password for root, since we havent set any yet.

Type Y, for the Set root password prompt!

Set a password and remember it, its important.

And select Y for remove anonymous user, also Y for disallow root login remotely, and Y again for test DB removal, and privilege reload.

Reload mariadb now:

    sudo systemctl restart mariadb
Enter fullscreen mode Exit fullscreen mode

Installing PHP Dependencies

Now we need to install a couple of PHP things, this is needed for wordpress which is, basically, PHP.

    sudo apt install php php-mysql php-gd php-cli php-common
Enter fullscreen mode Exit fullscreen mode

Downloading the wordpress files

We need to have wget and unzip first. Wget most probably will be there allready but not unzip. So just do the following:

    sudo apt install wget unzip
Enter fullscreen mode Exit fullscreen mode

Once its done, we will donwload wordpress:

    sudo wget https://wordpress.org/latest.zip
Enter fullscreen mode Exit fullscreen mode

This will download the latest version of wordpress. But its a zip, so lets go ahead and unzip it.

    sudo unzip latest.zip
Enter fullscreen mode Exit fullscreen mode

It will generate a wordpress directory, check it by using the "ls" command.

Now Transfer wordpress to the correct folder!

Copy the whole directory to the Apache2 folder.

    sudo cp -r wordpress/* /var/www/html
Enter fullscreen mode Exit fullscreen mode

That will transfer all the files to the Apache root folder.
Now cd to that folder:

    cd /var/www/html
    ls
Enter fullscreen mode Exit fullscreen mode

You should have all the files there. And now we have to change the owner properties of the files to let apache use them:

    sudo chwon www-data:www-data -R /var/www/html
Enter fullscreen mode Exit fullscreen mode

Now, to access the website we need to remove the default page, inside /var/www/html, remove the index.html which was the default apache page

    sudo rm -rf index.html
Enter fullscreen mode Exit fullscreen mode

Now go to your IP adress again, and you should get the wordpress installation site! Well done!

Setting up Wordpress

But were not there yet, just a bit more. So click your language, click on lets go! and we'll put in the info needed to make wordpress work

So you'll need to set the DB for wordpress.

Back to the SSH terminal -

    sudo mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

It will ask your root password which I told you to remember, remember?

Enter it, and you should be inside MariaDB.

So we now will create a DB for wordpress:

    create database wpdb;
Enter fullscreen mode Exit fullscreen mode

wpdb can be anything you wish and desire, it can be wordpressdb, wordpress, database....

So now we need to create a user,

    create user "user"@"%" identified by "password";
Enter fullscreen mode Exit fullscreen mode

You guessed it, replace user and password for whichever user and password you choose to use.

Now provide access for the new user to the DB

    grant all privileges on wpdb.* to "user"@"%";
Enter fullscreen mode Exit fullscreen mode

now exit by:

    exit
Enter fullscreen mode Exit fullscreen mode

Now, provide the information to the wordpress page which was asking for it.

Database name: wpdb
username: user
password: password
Database Host: localhost
table prefix: wp_

Click Submit and you should be successful.

You might get a message that it was not able to write it. And it will give you a php code to put in manually. To do this, copy the code, and back in your terminal, you should still be in the Apache folder, run the following:

    sudo nano wp-config.php
Enter fullscreen mode Exit fullscreen mode

Once inside, delete everything and paste the code you copied. Then just CTRL-X to exit, and Y to save.

Thats it.

Go back to the page, and click to continue, and run the installation. You should be on a normal wordpress installation.

Site title: Whatever
username: your user to access the wordpress admin area
password: your desired password.

email: an email to recover password and get notifications.

After that, login into wordpress and voilá your done.

We are just missing a custom domain, and SSL configuration. But thats for another post.

Thank you for reading!

Top comments (0)