Migrating WordPress to Cycle

Moving your WordPress Site to Cycle is incredibly fast and easy. Let’s take a look at what we’ll need to follow along with this tutorial.

  1. We’ll be using SFTP to copy over our WordPress theme files so we’ll need an FTP client. I suggest using CyberDuck or FileZilla.
  2. Copying the database to the volume will require an SQL client. All the examples in this article are using Sequl Pro.
  3. From Cycle you’ll need a Cycle account, an active hub, and a live server. Check out this awesome getting started guide from our docs, you only need to get to the step where you deploy infrastructure.

If you don’t have that set up, take a moment now to do that so you can follow along.

For assistance reach out to us directly on our public slack channel, or visit the Cycle documentation.

Part One — Creating an Environment

Environments are how we create a new private network group on Cycle. Each time you create an environment you’ll automatically create 3 service containers specially crafted by Cycle to abstract all the heavy lifting needed to network your containers (discovery container) and route your traffic (load balancer). The third generated container is a VPN container which we will cover here in a bit.

Let’s run through how to create your environment.

  • Log into your hub through the Cycle portal.
  • Click “Environments” on the left-hand navigation.
  • In the top right of the screen, select the button that says “Create Environment”.
  • Name your environment using the namefield.
  • Select your cluster from the dropdown (if you kept the default cluster name when you deployed infrastructure it will be “production”).
  • Select the “Enable Legacy Networking” Box.
  • Click “Create Environment”.

Here’s a quick gif that shows all the steps. The screen you come to after your environment is created is referred to as the environment dashboard.

Creating your WordPress environment Creating your WordPress environment

Part Two — Importing Images

Great, now we have an environment with a load balancer to handle our traffic, a discovery container to help our containers communicate on our private network and an optional VPN container we will use later to create a secure connection to our database.

Next, we need to import our image and deploy our containers.

  1. Press the “Deploy Containers” button in the top right of environment dashboard.
  2. Give the container the name “db” in the name field.
  3. Select “Stateful” from the Stateful dropdown.
  4. Click “Import New Image” under Image.
  5. Enter “mysql” in the Image Name field.
  6. Enter “5.7” in the Tag field.
  7. Click the “Import” button.

This will start importing your image. When it’s done importing you’ll see a dropdown menu appear and you can select your image from the top of that list. Images that have volumes will automatically show volume information after being selected. Our default volume size is 1GB but, for production cases, you will need much more than that. In the example below, you will see me keep the volume size at 1GB, this is for demonstration purposes only.

Below the volume size, you will also see that I leave the Public Network field as “disabled”. With Cycle, you won’t need to expose this database to public internet. All communication can happen from container to container on your private environment network. After you’ve completed all the steps, click “Create Container” to create the container. This will take you to the container dashboard.

Import and Create the MySQL Container Import and Create the MySQL Container

After creating the MySQL container, it’s time to configure the environment variables.

  1. Click the “Config” tab from the horizontal navigation.
  2. Select “Runtime” from the configuration panel.
  3. Enter the following environment variables ( these can be modified to fit your specific users and passwords ).

MYSQLDATABASE → wordpress
MYSQL
USER → wordpress
MYSQLPASSWORD → wordpress
MYSQL
ROOT_PASSWORD → somewordpress

Now click “Save Config” at the bottom and your container will add these variables to its environment.

Next, let’s take care of our WordPress container. We will follow the same steps as before. Get started by clicking the “Deploy Containers” button on the top right of the screen. From this page name your container, click import new image, type wordpress (lowercase) in the image name form box. The only difference between importing the MySQL container and this one is we need to make sure to set the public network to “enabled”.

After you create the WordPress container set these environment variables in the config ( these can be modified to fit your specific users and passwords).

WORDPRESSDBHOST → db
WORDPRESSDBUSER → wordpress
WORDPRESSDBPASSWORD → wordpress
WORDPRESSDBNAME → wordpress

  • don’t forget to click “Save Config” at the bottom before moving on.

Go back to the environment dashboard and hold the start button on the top right of the screen to start all of the containers we have imported so far.

Starting your containers for the first time. Starting your containers for the first time.

Part Three — Update your WordPress Image via SFTP

Using an FTP client, we can now access our WordPress containers volume and upload any files we may need to fulfill our site transfer. To connect via the FTP client, you’ll navigate to the volumes page (shown below) and enable remote access.

Once you’ve enabled remote access to the volume.

  • Click “Instances” and then the instance you’re trying to connect to.
  • At the bottom of the page, there will be a button that says “SFTP Details”, clicking that will pop up a modal with your log in information.

Volumes with Remote Access Volumes with Remote Access

Using this workflow you can copy over any files you need to get your WordPress application migrated. Next we’ll cover more about migrating our database files to our “db” container.

Part Four — Migrate your database

There are a few essential steps to migrating the database.

  1. We need to “dump” all of the contents of the database into a .sql file. The example below is how to achieve this using Sequel Pro.
  2. After we have the file we can connect to our private environment network via our VPN container.
  3. Once we are connected to that network we can use our credentials to log into the database using Sequel Pro.
  4. Finally, we can import the file into the database container volume using Sequel Pro and our migration will be complete.

Create a .sql file by exporting the database via a “dump” Create a .sql file by exporting the database via a “dump”

After the dump is complete and you have your .sql file ready, we need to start and configure the VPN container.

  1. Select “VPN” from the environment dashboard.
  2. Select “Enable”.
  3. Click “Download VPN Files” ( if it doesn’t download right away give the container a few minutes and then try again ).
  4. Unzip the files and use the config file to create a new VPN connection.
  5. Select the setting “Allow Cycle Logins” and then “Update VPN Access”

Now when you go to log in to your new connection you can use the same email address and password that you use to login to Cycle.

VPN VPN

Now that the VPN container is running and you are connected, we can use Sequel Pro to make a standard connection to our database container via the IP address listed in the instance dashboard as the host.

The database instance dashboard and IP The database instance dashboard and IP

The username to log into your container is root and the password is the MYSQL_ROOT_PASSWORD you set as the environment variable above.

Part Five — Point your domain

Before you get started with DNS records make sure you have your domain’s nameservers pointed to ns1, ns2, and ns3.cycle.io.

The last step is to finish our DNS records. Luckily, with Cycle, DNS is a snap.

  • Navigate to the “DNS” tab from the left-side navigation.
  • Click “Create Zone” on the top right of the DNS dashboard.
  • Type the origin into the Origin field.
  • Select “Hosted” from the Zone Type dropdown.
  • Make sure to use the “Verify Domain” button to verify your DNS Zone.

If your DNS Zone doesn’t verify, it’s likely that either your nameservers haven’t been pointed to Cycle or propagation has not completed. If you get stuck here and need some help reach out to us on slack.

Next, you’ll need to add a linked record pointing at your WordPress container.

  • Press the “Add Record” button.
  • Choose “Linked” for the record type.
  • Put “@” (to refer to the root domain) in the name field.
  • Under Assignment choose “Container”.
  • Choose your environment and the “wordpress” container.
  • Click “Add Record”

In the example, you will see me use the “dev” subdomain. For your workflow just use your normal domain. I will do another post soon on how to delegate DNS for subdomains on Cycle.

DNS DNS

To check if everything is working navigate to your domain and check the output. And that’s it! You’ve successfully migrated your WordPress application to Cycle.

Still Have Questions?

If you want to dive in and learn more, head over to our slack channel. Our community is growing, and our team hangs out there daily. Feel free to shoot us a message any time with your questions and we’ll be sure to respond!

Of course, for a more in-depth look at how to use Cycle, check out our documentation.