Deploy Dokuwiki to localhost

导言

Dokuwiki is the most easy log-in-blog choice of lab/team to accumulate knowledge.

弄明白dukuwiki的权限系统和无数据库怎么实现的:基于文本

PHP vs HTML

PHP(Hypertext Preprocessor)和 HTML(Hypertext Markup Language)是两种不同的技术,但它们通常一起使用以创建动态的、交互式的网页。

  1. PHP 是服务器端脚本语言:

    • PHP 是一种服务器端脚本语言,它用于处理服务器上的任务,如数据库查询、文件操作等。PHP 的主要目的是生成动态内容,而不像 HTML 那样是静态的。
  2. HTML 是用于构建网页的标记语言:

    • HTML 是一种标记语言,用于定义网页的结构和内容。HTML 文档包含各种标签,这些标签描述了文档的各个部分,如标题、段落、链接、图像等。HTML 是一种静态语言,它描述了页面的初始状态。
  3. PHP 和 HTML 的结合:

    • PHP 和 HTML 通常通过嵌套的方式结合在一起。在 PHP 中,你可以嵌入 HTML 代码,并且在其中插入 PHP 代码块。这使得你可以在页面中包含动态生成的内容。例如:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      <!DOCTYPE html>
      <html>
      <head>
      <title>PHP and HTML</title>
      </head>
      <body>
      <h1>Hello, <?php echo "World"; ?>!</h1>
      </body>
      </html>

    上面的例子中,PHP 代码 <?php echo "World"; ?> 将动态生成 “World” 并嵌入到 HTML 页面中。

  4. 动态生成内容:

    • PHP 被用来在服务器上执行任务,生成动态内容,然后将生成的 HTML 送回到客户端的浏览器。这使得网页可以根据用户的请求、数据库的内容等动态地生成并呈现。

总的来说,PHP 和 HTML 一起使用,使得开发者能够创建动态、交互性更强的网页。 PHP 处理服务器端的逻辑,而 HTML 描述页面的结构和初始状态。通过将它们结合使用,可以构建出丰富、实用的 Web 应用程序。

Docker 部署

其余的默认不集成git插件。

使用dockerfile或者这个, 但是无法集成git插件。

=== “bitnami/dokuwiki”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
version: '2'
services:
dokuwiki:
image: 'docker.io/bitnami/dokuwiki:latest'
# 镜像:'docker.io/bitnami/dokuwiki:20200729.0.0-debian-10-r107'
user: root
ports:
- '8233:8080'
- '443:8443'
volumes:
- '/staff/shaojiemike/dockerVolumes/dokuwiki:/bitnami/dokuwiki'
# - /absolute/path/on/host:/path/in/container
environment:
- DOKUWIKI_USERNAME=yahaha
- DOKUWIKI_PASSWORD=yahaha
- DOKUWIKI_EMAIL=9436481817@qq.com
- DOKUWIKI_WIKI_NAME=TSJ test wiki
git:
image: 'docker.io/library/git:latest'
command: ["tail", "-f", "/dev/null"]
# portainer部署已知问题:无法发邮件, 而且默认没有git

=== “simple docker command”

1
docker run -ti -d --name dokuwiki -p 8233:8080 -v /staff/shaojiemike/dockerVolumes/dokuwiki:/bitnami/dokuwiki  docker.io/bitnami/dokuwiki:latest

=== “shuosc/docker-dokuwiki”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# docker-compose.yml

version: '2'
services:
dokuwiki:
image: shuosc/dokuwiki:latest
ports:
- 80:80
environment:
- DIR=wiki
volumes:
- ./data:/opt/data
- ./log:/var/log/apache2
# After running the container with the above, you can refer to http://localhost/wiki to check it.
# The default admin username & password are both admin
  • 保存挂载在外的volumes,来实现数据的保存、迁移和快速部署。
  • 建议使用portainer,十分不建议使用docker-compose的命令行命令。除非利用root用户执行docker-compose up -d,不然会有文件权限问题。各种问题,软件版本问题等,十分折磨。
title
1
2
3
4
5
6
7
8
9
10
11
12
13
# docker-compose.yml

version: '3'
services:
dokuwiki:
image: tsj/dokuwili:v1
ports:
- 8333:80
environment:
- DIR=wiki
volumes:
- /root/doku-tsj/data:/opt/data
- /root/doku-tsj/log:/var/log/apache2

Ubuntu下安装

测试机器 icarus0 http://222.195.72.221/

使用Nginx替换Apache

1
2
3
4
5
6
7
8
9
# Ubuntu/Debian:
sudo service apache2 stop
# Install nginx
sudo apt-get update
sudo apt-get install nginx
# Start
sudo service nginx start
# check
systemctl status nginx.service

