本教程适用于以下操作系统版本
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 18.04 (Bionic Beaver)
本页内容
- 先决条件
- 安装 Apache 和 PHP
- 在 Ubuntu 22.04 上安装 DokuWiki
- 为 DokuWiki 创建 Apache 虚拟主机
- 在 DokuWiki 网站上启用 SSL
- 访问 DokuWiki
- 设置自动续期
- 结论
DokuWiki 是一款简单、易用且高度通用的 wiki 软件,使用 PHP 编写。它是免费的、开源的,并使用简单的文件格式来存储数据,而不使用任何数据库系统。它提供了许多功能,可帮助你轻松地扩展和优化你的 wiki 站点。由于其简洁且可读性强的语法,它正变得越来越流行。使用 DokuWiki,你可以通过 DokuWiki 的 Web 面板创建个人或商业网站。
在本教程中,我们将向你展示如何在 Ubuntu 22.04 上使用 Apache 和 Let's Encrypt SSL 证书安装 DokuWiki。
先决条件
- 一台运行 Ubuntu 22.04 的服务器。
- 一个已指向你服务器的有效域名。
- 你的服务器上已配置 root 密码。
安装 Apache 和 PHP
首先,你需要在系统上安装 Apache 网页服务器、PHP 以及其他 PHP 库。你可以通过运行以下命令来安装它们:
apt-get install apache2 php php-gd php-xml php-json -y
安装完所有软件包后,使用以下命令启动 Apache 服务并使其在开机时自动启动:
systemctl start apache2
systemctl enable apache2
完成后,你可以继续下一步。
在 Ubuntu 22.04 上安装 DokuWiki
接下来,访问 DokuWiki 官方下载页面,复制下载 URL,并使用以下命令下载最新版本的 DokuWiki:
wget https://download.dokuwiki.org/out/dokuwiki-24117f7f9e0362c4b1782ff29220b0ab.tgz
下载完成后,在 Apache 网页根目录中创建一个 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 网页服务器已配置为提供 DokuWiki 站点服务。你现在可以继续在你的网站上安装 Let's Encrypt SSL。
在 DokuWiki 网站上启用 SSL
要在 DokuWiki 上启用 SSL,你需要在系统中安装 Certbot 客户端。Certbot 是一个 Let's Encrypt 工具,用于下载和管理 SSL。
你可以使用以下命令安装 Certbot:
apt-get install certbot python3-certbot-apache -y
安装完成后,运行以下命令为你的网站安装 Let's 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): [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.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 站点已通过 Let's Encrypt SSL 进行保护。
访问 DokuWiki
现在,打开你的网页浏览器并输入 URL https://dokuwiki.linuxbuz.com/install.php 。你应该会看到 DokuWiki 安装界面:


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

点击“你的新 DokuWiki”。你应该会看到以下界面:

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

输入你的管理员用户名、密码,然后点击“登录”按钮。你应该在以下界面上看到 DokuWiki 仪表板:

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