Migrate WordPress – Amazon AWS EC2 to Google Compute Engine

Steps to migrate Wordpress from Amazon EC2 to google compute engine using Bitnami image. Linux server VM with 3.75 GB memory. WP Super Cache settings.

Technology that we are going to use

  1. Google Compute Engine VM – This is same as Amazon AWS EC2
  2. Google Domains – For website domain and DNS. You can use any domain registrar like Godaddy or anyone that your domain is already registered with.
  3. WP Super Cache Plugin Settings

Step by step process to move from Amazon AWS to Google Compute Engine

  1. WordPress back Up
    1. Use ‘WP All in One Migration’ plugin to get a back for your wordpress.
    2. Save the back up as a file on local machine. Please note that if your back up file is larger than 512 MB, the free version will not support it.

      In that case, you can choose to exclude the wp-content folder all-together. This will certainly bring down the total file size by at-least 70%. WP-Content folder can be copied separately to new server easily with using this plugin.
  2. Install Bitnami Image on Google Compute Engine VM
    1. Create account on Google CLoud console or log in to your account, if you already have one.
    2. Create a project, add billing and then use Bitnami WordPress Image to launch the installer.
    3. After couple of minutes, you should have your wordpress blog ready to go. Google assigns it a default External IP address (They call it ‘Ephemeral IP’).
  3. Connect to Google VM using Putty or WinSCP client
    1. Create Private Key File using PuttyGen.
    2. Add this private key to google’s VM instance.
    3. Then, use this private key in Winscp to connect to VM instance.
  4. Things to do after bitnami wordpress install
    1. Remove bitnami banner: Get into machine SSH (Easiest way is to use Google Clound console login)
      Run this command:
      sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1
    2. Change website domain name using this help
      https://docs.bitnami.com/google/apps/wordpress/#how-to-change-the-wordpress-domain-name
    3. To change the wp-config file
      Run this command to give permissions to user bitnami:
      sudo chown bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-config.php
      Log in with user ‘bitnami’ using WinSCP, then open file and make changes to local file. Save.
  5. Set Up WP Super Cache
    1. Add mod_rewrite rules
      Use this link :https://docs.bitnami.com/google/apps/wordpress/#using-modrewrite-caching
    2. Set up ‘Browser Caching’
      Open /opt/bitnami/apps/wordpress/conf/htaccess.conf file.
      Add the following rules at the end of file.
      # BEGIN EXPIRES

      ExpiresActive On
      ExpiresDefault "access plus 10 days"
      ExpiresByType text/css "access plus 1 week"
      ExpiresByType text/plain "access plus 1 month"
      ExpiresByType image/svg+xml "access 1 month"
      ExpiresByType image/gif "access plus 1 month"
      ExpiresByType image/png "access plus 1 month"
      ExpiresByType image/jpeg "access plus 1 month"
      ExpiresByType application/x-javascript "access plus 1 month"
      ExpiresByType application/javascript "access plus 1 week"
      ExpiresByType application/x-icon "access plus 1 year"

      # END EXPIRES

    3. Then, use this private key in Winscp to connect to VM instance.
  6. Editing or adding files to wp-content or theme folder.
    For security reasons, these folders have the daemon:daemon permissions. What you can do is connect via ssh and then execute these commands.
    sudo chown bitnami:daemon -R /opt/bitnami/apps/wordpress/htdocs/wp-content/themes
    Add the files you require, and then make sure you revert it back
    sudo chown daemon:daemon -R /opt/bitnami/apps/wordpress/htdocs/wp-content/themes
  7. for Final permissions to help all plugins work correctly, execute these commands:

    sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/cache
    sudo find /opt/bitnami/apps/wordpress/htdocs/wp-content/cache -type f -exec chmod 664 {} \;
    sudo find /opt/bitnami/apps/wordpress/htdocs/wp-content/cache -type d -exec chmod 775 {} \;
    sudo chown bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    sudo chmod g+w /opt/bitnami/apps/wordpress/htdocs/wp-config.php

    Source: https://docs.bitnami.com/google/apps/wordpress/ -> FAQ section

  8. To enable Varnish cache, use the steps mentioned here:
    https://docs.bitnami.com/google/components/varnish/

WordPress with FREE HTTPS SSL security certificate – Good for Google SEO

Thanks to this post here that has helped me write up these steps. They are basically same. I have just added a few more details, to explain a little more wherever possible.

  1. Install plugin ‘WP Encrypt’

    As the instructions are quite well documented follow these instructions here.

    WP Encrypt has settings to ‘Automatically update the certificate’ before it expires.
    Do check that option as the validity is just 90 days and you do not want to manually do it every time.

    Return here after generating your certificates.

    Once you have generated your certificates, follow the next steps below.

  2. Give appropriate permissions AGAIN. Remember, you would have already ran these commands before you generated certificates. You need to run them again now.
    sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/letsencrypt
    sudo find /opt/bitnami/apps/wordpress/letsencrypt -type d -exec chmod 0775 {} \;
    sudo find /opt/bitnami/apps/wordpress/letsencrypt -type f -exec chmod 0664 {} \;
  3. Rename existing files to avoid conflict.
    sudo mv /opt/bitnami/apache2/conf/server.crt /opt/bitnami/apache2/conf/server.crt.bak
    sudo mv /opt/bitnami/apache2/conf/server.key /opt/bitnami/apache2/conf/server.key.bak
  4. Link your SSL certificate and certificate key file to the correct locations. Remember to replace the DOMAIN placeholder with your actual domain name.
    sudo ln -s /opt/bitnami/apps/wordpress/letsencrypt/live/YOUR_DOMAIN_NAME/fullchain.pem /opt/bitnami/apache2/conf/server.crt
    sudo ln -s /opt/bitnami/apps/wordpress/letsencrypt/live/YOUR_DOMAIN_NAME/private.pem /opt/bitnami/apache2/conf/server.key
  5. Once you have copied all the server certificate files, you may make them readable by the root user only with the following commands:
    sudo chown root:root /opt/bitnami/apache2/conf/server*
    sudo chmod 600 /opt/bitnami/apache2/conf/server*
  6. Open port 443 in the server firewall.
  7. Force https redirection. (https://docs.bitnami.com/aws/apps/wordpress/#how-to-force-https-redirection)
    Add the following to the top of the /opt/bitnami/apps/wordpress/conf/httpd-prefix.conf file:
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
  8. Restart the Apache server
    sudo /opt/bitnami/ctlscript.sh restart apache
    Once re-started with no error, go to your wordpress blog and you should see all the URL’s automatically changed to to include https. Try to explicitly go to a URL with http://YOUR_DOMAIN and it should be redirected to https version.
Disqus Comments Loading...