zhuangjie
ZhuangJie

原文(英文):https://eskerda.com/wordpress-sqlite-quick-start-with-docker-compose/

 

今天,我尝试使用 sqlite 插件 为 WordPress 添加 sqlite 支持,该插件即将加入 WordPress 核心。我在网上找到了许多不同的教程,但希望有一个无需现有实例运行、无需手动执行步骤或无需信任非官方镜像的解决方案。因此,我编写了一个 Docker Compose 项目 以便快速设置并关闭环境。请注意以下步骤仅用于本地测试目的。

该仓库包含一个 db.php 文件(从插件的 db.copy 文件复制而来),当插件激活时会填充该文件。我使用了一个预填写的文件来避免执行自动填充。WordPress 还需要一个 wp-config.php 文件来告知其已进行配置,且配置步骤需要数据库连接。为了省去这一步骤,我将 WordPress Alpine 版本的 php-fpm 镜像运行了起来,而不是使用默认的 Apache 镜像,同时包含 fpm.conf 文件,其中有简单的配置以与 nginx 一起使用。

以下是大致的操作步骤:

$ git clone https://github.com/eskerda/wp-sqlite-docker-compose
$ cd wp-sqlite-docker-compose
$ git clone https://github.com/wordpress/sqlite-database-integration
$ docker compose up -d
$ open http://localhost:8080
$ docker compose logs -f

以下是 Docker Compose 文件的内容:

version: '3.8'
services:
  wordpress:
    image: wordpress:6.1.1-fpm-alpine
    volumes:
      - wordpress:/var/www/html/
      - ./wp-config.php:/var/www/html/wp-config.php
      - ./db.php:/var/www/html/wp-content/db.php
      - ./sqlite-database-integration:/var/www/html/wp-content/plugins/sqlite-database-integration
      - ./wp-content:/var/www/html/wp-content
  nginx:
    image: nginx:1.7
    volumes:
      - ./fpm.conf:/etc/nginx/conf.d/default.conf
      - wordpress:/var/www/html
    ports:
      - 8080:80
volumes:
  wordpress:

该内容定义了一个持久化的 volume 用于保存所有 WordPress 文件,并包含一个本地绑定挂载到 wp-content 的目录,以方便快速编辑 sqlite 数据库文件。理想情况下,我希望能够直接绑定这个文件,但由于遇到了权限错误,为了避免复杂的错误处理过程,我选择了这种方式。

$ sqlite3 wp-content/database/wordpress.db
SQLite version 3.37.0 2021-12-09 01:34:53
Enter ".help" for usage hints.
sqlite> .tables
wp_commentmeta wp_postmeta wp_termmeta wp_comments wp_posts wp_terms wp_links wp_term_relationships wp_usermeta wp_options wp_term_taxonomy wp_users
sqlite> .schema wp_posts
CREATE TABLE wp_posts ( 
  ID integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  post_author integer NOT NULL default '0',
  post_date text NOT NULL default '0000-00-00 00:00:00',
  post_date_gmt text NOT NULL default '0000-00-00 00:00:00',
  post_content text NOT NULL,
  post_title text NOT NULL,
  post_excerpt text NOT NULL,
  post_status text NOT NULL default 'publish',
  comment_status text NOT NULL default 'open',
  ping_status text NOT NULL default 'open',
  post_password text NOT NULL default '',
  post_name text NOT NULL default '',
  to_ping text NOT NULL,
  pinged text NOT NULL,
  post_modified text NOT NULL default '0000-00-00 00:00:00',
  post_modified_gmt text NOT NULL default '0000-00-00 00:00:00',
  post_content_filtered text NOT NULL,
  post_parent integer NOT NULL default '0',
  guid text NOT NULL default '',
  menu_order integer NOT NULL default '0',
  post_type text NOT NULL default 'post',
  post_mime_type text NOT NULL default '',
  comment_count integer NOT NULL default '0' 
);
CREATE INDEX post_name ON wp_posts(post_name);
CREATE INDEX type_status_date ON wp_posts(post_type,post_status,post_date,ID);
CREATE INDEX post_parent ON wp_posts(post_parent);
CREATE INDEX post_author ON wp_posts(post_author);
sqlite>

总体来说,这看起来很有前景,我将尽快将其更新到类似的状态。

最后,我还提供了一个简化的 Docker 一行命令,省去了我添加的复杂的 fpm 绑定挂载。简化的命令如下:

docker run --name wp-sqlite -v $(realpath wp-config.php):/var/www/html/wp-config.php -v $(realpath db.php):/var/www/html/wp-content/db.php -v $(realpath sqlite-database-integration):/var/www/html/wp-content/plugins/sqlite-database-integration -p 8080:80 wordpress

 

posted on 2025-02-07 11:21  zhuangjie  阅读(106)  评论(0)    收藏  举报