简单修改配置文件/etc/nginx/nginx.conf:

  1. 在html块加上 root /var/www/html;,
  2. 然后修改/var/www/html/index.html,来check是否能内网80端口访问。

安装php in Nginx

1
2
3
4
5
sudo apt-get install php-fpm php-cli php-mbstring php-xml php-gd
# check service verion
ls /lib/systemd/system/php*-fpm.service
sudo systemctl start php8.1-fpm
sudo systemctl status php8.1-fpm

不同于apache2[^2],你还需要在sudo vim /etc/nginx/sites-enabled/defaultserver块里开启对应代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server{
...

; 处理根目录 / 下的请求的方式
location / {
; try_files 指令尝试查找静态文件,如果找不到,则将请求重定向到 /doku.php 脚本,并将查询参数($args)传递给 PHP 脚本。
try_files $uri $uri/ /doku.php?$args;
}

; 使用正则表达式匹配以 .php 结尾的请求。
location ~ \.php$ {
include snippets/fastcgi-php.conf;

# 请根据你的 PHP 版本和配置进行调整
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

# 设置 FastCGI 参数,告诉 PHP-FPM 请求的脚本文件名。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

# 引入了一些常用的 FastCGI 参数。
include fastcgi_params;
}
}

apache2 | nginx with php

  • 在 Ubuntu 上,使用 systemctl 命令可以重启 Apache HTTP Server,也称为 httpd。
  • nginx 本身不直接负责启动或重启 PHP 进程,因为 PHP 进程通常由 PHP-FPM(FastCGI Process Manager)来管理。如果你想重启 PHP-FPM,你需要执行以下命令:sudo systemctl restart php-fpm

php配置文件

配置文件通常位于 /etc/php/{PHP_VERSION}/fpm/php-fpm.conf,而具体的 PHP 版本可能会有所不同。你需要打开该文件并确保以下配置项已设置:

在配置文件中找到以下行并确保它们没有注释(默认会没注释)

1
2
pid = /var/run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm.log

测试php

在默认的httpd服务数据存放目录/var/www/html/创建一个名称为phpinfo.php的测试文件,内容如下:

1
<?php phpinfo(); ?> 

重启httpd服务sudo systemctl restart nginx

测试http://IP地址/phpinfo.php 会显示紫色的表格信息,而不是下载文件。

下载dokuwiki

