OpenBSD(4.1): Lighttpd(vhosts), PHP(FastCGI)
来自 ChinaUnix Wiki
目录 |
[编辑]
Summary
[编辑]
About This Document
| Wrote for: OpenBSD Version 4.1 |
![]() |
Contact the author: | |
|---|---|---|
| Author: | Bibby | |
| Website: | http://www.OpenBSDonly.org | |
| MSN: | michaelbibby#hotmail.com | |
| Mail/GTalk: | michaelbibby#gmail.com | |
[编辑]
About OpenBSD
- OpenBSD: "Only two remote holes in the default install, in more than 10 years!"
- 参考:OpenBSD简介
- 购买 OpenBSD 光盘是支持 OpenBSD 持续发展的重要途径。
- 用于实践、实验本文档的最佳方法是购买一套 OpenBSD 光盘,欢迎您通过 http://www.openbsd.org/orders.html#china 页面的联系方式与 Bibby 联系购买,或直接参与 OpenBSDonly.org 论坛。价格:
- CD(4.x -release):¥180。
- T-Shirt: ¥150。
[编辑]
ENV
- OpenBSD: 4.1 -release
- Lighttpd: 1.4.13p2(binary package)
- PHP: 5.1.6(binary packages)
- php5-fastcgi(use *UNOFFICIAL* ports). in 4.2 -release or -current, we have a fastcgi subpackage in ports/www/php5/core/.
[编辑]
Installation
# pkg_add lighttpd-1.4.13p2
[编辑]
Configuration: /etc/lighttpd.conf
[编辑]
server.username
server.username = "www"
[编辑]
server.groupname
server.groupname = "www"
[编辑]
Default Host
[编辑]
server.port
server.port = 80
[编辑]
server.document-root
server.document-root = "/var/www/lighttpd/vhosts/default/htdocs/"
[编辑]
server.errorlog
server.errorlog = "/var/www/lighttpd/vhosts/default/logs/lighttpd.error.log"
[编辑]
accesslog.filename
accesslog.filename = "/var/www/lighttpd/vhosts/default/logs/access.log"
[编辑]
Directories
创建目录:
# mkdir -p /var/www/lighttpd/vhosts/default/{htdocs,logs}
# chown -R www:www /var/www/lighttpd/vhosts/default/
[编辑]
Virtual Hosts
[编辑]
Modules
在 server.modules 部分将以下几个模块前的注释去掉:
- mod_simple_vhost
[编辑]
Hosts
这里将配置以下几个虚拟主机:
- www.bibby.org
- www.bibby2.org
对应的目录分别为:
# For virtual host: www.bibby.org /var/www/lighttpd/vhosts/bibby.org/ /var/www/lighttpd/vhosts/bibby.org/htdocs/ /var/www/lighttpd/vhosts/bibby.org/logs/
# For virtual host: www.bibby2.org /var/www/lighttpd/vhosts/bibby2.org/ /var/www/lighttpd/vhosts/bibby2.org/htdocs/ /var/www/lighttpd/vhosts/bibby2.org/logs/
[编辑]
Directories & Permissions
创建目录并设置正确的权限:
# mkdir -p /var/www/lighttpd/vhosts/bibby{,2}.org/{htdocs,logs}
# chown -R www:www /var/www/lighttpd/
[编辑]
Configuration
$HTTP["host"] == "www.bibby.org" {
server.document-root = "/var/www/lighttpd/vhosts/bibby.org/htdocs/"
server.errorlog = "/var/www/lighttpd/vhosts/bibby.org/logs/error"
accesslog.filename = "/var/www/lighttpd/vhosts/bibby.org/logs/access"
server.error-handler-404 = “/index.php”
}
$HTTP["host"] == "www.bibby2.org" {
server.document-root = "/var/www/lighttpd/vhosts/bibby2.org/htdocs/"
server.errorlog = "/var/www/lighttpd/vhosts/bibby2.org/logs/error"
accesslog.filename = "/var/www/lighttpd/vhosts/bibby2.org/logs/access"
server.error-handler-404 = “/index.php”
}
[编辑]
PHP support(as FastCGI)
[编辑]
php5-fastcgi
从以下地址下载对应版本的 Ports: http://download.pureftpd.org/OpenBSD/misc/ports/
我这里用的是针对 OpenBSD 4.1 -release 的 php5.1-with-fastcgi-openbsd-4.1.tar.gz。
先将原来的 Ports 备份:
# mv /usr/ports/www/php5 /usr/ports/www/php5.bak
然后将下载的 Ports 解压缩:
# tar zxf php5.1-with-fastcgi-openbsd-4.1.tar.gz -C /usr/ports/www/
如果已经安装了 php5-core,则只需要进 /usr/ports/www/php5/fastcgi 目录进行安装即可:
# cd /usr/ports/www/php5/fastcgi/ # make install
安装的包的名字是:
php5-fastcgi-5.1.6p0.tgz
它只安装了一个文件:
/usr/local/bin/php-fcgi
这就是 Lighttpd 需要的,用于提供 PHP 支持的模块。
[编辑]
/etc/lighttpd.conf
在 server.modules 中将 mod_fastcgi 模块前的注释符号去掉,然后在配置文件的最末尾添加以下内容:
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-fcgi"
)
)
)
这是指所有的虚拟主机都使用这个 fastcgi.server。如果需要为不同的虚拟主机设置不同的参数,只要放到对应的 $HTTP["host"] 的大括号内即可。比如:
$HTTP["host"] == "www.bibby.org" {
server.document-root = "/var/www/lighttpd/vhosts/bibby.org/htdocs/"
server.errorlog = "/var/www/lighttpd/vhosts/bibby.org/logs/error"
accesslog.filename = "/var/www/lighttpd/vhosts/bibby.org/logs/access"
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-fcgi"
)
)
)
}
[编辑]
/etc/rc.conf.local
lighttpd_flags="-f /etc/lighttpd.conf"
[编辑]
/etc/rc.local
# Start Lighttpd web server.
if [ X"${lighttpd_flags}" != X"NO" ]; then
echo -n ' lighttpd'
/usr/local/sbin/lighttpd ${lighttpd_flags}
fi
[编辑]
Resource Links
页面分类: OpenBSD | OpenBSDonly.org | Bibby

