如何在 Ubuntu 22.04 上安装 DokuWiki
本教程适用于这些操作系统版本
- Ubuntu 22.04(果酱水母)
- Ubuntu 18.04(仿生海狸)
在此页
- 先决条件
- 安装 Apache 和 PHP
- 安装 DokuWiki Ubuntu 22.04
- 为 DokuWiki 创建一个 Apache 虚拟主机
- 在 DokuWiki 网站上启用 SSL
- 访问 DokuWiki
- 设置自动续订
- 结论
DokuWiki 是一个用 PHP 编写的简单易用且用途广泛的 wiki 软件。它是免费的、开源的,并使用简单的文件格式来存储其数据,而不是使用任何数据库系统。它提供了许多功能,可帮助您轻松扩展和优化您的 wiki 站点。由于其简洁易读的语法,它越来越受欢迎。使用 Dokuwiki,您可以通过 Dokuwiki 网页面板创建您的个人或企业网站。
在本教程中,我们将向您展示如何在 Ubuntu 22.04 上使用 Apache 和 Lets Encrypt SSL 证书安装 DokuWiki。
先决条件
- 一台运行 Ubuntu 22.04 的服务器。
- 指向您的服务器的有效域名。
- 在您的服务器上配置了根密码。
安装 Apache 和 PHP
首先,您需要在您的系统上安装 Apache 网络服务器、PHP 和其他 PHP 库。您可以通过运行以下命令来安装所有这些:
apt-get install apache2 php php-gd php-xml php-json -y
安装所有包后,启动 Apache 服务并使用以下命令使其在引导时启动:
systemctl start apache2
systemctl enable apache2
完成后,您可以继续下一步。
安装 DokuWiki Ubuntu 22.04
接下来,访问DokuWiki官方下载页面,复制下载地址,使用以下命令下载最新版本的DokuWiki:
wget https://download.dokuwiki.org/out/dokuwiki-24117f7f9e0362c4b1782ff29220b0ab.tgz
下载完成后,在 Apache web 根目录中创建一个 DokuWiki 目录并提取 DokuWiki:
mkdir /var/www/html/dokuwiki
tar -xvzf dokuwiki-24117f7f9e0362c4b1782ff29220b0ab.tgz -C /var/www/html/dokuwiki/ --strip-components=1
接下来,使用以下命令复制示例 .htaccess 文件:
cp /var/www/html/dokuwiki/.htaccess{.dist,}
接下来,将 dokuwiki 的所有权更改为 www-data:
chown -R www-data:www-data /var/www/html/dokuwiki
完成后,您可以继续下一步。
为 DokuWiki 创建一个 Apache 虚拟主机
接下来,您需要创建一个 Apache 虚拟主机配置文件来为 DokuWiki 网站提供服务。您可以使用以下命令创建它
nano /etc/apache2/sites-available/dokuwiki.conf
添加以下行:
<VirtualHost *:80>
ServerName doku.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>
完成后保存并关闭文件。然后,启用 DokuWiki 虚拟主机配置文件并使用以下命令重新加载 Apache 服务:
a2ensite dokuwiki.conf
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 Sat 2022-06-25 15:44:31 UTC; 4min 30s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 52450 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 52131 (apache2)
Tasks: 6 (limit: 4579)
Memory: 16.9M
CPU: 331ms
CGroup: /system.slice/apache2.service
??52131 /usr/sbin/apache2 -k start
??52454 /usr/sbin/apache2 -k start
??52455 /usr/sbin/apache2 -k start
??52456 /usr/sbin/apache2 -k start
??52457 /usr/sbin/apache2 -k start
??52458 /usr/sbin/apache2 -k start
Jun 25 15:44:30 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...
此时,Apache Web 服务器已配置为服务 DokuWiki 站点。您现在可以继续在您的网站上安装 Lets Encrypt SSL。
在 DokuWiki 网站上启用 SSL
要在 DokuWiki 上启用 SSL,您需要在系统中安装 Certbot 客户端。 Certbot 是一个用于下载和管理 SSL 的 Lets Encrypt 工具。
您可以使用以下命令安装 Certbot:
apt-get install certbot python3-certbot-apache -y
安装后,运行以下命令为您的网站安装 Lets Encrypt SSL:
certbot --apache -d dokuwiki.linuxbuz.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):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.linuxbuz.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,如下所示:
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 并按 Enter 键开始该过程。安装完成后,您应该得到以下输出:
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.linuxbuz.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=dokuwiki.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/dokuwiki.linuxbuz.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/dokuwiki.linuxbuz.com/privkey.pem
Your cert will expire on 2020-09-05. 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 站点已使用 Lets Encrypt SSL 进行保护。
访问 DokuWiki
现在,打开您的 Web 浏览器并输入 URL https://dokuwiki.linuxbuz.com/install.php。您应该会看到 DokuWiki 安装屏幕:


提供您的 wiki 名称、管理员用户名、密码、电子邮件,选择您的策略,然后单击“保存”按钮。您将被重定向到以下页面:

点击“你的新 DokuWiki”。您应该看到以下屏幕:

单击“登录”按钮。您将被重定向到 DokuWiki 登录屏幕,如下所示:

提供您的管理员用户名、密码,然后单击“登录”按钮。您应该在以下屏幕上看到 DokuWiki 仪表板:

设置自动续订
默认情况下,Let's Encrypt 证书的有效期为 90 天。因此,您需要设置一个 cron 作业来自动更新 SSL 证书。创建每周甚至每天运行的 cron 作业是安全的。
如果要手动续订 SSL 证书,请运行以下命令:
certbot renew --dry-run
您可以设置一个 cron 作业,通过编辑以下文件在每天早上 6:00 自动更新 SSL 证书:
crontab -e
添加以下行:
00 06 * * * root /usr/bin/certbot renew >/dev/null 2>&1
完成后保存并关闭文件。
结论
恭喜!您已经在 Ubuntu 22.04 上成功安装了 DokuWiki 并使用 Lets Encrypt SSL 对其进行了保护。您现在可以使用 DokuWiki 创建自己的 wiki 站点。如果您有任何问题,请随时问我。