Please refer the document test the host network status with TiDB Serverless before you start deploy.

Deploy WordPress

docker run --name tidb-wordpress -p 80:80 -d \
  -e WORDPRESS_DB_HOST=<database host url>:4000 \
  -e WORDPRESS_DB_CHARSET=utf8mb4 \
  -e WORDPRESS_DB_COLLATE=utf8mb4_bin \
  -e WORDPRESS_DB_USER=<username> \
  -e WORDPRESS_DB_NAME=<database name> \
  -e WORDPRESS_DB_PASSWORD=<password> \
  -e WORDPRESS_CONFIG_EXTRA="define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);" \
  -e WORDPRESS_DEBUG=1 \
  wordpress

 

1. Install wp command

2. Install WordPress by wp command

$ # Enable SSL to add define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
$ # Set the DB_CHARSET to utf8mb4.  
$ # Set the DB_COLLATE to utf8mb4_bin.
$ wp core config --dbhost=&lt;database host url&gt;:4000 --dbname=&lt;database name&gt; --dbuser=&lt;username&gt; --dbpass=&lt;password&gt; --dbprefix=&lt;dbprefix&gt; --dbcharset=utf8mb4 --dbcollate=utf8mb4_bin --extra-php &lt;&lt;PHP
define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
PHP
Success: Generated 'wp-config.php' file.
$ # Confirm the wp-config.php setting file. The command below is sample, please confirm the wp-config.php path by yourself environment.
$ echo /var/www/html/wordpress/wp-config.php
......
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', 'utf8mb4_bin' );

/* Add any custom values between this line and the "stop editing" line. */

define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);

/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';
......
$ wp core install --url=&lt;domain&gt; --title="&lt;web site title&gt;" --admin_name=&lt;admin username&gt; --admin_password=&lt;admin password&gt; --admin_email=&lt;admin Email&gt;
Warning: Unable to create directory wp-content/uploads/2023/08. Is its parent directory writable by the server?
Success: WordPress installed successfully.

The example provided does not include configurations for persistent storage and load balancer settings. Please set these configurations based on business and environmental requirements.

 

Prerequisites:

  • You have already set up a Kubernetes cluster.
  • The kubectl CLI is configured to communicate with your cluster.

 

Creating a secret to store the database password:

This will create a Kubernetes Secret named mysql-pass, which contains a key named password. The value of this key is the database password.

kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD

 

Deploying WordPress:

Create a wordpress-deployment.yaml file.

apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
  selector:
    app: wordpress
    tier: frontend
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
        - image: wordpress
          name: wordpress
          env:
          - name: WORDPRESS_DB_HOST
            value: <database host url>:4000
          - name: WORDPRESS_DB_USER
            value: <username>
          - name: WORDPRESS_DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-pass
                key: password
          - name: WORDPRESS_DB_NAME
            value: <database name> 
          - name: WORDPRESS_DB_CHARSET
            value: utf8mb4
          - name: WORDPRESS_DB_COLLATE
            value: utf8mb4_bin
          - name: WORDPRESS_CONFIG_EXTRA
            value: "define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);"
          ports:
            - containerPort: 80
              name: wordpress

 

Execute:

$ kubectl apply -f wordpress-deployment.yaml

 

 

 

Docker
docker run --name tidb-wordpress -p 80:80 -d \
  -e WORDPRESS_DB_HOST=<database host url>:4000 \
  -e WORDPRESS_DB_CHARSET=utf8mb4 \
  -e WORDPRESS_DB_COLLATE=utf8mb4_bin \
  -e WORDPRESS_DB_USER=<username> \
  -e WORDPRESS_DB_NAME=<database name> \
  -e WORDPRESS_DB_PASSWORD=<password> \
  -e WORDPRESS_CONFIG_EXTRA="define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);" \
  -e WORDPRESS_DEBUG=1 \
  wordpress

 

Vitrual Machine

1. Install wp command

2. Install WordPress by wp command

$ # Enable SSL to add define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
$ # Set the DB_CHARSET to utf8mb4.  
$ # Set the DB_COLLATE to utf8mb4_bin.
$ wp core config --dbhost=&lt;database host url&gt;:4000 --dbname=&lt;database name&gt; --dbuser=&lt;username&gt; --dbpass=&lt;password&gt; --dbprefix=&lt;dbprefix&gt; --dbcharset=utf8mb4 --dbcollate=utf8mb4_bin --extra-php &lt;&lt;PHP
define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
PHP
Success: Generated 'wp-config.php' file.
$ # Confirm the wp-config.php setting file. The command below is sample, please confirm the wp-config.php path by yourself environment.
$ echo /var/www/html/wordpress/wp-config.php
......
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', 'utf8mb4_bin' );

/* Add any custom values between this line and the "stop editing" line. */

define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);

/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';
......
$ wp core install --url=&lt;domain&gt; --title="&lt;web site title&gt;" --admin_name=&lt;admin username&gt; --admin_password=&lt;admin password&gt; --admin_email=&lt;admin Email&gt;
Warning: Unable to create directory wp-content/uploads/2023/08. Is its parent directory writable by the server?
Success: WordPress installed successfully.
Kubernetes

The example provided does not include configurations for persistent storage and load balancer settings. Please set these configurations based on business and environmental requirements.

 

Prerequisites:

  • You have already set up a Kubernetes cluster.
  • The kubectl CLI is configured to communicate with your cluster.

 

Creating a secret to store the database password:

This will create a Kubernetes Secret named mysql-pass, which contains a key named password. The value of this key is the database password.

kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD

 

Deploying WordPress:

Create a wordpress-deployment.yaml file.

apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
  selector:
    app: wordpress
    tier: frontend
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
        - image: wordpress
          name: wordpress
          env:
          - name: WORDPRESS_DB_HOST
            value: <database host url>:4000
          - name: WORDPRESS_DB_USER
            value: <username>
          - name: WORDPRESS_DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-pass
                key: password
          - name: WORDPRESS_DB_NAME
            value: <database name> 
          - name: WORDPRESS_DB_CHARSET
            value: utf8mb4
          - name: WORDPRESS_DB_COLLATE
            value: utf8mb4_bin
          - name: WORDPRESS_CONFIG_EXTRA
            value: "define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);"
          ports:
            - containerPort: 80
              name: wordpress

 

Execute:

$ kubectl apply -f wordpress-deployment.yaml