Connect to TiDB Cloud Serverless with WordPress
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.
Prerequisites
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.
Run WordPress with TiDB Cloud Serverless
This section demonstrates how to run WordPress with TiDB Cloud Serverless.
Step 1: Clone the WordPress sample repository
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
Step 2: Install dependencies
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.shThe sample repository includes the TiDB Compatibility Plugin as a submodule. Run the following command to update the submodule:
git submodule update --init --recursive
Step 3: Configure connection information
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.
Run the following command to copy
.env.example
and rename it to.env
:cp .env.example .envCopy 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.
Step 4: Start WordPress with TiDB Cloud Serverless
Execute the following command to run WordPress as a Docker container:
docker compose up -dSet 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.
Step 5: Confirm the database connection
- 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.
Need help?
Ask questions on TiDB Community, or create a support ticket.