Comment on page
WordPress with MySQL
In this tutorial, you'll learn how to deploy WordPress and MySQL on Release.
Using Docker Compose during WordPress theme or plugin development ensures that your development and build environments can be recreated easily on your team's workstations and staging servers.
By adding your WordPress repository to Release, you can create environments per branch, create staging environments, test contributors' pull requests, and share demo links with clients.
Besides a web browser, you won't need anything specific installed on your computer for this guide.
docker-compose.yamlfile lists two services for this application:
The service called
dbruns a specific
mysqlDocker image, while the
wordpressservice runs the latest
Release can import applications based on Docker Compose, so we won't need to change anything in the repository to add this application to Release.
Create an application
Enter a unique name for your application, and pick the forked repository you created earlier, then click Next step.
Enter a name and pick your repository
- 1.Pick Analyze the repository, so Release can create services from
- 2.Select the branch from your repository you'd like to track in this application.
- 3.Select the
- 4.Click Start analysis.
Pick your services
Release will read your Docker Compose file, and list the services found.
Pick your services showing analysis result
Click Next step.
Release will generate a template based on the services from your
Generate an application template
Release will use this template to create new environments later on, and the defaults should work as expected for most Docker Compose applications.
Release does not currently convert
exposedirectives when importing services from Docker Compose. Add a
container_portfor each port in your Docker Compose file. Read more about ports in our template schema.
For this example application, we'll make one important change to the template to make sure the
dbservice exposes two ports for MySQL.
dbservice in the application template YAML, and add two container ports by making the following changes:
- name: db
+ - type: container_port
+ port: '3306'
+ - type: container_port
+ port: '33060'
Release supports two different port types:
container_port. We're adding a container port to the
dbservice because this port should only be accessible on your application's private network. This enables the
wordpressservice to connect to the
dbservice without exposing your MySQL database to the internet.
After editing the template, click Next step.
docker-compose.yamlfile from our repo lists the environment variables for each service.
To see how each service's container will use these environment variables, we can consult the Docker images documentation.
rootMySQL user's password. On a production server, this should be treated as secret.
If this variable is set, MySQL will create a database with this variable's value as a name. For our example, we'll set this to
We can expect the MySQL server to create a database called
MySQL uses these two variables together to set a username and password for a new MySQL user on startup. This user will be granted superuser privileges (
GRANT ALL) on the database specified by
For the example application, we'll set both to
On startup, we can expect MySQL to create a new user called
wordpresswith the password
wordpress, and grant the user all privileges on the
WordPress uses a
wp-config.phpfile to set database access strings and other settings. Usually, you would edit
wp-config.phpmanually and set the database hostname, username, and password as PHP variables.
Let's take a look at the four environment variables in our example application.
The WordPress Docker image uses this variable to set the database hostname. For our example, we'll set this to
Release creates a private network for your application, and by default, any service in your application can discover any other service in the application by querying a service's name.
This means the
wordpressservice can reach the
dbservice's container on the private network by querying the
The WordPress Docker image uses these three variables to know which database to use and to authenticate with the MySQL database server.
For this example, we'll set all three to
wordpressso that they match the equivalent variables set for the
Set your environment variables
Edit the YAML environment variables in Release to look like this:
- key: MYSQL_ROOT_PASSWORD
- key: MYSQL_DATABASE
- key: MYSQL_USER
- key: MYSQL_PASSWORD
- key: WORDPRESS_DB_HOST
- key: WORDPRESS_DB_USER
- key: WORDPRESS_DB_PASSWORD
- key: WORDPRESS_DB_NAME
You'll notice that we marked the
WORDPRESS_DB_PASSWORDvariables as secret by setting the
secretflag to true for each of them.
Click Next step to save your environment variables.
This application does not use any build arguments, so we can click Next step.
Click Deploy your app to create your application.
Deploy your app
Release will now pull two Docker images,
wordpress, then start two services,
Your browser should redirect to a deployment status page, showing the progress of the setup workflow.
After Release's set-up and deployment workflow completes, navigate to your new environment and click on the URL for the
Service hosted URL
You should now see the WordPress setup screen.
WordPress' language selection screen
Select your language and click Continue.
Create a user and install WordPress by following these steps:
- 1.Enter a site title.
- 2.Enter a username, which you'll use later to log into WordPress.
- 3.Copy and save the recommended password. You'll use this later to log into WordPress.
- 4.Enter your email address.
- 5.Tick the search engine visibility checkbox. We recommend this to discourage search engines from crawling websites in development.
- 6.Click Install WordPress.
Your WordPress service will now run WordPress's installation script, which connects to your MySQL database and adds the required tables and configuration. WordPress also creates an admin user based on the username and password you entered.
WordPress installed successfully
Click log in.
Enter your username and password, then click Log in.
Log into WordPress
On the WordPress dashboard, hover over your site's name and click visit site.
View your WordPress site
You should see a sample page on your WordPress site now.
WordPress sample page
If you don't see the WordPress language selector after the deployment workflow above, you can view the logs for each service in your environment to see whether either service logged any errors.
To view a service's logs, navigate to your environment's details page, scroll down to the list of services, and click on logs.
The most common problem when first installing WordPress is a database connection error.
WordPress database error
On Release, this error can be solved by working through the following steps:
- 1.Make sure the corresponding environment variables from both services match.Values for the variables in each row below should match:
- 2.Make sure the
WORDPRESS_DB_HOSTenvironment variable matches the name of your database service.
- 3.Make sure your database service exposes the correct ports. MySQL on Docker uses ports
Docker is most useful when developing WordPress plugins and themes, rather than just configuring a WordPress site.
We recommend pre-installing your themes and plugins if you're using Docker for WordPress development.
In the example above, only the database service mounts a persistent volume. This means that the database data for each environment will remain after the application restarts or re-deploys.
The WordPress service does not use a persistent volume.
Images and other files uploaded to your WordPress site will be deleted when you re-deploy your application.