最近着手用 WordPress Mu 和 bbPress 为身边朋友们做一个 Blog 小社区。这篇 post 是记录过程中的一些小问题和笔记,主要关于 WordPress Mu,下篇写 bbPress 安装。
我打算先在本地完成以后,再上传到服务器。所以本地要安装支持 WordPress 的服务,首先确保系统中安装了 Apache, PHP, MySQL 以及基于浏览器管理 MySQL 的 phpMyAdmin。或者直接安装 xampp ── 集成了 LAMP 环境。
- 要实现用户 Blog 二级域名的模式,为了更好在本地设置好,需要修改 hosts 文件把域名指向本地(*.localhost 是能够实现的)。Ubuntu 下 hosts 文件路径是 /etc/hosts,Windows 下的路径好像是 WINDOWS\system32\hosts。在 hosts 文件中的 “127.0.0.1 localhost” 后面增加你的域名,和你要测试的二级域名。因为 hosts 文件不支持泛域名解析,所以添加 “*.domain.tld” 是无效的,你只能根据你需要测试的二级域名逐个增加。
- 因为打算把 WorPress Mu 和 bbPress 绑定到两个不同的域名,非上下级目录关系,而我的机器只有一个内网 IP ,这时就需要开启 Apache 的虚拟主机功能。
- 创建配置文件 /etc/apache2/conf.d/virtual.conf
#
# We’re running multiple virtual hosts.
#
NameVirtualHost *
- 创建配置文件 /etc/apache2/conf.d/virtual.conf
- 创建网站的配置文件 /etc/apache2/sites-available/domain.tld
ServerAdmin webmaster@domain.tld
ServerName domain.tld
ServerAlias *.domain.tld - 配置 WordPress Mu 需求条件,可参考 WordPress Mu 官方的安装说明。
- 启用 rewrite 模块。注意:若未启用则会出现 “500 internal error” 错误。终端输入:$ sudo a2enmod rewrite(取消为:a2dismod)。
- 把 /etc/apache2/sites-enabled/000-default 里 标签中的 “AllowOverride None” 替换为 “AllowOverride FileInfo Options”。
- 为了 WordPress Mu 二级域名模式能够正常工作,在 标签里添加主机别名: “ServerAlias *.domain.tld”,在第二步已经做了。
- 接收不到邮件?
- 由于系统没有 sendmail 服务,WordPress Mu 默认使用 sendmail 发送邮件。解决方法:安装 sendmail,在终端输入 $ sudo apt-get install sendmail。
- 用 PHP 的 phpmailer 功能发送邮件,方法
注意:如果此行代码申明了两次则会使 Apache 不能正常启动,我就为解决这个错误费了些时间。
# Indexes + Directory Root.
DirectoryIndex
DocumentRoot /home/vin/www/domain.tld/public/
# CGI Directory
ScriptAlias /cgi-bin/ /home/vin/www/domain.tld/cgi-bin/
Options +ExecCGI
# Logfiles
ErrorLog /home/vin/www/domain.tld/logs/error.log
CustomLog /home/vin/www/domain.tld/logs/access.log combined
当然,你要确保你建立了这样的网站目录。
在终端输入:$ sudo a2ensite domain.tld,把 /etc/apache2/sites-available/domain.tld 连接到 /etc/apache2/sites-enabled/domain.tld,这样 domain.tld 的设置就被激活了(取消连接为:a2dissite)。在 Ubuntu Apache 的配置文件除 /etc/apache2/sites-available 和 /etc/apache2/mods-available 外都被 include 在 /etc/apache2/apache2.conf 里面了。
END…
Good words.