title | summary |
---|---|
Connect to TiDB Cloud Serverless with WordPress |
Learn how to use TiDB Cloud Serverless to run WordPress. This tutorial gives step-by-step guidance to run WordPress + TiDB Cloud Serverless in a few minutes. |
TiDB is a MySQL-compatible database, TiDB Cloud Serverless is a fully managed TiDB offering, and WordPress is a free, open-source content management system (CMS) that lets users create and manage websites. WordPress is written in PHP and uses a MySQL database.
In this tutorial, you can learn how to use TiDB Cloud Serverless to run WordPress for free.
Note:
In addition to TiDB Cloud Serverless, this tutorial works with TiDB Cloud Dedicated and TiDB Self-Managed clusters as well. However, it is highly recommended to run WordPress with TiDB Cloud Serverless for cost efficiency.
To complete this tutorial, you need:
- A TiDB Cloud Serverless cluster. Follow creating a TiDB Cloud Serverless cluster to create your own TiDB Cloud cluster if you don't have one.
This section demonstrates how to run WordPress with TiDB Cloud Serverless.
Run the following commands in your terminal window to clone the sample code repository:
git clone https://github.com/Icemap/wordpress-tidb-docker.git
cd wordpress-tidb-docker
-
The sample repository requires Docker and Docker Compose to start WordPress. If you have them installed, you can skip this step. It is highly recommended to run your WordPress in a Linux environment (such as Ubuntu). Run the following command to install Docker and Docker Compose:
sudo sh install.sh
-
The sample repository includes the TiDB Compatibility Plugin as a submodule. Run the following command to update the submodule:
git submodule update --init --recursive
Configure the WordPress database connection to TiDB Cloud Serverless.
-
Navigate to the Clusters page, and then click the name of your target cluster to go to its overview page.
-
Click Connect in the upper-right corner. A connection dialog is displayed.
-
Ensure the configurations in the connection dialog match your operating environment.
- Connection Type is set to
Public
. - Connect With is set to
WordPress
. - Operating System is set to
Debian/Ubuntu/Arch
. - Database is set to the database you want to use—for example,
test
.
- Connection Type is set to
-
Click Generate Password to create a random password.
Tip:
If you have created a password before, you can either use the original password or click Reset Password to generate a new one.
-
Run the following command to copy
.env.example
and rename it to.env
:cp .env.example .env
-
Copy and paste the corresponding connection string into the
.env
file. The example result is as follows:TIDB_HOST='{HOST}' # e.g. gateway01.ap-northeast-1.prod.aws.tidbcloud.com TIDB_PORT='4000' TIDB_USER='{USERNAME}' # e.g. xxxxxx.root TIDB_PASSWORD='{PASSWORD}' TIDB_DB_NAME='test'
Be sure to replace the placeholders
{}
with the connection parameters obtained from the connection dialog. By default, your TiDB Cloud Serverless comes with atest
database. If you have already created another database in your TiDB Cloud Serverless cluster, you can replacetest
with your database name. -
Save the
.env
file.
-
Execute the following command to run WordPress as a Docker container:
docker compose up -d
-
Set up your WordPress site by visiting localhost if you start the container on your local machine or
http://<your_instance_ip>
if the WordPress is running on a remote machine.
- Close the connection dialog for your cluster on the TiDB Cloud console, and open the SQL Editor page.
- Under the Schemas tab on the left, click the database you connected to Wordpress.
- Confirm that you now see the Wordpress tables (such as
wp_posts
andwp_comments
) in the list of tables for that database.
Ask the community on Discord or Slack, or submit a support ticket.