Use shell scripts to quickly build a WordPress website and configure the mariadb database for remote access

Table of contents

Preface

1. What is WordPress?

2. Construction steps

1. Create a new file wp.conf in the home directory with the following content

2. Create a new file: wordpress.sh

3. Add executable permissions to wordpress.sh and execute it

4. Create the my.cnf file in /home/mariadb/config and write the following content

5. Restart the mariadb container


Preface

How to quickly build a WordPress website and configure the database for remote access? This article will provide you with the answers.


提示:以下是本篇文章正文内容,下面案例可供参考

1. What is WordPress?

        ​​ ​ WordPress is a free, open source content management system (CMS) used to create and manage websites, blogs, and other online content. It is scalable and flexible, allowing users to customize its appearance and functionality, and is easy to use. WordPress supports a variety of plugins and themes, allowing users to easily extend its functionality and customize its appearance.

2. Construction steps

1. Home directoryCreate a new file wp.conf with the following content

The code is as follows (example):

server {
  listen 80;
  default_type text/html;

  location / {
      proxy_http_version 1.1;
      proxy_set_header Host $host;
      proxy_pass http://172.17.0.3;
  }
}

172.17.0.3理论上为WordPress docker地址,如果不对,可使用“docker inspect 容器id”命令查看地址并修改。 

 
 

2. Create a new file: wordpress.sh

mkdir -p my/mariadb/data
mkdir -p my/mariadb/config
docker run -v `pwd`/my/mariadb/data:/var/lib/mysql -v `pwd`/my/mariadb/config:/etc/mysql -d -p 3306:3306 \
    --env MARIADB_DATABASE=db \
    --env MARIADB_USER=test \
    --env MARIADB_PASSWORD=123456 \
    --env MARIADB_ROOT_PASSWORD=123456 \
    mariadb:10
docker run -d \
    --env WORDPRESS_DB_HOST=172.17.0.2 \
    --env WORDPRESS_DB_USER=test \
    --env WORDPRESS_DB_PASSWORD=123456 \
    --env WORDPRESS_DB_NAME=db \
    wordpress:6
docker run -d \
    -p 80:80 \
    -v `pwd`/wp.conf:/etc/nginx/conf.d/default.conf \
    nginx:alpine
According to the above steps, if the docker container has not been started in the current system, according to the sequence, the IP of mariadb is 172.17.0.2. After the container is started, the command: docker inspect container id can be used to verify and adjust.

3. Add executable permissions to wordpress.sh and execute it

chmod +x wordpress.sh
./wordpress.sh

4. Create the my.cnf file in /root/my/mariadb/config and write the following content

[client]
default-character-set = utf8
port = 3306

[mysql]
port = 3306
default-character-set  = utf8

[mysqld]
default-storage-engine  = InnoDB
skip-name-resolve
skip-host-cache
skip-grant-tables
skip-external-locking
max_connections = 2000
max_allowed_packet = 64M
table_open_cache = 2048

5. Restart the mariadb container

docker restart mariadb:10

Guess you like

Origin blog.csdn.net/wangluoxiehui/article/details/129898441