[官网](https

  • Stable version
  • languages: en + zh
  • plugins:
    • CAPTCHA Plugin
    • Upgrade Plugin
    • Translation Plugin
    • Gallery Plugin

安装包十分的小(3.3MB),

1
2
3
4
5
6
# powershell
scp dokuwiki-a6b3119b5d16cfdee29a855275c5759f.tgz shaojiemike@192.168.31.237:~/docu.tgz

tar xvf docu.tgz
# shaojiemike @ icarus1 in ~/Download [19:17:26] C:1
$ sudo cp -r dokuwiki/* /var/www/html/

配置dokuwiki网页

修改文件 sudo vim /etc/nginx/sites-enabled/default

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
server {
listen 80;
; set will triger bugs
; server_name 222.195.72.221;

; root /path/to/your/dokuwiki;
root /var/www/html/;
index index.php;

location / {
try_files $uri $uri/ /doku.php?$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Adjust for your PHP version and configuration
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

; 有些doku数据文件夹,不应该被直接访问
location ~ /(data|conf|bin|inc|vendor)/ {
deny all;
}

# Additional configurations...
}
  1. 测试sudo nginx -t
  2. 重启sudo systemctl restart nginx

The datadir (‘pages’) at /var/www/html/data/pages is not found, isn’t accessible or writable.

设置文件权限:确保 DokuWiki 目录具有正确的文件权限,以便 Nginx 和 PHP-FPM 可以读取和写入必要的文件。

1
sudo chown -R www-data:www-data /path/to/your/dokuwiki

请注意,www-data 是 Nginx 默认使用的用户和组,你可能需要根据你的实际情况调整。

安装dokuwiki in Web

  • 安装并配置好 nginxphp 之后,应该能顺利打开网页端的 http://222.195.72.221/install.php
  • 并配置 enable acl(Access control)并设置 close wiki
  • And delete the install.php file.

至此,安装完成,http://222.195.72.221/doku.php

插件安装

无法连接到扩展库。请确定您的服务器可以连接 www.dokuwiki.org 并检查您的代理设置。

要让你的Nginx通过代理服务器访问外部互联网,你需要配置Nginx来使用HTTP代理。以下是你可以尝试的步骤:

  1. 全局代理配置
    如果你希望整个系统都使用代理,你可以在系统级别配置代理。

编辑或创建 /etc/environment 文件,添加以下内容:

1
2
http_proxy="http://192.168.31.154:7890"
https_proxy="http://192.168.31.154:7890"

然后,重启Nginx服务以应用新配置:

1
sudo systemctl restart nginx
  1. Nginx代理配置
    如果你只想为Nginx特定的请求使用代理,你可以在Nginx配置文件中使用proxy_pass指令。

编辑你的Nginx配置文件,通常在 /etc/nginx/nginx.conf/etc/nginx/conf.d/your-config.conf

1
2
3
4
5
6
7
location / {
proxy_pass http://192.168.31.154:7890;
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-Proto $scheme;
}

请注意,这将通过你的代理转发所有请求。如果你只想代理特定的请求路径,可以在 location 块中进行更具体的匹配。

  1. 环境变量配置
    确保环境变量已正确设置,特别是在Nginx启动时需要加载的环境变量。

你可以在Nginx的systemd服务文件中添加环境变量。编辑 /etc/systemd/system/nginx.service.d/proxy.conf,并添加以下内容:

1
2
3
[Service]
Environment="http_proxy=http://192.168.31.154:7890"
Environment="https_proxy=http://192.168.31.154:7890"

然后,重新加载systemd并重启Nginx服务:

1
2
sudo systemctl daemon-reload
sudo systemctl restart nginx
  1. 应用程序层面配置
    如果是应用程序(例如Dokuwiki)本身需要使用代理,你可能需要在应用程序的配置文件中设置代理。

查看Dokuwiki的配置文件,通常在 conf 目录下,找到或添加代理配置。

1
2
// conf/dokuwiki.php 或 local.php
$conf['proxy'] = 'http://192.168.31.154:7890';

通过以上步骤,你应该能够让Nginx或你的应用程序通过指定的HTTP代理访问外部互联网。具体取决于你的需求和环境,你可以选择全局代理配置、Nginx代理配置、环境变量配置或应用程序层面的配置。

最终修改conf/dokuwiki.php里的proxy相关hostport即可。

插件手动安装

413 Request Entity Too Large

修改sudo vim /etc/nginx/sites-enabled/default

1
2
3
4
5
server {
...
client_max_body_size 100M;
...
}

测试并应用

1
2
sudo nginx -t
sudo systemctl restart nginx

gitbacked Plugin 同步修改和资料

  1. 安装:管理->扩展管理器->搜索安装

  2. 为了之后在线修改网页内容,能及时同步到git仓库,修改conf/local.php, 添加

    1
    2
    $conf['datadir'] = './data/gitrepo/wiki/pages';
    $conf['mediadir'] = './data/gitrepo/wiki/media';

情况一

移动文件夹

1
2
3
4
cd data
mkdir -p gitrepo/wiki
mv pages gitrepo/wiki
mv media gitrepo/wiki

情况二

只能克隆仓库到/var/www/html

  1. 配置gitbacked Plugin插件相关选项
    1. 管理->配置管理器repoPath to ./data/gitrepo, 并保存
    2. 勾选pushAfterCommit, 并保存。
  2. 配置git仓库
    1. 保证容器里git 命令正常运行(attach bash 测试)
    2. 由于dokuwiki使用的是www-data用户,为了能访问仓库,需要在/var/www/下配置.ssh的相关公私钥(如果是docker,要在docker里),并添加到github账户。
    3. www-data没有terminal, 使用其他用户clone./data/gitrepo。然后修改所属chown www-data:www-data -R gitrepo
1
2
3
4
5
6
7
8
9
10
root@f46a6515abeb:/var/www# mkdir .ssh
root@f46a6515abeb:/var/www# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /var/www/.ssh/id_rsa
xxx

root@f46a6515abeb:/var/www# cat .ssh/id_rsa.pub
xxx

sudo chown -R www-data:www-data /var/www/.ssh

测试: 之后每次修改保存时,都会触发修改。

git push using token

git remote set-url origin https://Kirrito-k423:<access token>@github.com/Kirrito-k423/dokuwiki-data.git

但是在docker里和外面有时会失效,原因不明

1
2
DokuWiki Setup Error
Something unforeseen has happened: Git committing or pushing failed: Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

[^3]

只能root用户 crontab -e

1
* */1 * * * cd /root/doku-tsj/data/data/gitrepo ; git push >> /root/dokuwiki.log 2>&1 && date >> /root/dokuwiki.log

参考文献

[^2]: dukuwiki in apache2

[^3]: DokuWiki Setup Error

Author

Shaojie Tan

Posted on

2023-11-11

Updated on

2026-03-11

Licensed under