docker 安装 wordpress

还是用 docker 比较方便一点,这里直接使用官方镜像

docker-compose.yml

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 127.0.0.1:8080
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: password
      WORDPRESS_DB_NAME: name

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: name
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      MYSQL_RANDOM_ROOT_PASSWORD: '1'

Nginx 配置

server {
    listen 443 ssl;
    server_name  domain;
    access_log  off;
    ssl_certificate /path/to/cert;
    ssl_certificate_key /path/to/key;
    location / {
        proxy_pass       http://127.0.0.1:8080;
        proxy_redirect   off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Forwarded-Proto https;
    }
}
server {
    listen 80;
    server_name domain;
    return 301 https://domain$request_uri;
}

还得修改一波这个这个容器中文件的权限并添加中文语言,镜像默认是英文的

// 进入容器
sudo docker exec -it CONTAINER_ID /bin/bash

// 修改文件权限
chown -R www-data:www-data /var/www/html

// 给 WP 添加中文语言
cat << EOF >> wp-config.php
define('WPLANG', 'zh_CN');
EOF

// 退出容器
exit

在 docker-compose.yml 的文件夹下执行docker-compose up -d创建相关容器,停止容器执行docker-compose stop。最后刷新 Nginx 配置即可完成安装

Share

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注