本教程适用于以下操作系统版本
- Debian 12 (Bookworm)
- Debian 11 (Bullseye)
- Debian 9 (Stretch)
本页目录
- 先决条件
- 开始
- 安装 Apache 和 PHP
- 安装 DokuWiki
- 为 DokuWiki 创建 Apache 虚拟主机
- 使用 Let's Encrypt SSL 保护 DokuWiki
- 设置 Let's Encrypt SSL 证书自动续期
- 访问 DokuWiki
- 结论
DokuWiki 是一款用 PHP 编写的免费、开源且功能强大的 Wiki 软件应用程序。它使用文件来存储其数据,而不是使用数据库。它简单、轻量,允许您通过 Web 浏览器创建和编辑网站。它提供了许多功能,使您可以轻松地扩展和优化您的网站。由于其简洁易读的语法、易于维护、备份和集成,它被许多用户使用。
在本教程中,我将向您展示如何在 Debian 11 上使用 Apache 和 Let's Encrypt SSL 安装 DokuWiki。
先决条件
- 一台运行 Ubuntu 20.04 的服务器。
- 一个指向您服务器 IP 的有效域名。
- 服务器上已配置 root 密码。
开始
在开始之前,建议将系统软件包更新到最新版本。您可以通过运行以下命令来更新它们:
apt-get update -y
所有软件包更新完成后,您可以继续下一步。
安装 Apache 和 PHP
DokuWiki 运行在 Apache 或 Nginx 上,并用 PHP 语言编写。因此您需要在服务器上安装 Apache、PHP 和其他所需的扩展。您可以通过运行以下命令来安装它们:
apt-get install apache2 php php-gd php-xml php-json -y
所有软件包安装完成后,启动 Apache 服务并使其在系统重启时自动启动:
systemctl start apache2
systemctl enable apache2
完成后,您可以继续下一步。
安装 DokuWiki
首先,进入 DokuWiki 下载页面,并使用以下命令下载最新版本的 DokuWiki:
wget https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz
下载完成后,在 Apache Web 根目录内为 DokuWiki 创建一个目录:
mkdir /var/www/html/dokuwiki
接下来,使用以下命令将下载的文件解压到 DokuWiki 目录:
tar -xvzf dokuwiki-stable.tgz -C /var/www/html/dokuwiki/ --strip-components=1
接下来,使用以下命令复制一些必要的文件:
cp /var/www/html/dokuwiki/.htaccess{.dist,}
接下来,为 DokuWiki 目录设置适当的所有权:
chown -R www-data:www-data /var/www/html/dokuwiki
完成后,您可以继续下一步。
为 DokuWiki 创建 Apache 虚拟主机
接下来,您需要创建一个 Apache 虚拟主机配置文件,以便在互联网上托管 DokuWiki。您可以使用以下命令来创建它:
nano /etc/apache2/sites-available/dokuwiki.conf
添加以下行:
<VirtualHost *:80>
ServerName dokuwiki.example.com
DocumentRoot /var/www/html/dokuwiki
<Directory ~ "/var/www/html/dokuwiki/(bin/|conf/|data/|inc/)">
<IfModule mod_authz_core.c>
AllowOverride All
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Deny from all
</IfModule>
</Directory>
ErrorLog /var/log/apache2/dokuwiki_error.log
CustomLog /var/log/apache2/dokuwiki_access.log combined
</VirtualHost>
保存并关闭文件,然后使用以下命令启用虚拟主机配置文件:
a2ensite dokuwiki.conf
接下来,重新加载 Apache 以应用更改。
systemctl reload apache2
您还可以使用以下命令检查 Apache 状态:
systemctl status apache2
您将得到以下输出:
? apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-10-24 04:01:29 UTC; 9min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 27698 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Tasks: 77 (limit: 4691)
Memory: 12.5M
CGroup: /system.slice/apache2.service
??21346 /usr/sbin/apache2 -k start
??27703 Passenger watchdog
??27706 Passenger core
??27711 Passenger ust-router
??27729 /usr/sbin/apache2 -k start
??27730 /usr/sbin/apache2 -k start
使用 Let's Encrypt SSL 保护 DokuWiki
配置 Apache 后,建议使用 Let's Encrypt SSL 证书来保护您的维基站点。为此,您需要在系统中安装 Certbot 客户端。Certbot 是一个易于使用的客户端,它从 Let's Encrypt(一个由 EFF、Mozilla 等发起的开放证书颁发机构)获取证书,并将其部署到 Web 服务器。使用 Certbot Let's Encrypt 客户端,您可以轻松地为您的域名下载、安装和续期 SSL 证书。
您可以使用以下命令安装 Certbot:
apt-get install certbot python3-certbot-apache -y
Certbot 客户端成功安装后,运行以下命令为您的网站安装 Let's Encrypt SSL:
certbot --apache -d dokuwiki.example.com
系统将要求您提供有效邮箱并接受服务条款,如下所示:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): [email protected] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for dokuwiki.example.com Enabled Apache rewrite module Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/apache2/sites-available/dokuwiki-le-ssl.conf Enabled Apache socache_shmcb module Enabled Apache ssl module Deploying Certificate to VirtualHost /etc/apache2/sites-available/dokuwiki-le-ssl.conf Enabling available site: /etc/apache2/sites-available/dokuwiki-le-ssl.conf
接下来,选择是否将 HTTP 流量重定向到 HTTPS,或配置 Nginx 将所有流量重定向到安全的 HTTPS 访问,如下面的输出所示:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
输入 2 并按回车键开始该过程。安装完成后,您应该会得到以下输出:
Enabled Apache rewrite module Redirecting vhost in /etc/apache2/sites-enabled/dokuwiki.conf to ssl vhost in /etc/apache2/sites-available/dokuwiki-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://dokuwiki.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=dokuwiki.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/dokuwiki.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/dokuwiki.example.com/privkey.pem Your cert will expire on 2021-01-25. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
此时,您的 Dokuwiki 站点已使用 Let's Encrypt SSL 进行了保护。您现在可以使用 HTTPS 协议安全地访问您的站点。
设置 Let's Encrypt SSL 证书自动续期
默认情况下,Let's Encrypt 证书的有效期为 90 天。因此,您需要设置一个 cron 任务来自动续期 SSL 证书。创建一个每周甚至每天运行的 cron 任务是安全的。
如果您想手动续期 SSL 证书,请运行以下命令:
certbot renew --dry-run
您可以通过编辑以下文件来设置一个每天上午 10:00 自动续期 SSL 证书的 cron 任务:
crontab -e
添加以下行:
00 10 * * * root /usr/bin/certbot renew >/dev/null 2>&1
完成后,保存并关闭文件。
访问 DokuWiki
现在,打开您的 Web 浏览器并输入 URL https://dokuwiki.example.com/install.php 。您应该会看到 DokuWiki 安装界面:

提供您的维基名称、管理员用户名、密码、邮箱,选择您的策略并点击 Save 按钮。您将被重定向到以下页面:

点击 " your new DokuWiki "。您应该会看到以下界面:

点击 Login 按钮。您将被重定向到如下所示的 DokuWiki 登录界面:

提供您的管理员用户名和密码,然后点击 Log In 按钮。您将在以下界面看到 DokuWiki 控制面板:

结论
恭喜!您已在 Debian 11 上成功安装 DokuWiki,并使用 Let's Encrypt SSL 对其进行了保护。您现在可以开始使用 DokuWiki 创建您的第一个网站。如有任何问题,请随时问我。