This post is to establish the proper way to establish WordPress on a GCP Instance in a secure manner in as little of time as possible for the lowest cost available on a SMALL instance. It is not set up for elasticity nor high availability. This is a setup for one single server with the database on a Cloud SQL instance.
Server Preparation
1. On GCP, spawn a Debian Server of a small size. How to do that is beyond the scope of this write-up as you are expected to already know how to do this.
2. Assign a static IP address. The IP Address assigned at creation is not a permanent IP Address and you must implicitly assign it in GCP. Once again, how to do this is beyond the scope of this write up.
3. Now fix your DNS settings for the chosen domain name to point to the assigned IP Address.
4. Access your server via SSH and run the following commands.
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install php-common
sudo apt-get install libapache2-mod-php
sudo apt-get install php-gd
sudo apt-get install php-curl
sudo apt-get install php-zip
sudo apt-get install php-intl
sudo apt-get install php-xml
sudo apt-get install php-mbstring
sudo apt-get install php-imagick
sudo apt-get install php-mysql
sudo apt-get install mariadb-client
5. Replace the file at this location /etc/apache2/sites-enabled/000-default.conf these contents.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
6. Next run the following command to enable url rewrite.
sudo a2enmod rewrite
7. Now restart the apache server and see that it runs and gives you the default page.
sudo systemctl restart apache2
8. Create the SSL Certificate using Certbot. Follow the instructions found on this website: https://certbot.eff.org/. For ease, here are the instructions:
$ sudo apt-get install snapd
$ sudo snap install --classic certbot
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
$ sudo certbot --apache
9. With the SSL Cert now working on the default apache website, now you can install wordpress.
Install WordPress
Download wordpress to your home directory and unzip it.
cd ~
wget https://wordpress.org/latest.zip
sudo apt-get install unzip
sudo unzip latest.zip
sudo rm /var/www/html/index.html
sudo cp -Rf wordpress/* /var/www/html/
You should be able to access website from the URL at this point and follow the wizard for the rest of the installation.
When complete, make certain you tighten the permissions as follows:
sudo chown www-data:www-data /var/www/html/*
sudo chmod -Rf 700 /var/www/html/*