WordPress on Google Cloud Platform

Wordpress on Google Cloud Platform

I am going over hosting WordPress on Google Cloud Platform in this article. This is a step by step guide on how to set up and host a WordPress website using a fresh installation.

Step 1: Fresh VM

console.cloud.google.com
(Note: Be sure and install gcloud https://cloud.google.com/sdk/docs/downloads-apt-get)
Setup Project and VM (micro)
sudo apt update && sudo apt upgrade

Step 2: Install Swap

$ sudo fallocate -l 1G /swapfile
$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ sudo nano /etc/fstab
-- /swapfile swap swap defaults 0 0

Step 3: Install LAMP Stack (Linux, Apache, MySQL, and PHP)

$ sudo apt install tasksel
$ sudo tasksel install lamp-server
$ sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc

Step 4: Configure Domain

Setup DNS
-Go to your web domain registrar and create A record pointing to your new server
Configure Apache conf for website
<Directory /var/www/example.com>
Require all granted
</Directory>
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com
</VirtualHost>

$ mkdir -p /var/www/example.com

$ a2dissite 000-default.conf
$ a2ensite example.com.conf
$ systemctl reload apache2

Step 5: Prep Database and PHP

Create database
$ mysql -u root
> CREATE DATABASE wordpress;
> GRANT ALL ON wordpress.* TO 'wordpressuser' IDENTIFIED BY 'Secure1234!';
> quit
$ mysql_secure_installation

Edit /etc/php/7.2/apache2/php.ini
max_input_time = 30
upload_max_filesize = 20M
post_max_size = 21M

Wordpress on Google Cloud Platform

Step 6: Install WordPress on Google Cloud Platform

https://codex.wordpress.org/Installing_WordPress
$ wget https://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz

Step 7: Tune the new install and MPM_Prefork.conf


https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl

Step 8: Troubleshooting

One important addition to setting up WordPress. Permission errors with the WordPress installation can be fixed with the following command.

$ chown -R www-data:www-data /var/www/html/*

This adds permissions for the Apache server user to use the files in the webpage directory.

Video Walkthrough

In Conclusion, you now have WordPress on Google Cloud Platform. Enjoy the experience and let me know in the comments if you have any issues.

Leave any Questions and Comments below and I will get back to you. I regularly publish on YouTube and christitus.com so if you’d like to see more videos and articles click the subscribe button in the top right.

3 Comments

  1. ayandebnath

    Hello, when I created my GC instance, I already have this entry in fstab –
    /.c2d-swap-file none swap sw 0 0

    Do I need to do something extra?

    1. Chris Titus

      I would verify that it seeing the swap partition and is using it by running an htop
      If it isn’t registering the swap, you probably need to run a swapon

  2. Arsen

    on other computers it will not open?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: