Host a WordPress website on Google cloud with Cloudflare?

Overview to host a WordPress website on Google cloud

host a WordPress website on Google cloud

Create a new instance by going to Google Cloud Platform Console.

Step 1: Log in

Log in to the Google Compute Engine console.

Step 2: Create a project

Create a new project or select an existing one. Here, you’ll get $100 for free as a trial, and after all, fill in your payment details there, such as credit/debit card info.

Step 3: Create VM Instance

Click on the hamburger menu (three horizontal lines) at the top left of the Compute Engine Console to open the side panel. Then click on Compute Engine -> VM instances under COMPUTE column.

Choose the zone for your WordPress site.

When you’re ready to create your WordPress site, choose the zone closest to you so that your website will run faster. This is where you want to be careful because Google Cloud Platform offers many options, and it’s easy to make a mistake. For example, I’m based in East Asia, and Singapore has the lowest latency of all available zones. Based on my research, if I choose a zone with higher latency because it’s closer to me geographically, it’ll reduce my website’s speed by 0.2 seconds. In short: Do not consider geographical location only when choosing a zone for your WordPress site. Instead, pay attention to the latency between zones and choose the one with the lowest latency.

Choose machine type

You should choose a machine type with at least 2 vCPUs, 8 GB of memory, and 1 local SSD. Because we share memory among all cores on a single CPU, the amount of memory available for each core will be 4 GB (8 GB Memory / 2 vCPUs). It is enough to run WordPress and MySQL comfortably. The size of the local SSD is essential. If you choose an instance of a type with 350 GB or 500 GB of local SSD, you can select standard persistent disks for your database volumes instead of premium-priced disks.

Select local SSD disk size

Choosing the right local SSD size is crucial to making your site run fast. You want to make sure that you select an SSD size big enough for your website and its databases, but don’t go overboard either. The local SSD is physically attached to the server you are using and will help keep things dashing. We attach local SSDs to a specific server, meaning that we do not share them across zones or regions; however, the data on a local SSD persists when instances are rebooted or stopped and started.

Local SSDs run at high speed and low latency, making them ideal for I/O intensive workloads like databases. However, since their capacity is limited compared to persistent disks (currently 1TB), it’s best to reserve them for tasks requiring quick access to stored data rather than as a long-term storage solution.

Configure firewall rules

Firewall Rules

You need to allow access to your WordPress website. To do that, create a new firewall rule that listens on port 80 and port 443 for HTTP and HTTPS traffic, respectively:

Inbound-http Inbound-https

Once the firewall rules have been created, you can use them to configure an external IP address for your VM instance to be accessible from the Internet. When you set up an HTTP or HTTPS load balancer and assign an external IP address, by default, automatically assigned, the same external IP address is automatically assigned to its VMs.

Connect to your WordPress instance via SSH.

Assuming you have followed the steps to set up a WordPress instance successfully, let’s dive into the next step. You will need to connect to your WordPress instance via SSH. We can do this using one of GCP’s many features, namely SSH or Cloud Shell. In this tutorial, we will use SSH.

When creating our WordPress instance, we chose to allow HTTP traffic in the firewall settings. We will now use this functionality and write a simple script that allows us to navigate directly from our local machine to the external IP address of your WordPress VM Instance by simply entering “wp” on the command line anywhere on your local machine.

Install Apache Web Server and PHP on WordPress server

On your WordPress server, install Apache web server and PHP. Run the below commands to install the Apache server and PHP on your machine.

sudo apt-get update

sudo apt-get install apache2

sudo apt-get install libapache2-mod-php7.0 php7.0 php7.0-gd php7.0-mcrypt php7.0-mbstring php7.0-curl

Enable the mod_rewrite module by running the following command:

sudo a2enmod rewrite

Install MySQL Database on WordPress server.

Now we need to install the MySQL database on the WordPress server.

To do so, run the following command:

sudo apt-get install MySQL-server

It will prompt you for a password for a root user for the MySQL database during installation. Enter any password that is strong enough and secure. You will have to re-enter this password again as a confirmation.

Install PHPMyAdmin and configure it with MySQL database.

The next step is to install PHPMyAdmin, a web-based database management tool. To proceed, first, download the latest version from their website.

Once the download is complete, open your FTP client and upload the .zip file into your root directory. After it’s uploaded, extract it and rename it to PHPMyAdmin.

Next up is configuration! Open your text editor and create a file config.inc.php with the following code: `$cfg[‘blowfish_secret’] = ‘a random string of at least 32 characters’;` Save this in your root server directory (the same one you created in step 3). To check that this worked, go to http://yourdomainname/phpmyadmin/, where you’ll see a login page for PHPMyAdmin.

You can now log in with your MySQL username and password to verify that everything is correctly set up.

Download and install the latest version of WordPress.

  • Download and install the latest version of WordPress.
  • Unzip the WordPress file.
  • Move the WordPress files to the server.
  • Create a WordPress configuration file.
  • Run the WordPress installation script.

Configure WordPress for use with Google Cloud SQL for MySQL:

Congratulations, you have successfully launched your WordPress website on the Google Cloud Platform. To recap, you have learned how to host a WordPress website on Google cloud:

  1. How to create a GCP account
  2. Creating a project within GCP
  3. How to launch a new Compute Engine instance from within your project
  4. Connecting to your WordPress instance via SSH
  5. How to install Apache Web Server and PHP on your WordPress server
  6. Installing MySQL Database on your WordPress server for use with the WordPress CMS application.

You also installed phpMyAdmin to efficiently manage the databases created when installing the CMS software WordPress or any other application that relies on MySQL.

####NOW, CONFIGURING A WORDPRESS WEBSITE ON GOOGLE CLOUD####

Configure a domain with Google Cloud DNS with an SSL certificate using Cloudflare

Configure your domain with Google Cloud DNS and host your content on Google Compute Engine Instances with an SSL certificate using Cloudflare to be served over HTTPS protocol.

Step 1: Create a VM instance in Google Compute Engine

To begin, you’re going to need access to Google Cloud Console. If you don’t have an account yet, go ahead and set one up. In Navigation Menu, Click on Compute Engine>>VM Instances. Now, click on Create to create a new instance.

Once you’re in, please create a new VM instance, and start by giving it a name. Once that’s done, we recommend using the f1-micro machine type for the best performance and resource allocation. If your needs are different from this setup, feel free to adjust accordingly. The most important thing is to make sure your machine has enough memory for the services (NodeJS and Nginx) running on it later.

Next, give yourself access to the virtual machine by adding your SSH key into the metadata—that way, you can log into it with a command line rather than using the web interface (which is less efficient). We’ve gone over how to generate an SSH key here if you need some help to set up yours. And while that documentation focuses on generating keys for Google Container Engine clusters specifically, its procedures will work just fine with Compute Engine and other tools like GitHub or BitBucket repositories that use SSH keys as an authentication mechanism during login.

Step 2: Create A Records in CloudFlare

At Cloudflare, you will need to add an A record. This type of DNS record specifies the IP address associated with your domain name.

Add an A record to your DNS records:

In the DNS section, select Add Record > A.

Enter your domain name (e.g. example.com).

Enter the IP address of your compute engine instance (the same one you used for step 1). You can find this in the compute engine dashboard or by running google cloud compute instances described [YOUR_INSTANCE_NAME] in Cloud Shell and looking at the network interfaces > accessConfigs[0] > natIP value under “network interface.”

Ensure that the Proxy Status is turned off or set to “DNS Only.” If you are still having trouble after setting up this connection, make sure that there are no other conflicting DNS records on Cloudflare that may override this one (e.g., CNAME records).

Step 3: Create CNAME Records in Cloudflare

In Cloudflare, select the DNS app.

Scroll to CNAME records.

For name, enter the name of your domain.

If you are purchasing a new domain or configuring your SSL certificate to work on www.example.com, enter www in this field.

If you configure your SSL certificate to work with example.com and other sub-domains, leave this field blank to become the @ record for your domain’s root (apex) site name.

For Canonical Name (CNAME), enter the web address provided by Google Domains as directed in Step 2: Configure a domain with Google Domains for SSL certificates and forwarding.

Click Add Record when done. When prompted, click I’ve added all missing records. Continue to step 4 and complete steps 4 through 6 as directed in Step 2: Configure a domain with Google Domains for SSL certificates and forwarding.

Step 4: Configure the DNS to point to Cloudflare name servers.

In Google Cloud DNS, click “Add Record Set.” For the name, enter @. For the type, select NS. Set the TTL to 1h. Finally, in the data field, enter your Cloudflare name servers. Keep in mind that there are multiple name servers, and you should use each of them as it provides them to you by Cloudflare.

Save your changes and navigate back to your domain provider’s website (GoDaddy), where you can verify that these changes have been applied successfully.

Step 5: Add an SSL certificate to your domain

To add an SSL certificate to your domain:

In the upper right corner, click your username and select My Profile.

Scroll down to the Global API Key section and click View next to the Cloudflare Global API Key.

Please enter your password, then click I understand, continue.

Copy your Global API Key. You’ll need this in a later step when you create an Origin CA certificate for your domain using CloudFlare’s APIs.

Return to the Cloudflare dashboard and navigate to Crypto > Origin Certificates > Create certificate from the menu on the left side of the page.

Enter a name for your certificate in Hostname (s) and enter one or more Hostnames separated by a comma (example: www., ).

Click Next and follow the instructions on the screen to generate a private key (privkey) and request file (certreq) for your certificate signing request (CSR).

Now your domain is hosted with Google Compute Engine and Google Cloud DNS. It has an SSL certificate from Cloudflare, and you can access it via HTTPS.

Congratulations, you have successfully configured your domain with Google Cloud DNS, an SSL certificate from Cloudflare.

In this tutorial, you learned how to configure a domain with Google Cloud DNS, apply for an SSL certificate from Cloudflare, and connect them using CNAME records. Then we looked at how to configure an App Engine application to use that custom domain and the SSL certificate. The App Engine application then migrated to a Compute Engine VM instance, Cloud Storage, and finally a GKE cluster. At the end of this tutorial, we saw how to host this website on a Cloudflare worker.


Post a Comment

Comment should not exceed 200 words.

Previous Post Next Post