读书人

安装Lighttpd并在其下安装PHP,该怎么处

发布时间: 2012-03-16 16:34:56 作者: rapoo

安装Lighttpd并在其下安装PHP
原地址:http://doc.zenw.org/linux/ch02s03.html#id2844165


Lighttpd

一个好用的轻巧的webservice


编译安装

-- 1.下载 --

下载相关软件


$ sudo apt-get install libpcre3*


cd /usr/local/src/

wget http://www.lighttpd.net/download/lighttpd-1.4.15.tar.gz

tar zxvf lighttpd-1.4.15.tar.gz

cd lighttpd-1.4.15


-- 2.安装 --

编译安装


./configure --prefix=/usr/local/lighttpd-1.4.15 \

--with-bzip2 \

--with-memcache

make

make install


-- 3.创建目录与配置文件 --

创建目录与配置文件

ln -s /usr/local/lighttpd-1.4.15/ /usr/local/lighttpd

mkdir -p /www/pages

mkdir /www/logs

mkdir /usr/local/lighttpd/htdocs

mkdir /usr/local/lighttpd/logs

mkdir /usr/local/lighttpd/etc

cp ./doc/lighttpd.conf /usr/local/lighttpd/etc/

cd /usr/local/lighttpd/


-- 4.修改配置文件 --

配置lighttpd.conf

vi etc/lighttpd.conf

找到 server.modules

删除 mod_fastcgi 前的注释

跟据你的需求修改下面定义

server.document-root = "/usr/local/lighttpd/htdocs/"

server.errorlog = "/usr/local/lighttpd/logs/lighttpd.error.log"

accesslog.filename = "/usr/local/lighttpd/logs/access.log"

注释 $HTTP["url"]

#$HTTP["url"] =~ "\.pdf$" {

# server.range-requests = "disable"

#}


-- 5.运行 --

运行lighttpd

/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf


测试

curl http://ip/ 因为/www/pages/下没有HTML页面所以返回:

404 - Not Found


-- 6.制作启动脚本 --

每次启动lighttpd时我们要指定配置文件的位置,停止lighttpd时要先找到进程号,然后用kill发送停止信号,有点太麻烦了。好在 lighttpd自带了一个脚本程序能辅助完成这些操作,只要稍微改改就能用了,那就是源码目录doc/rc.lighttpd和doc /rc.lighttpd.redhat,后者专用于RedHat Linux。主要的改动之处在于:

...
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
LIGHTTPD_CONF_PATH="/usr/local/lighttpd-1.4.9/lighttpd.conf"
fi
...
lighttpd="/usr/local/lighttpd-1.4.9/usr/sbin/lighttpd"
...

用这个脚本管理lighttpd是不是方便多了。

-- 7.z.en写的简单的管理脚本 --

#!/bin/bash
# author: z.En Wong <w@zenw.org>


PREFIX=/usr/local/lighttpd/
PROG=$PREFIX/sbin/lighttpd
OPTIONS=" -f /usr/local/lighttpd/lighttpd.conf"
restart(){
stop
start


}

start(){

$PROG$OPTIONS
}
stop(){
PID=`pidof lighttpd`
kill $PID

}

case "$1" in
stop)
stop
;;
start)
start
;;
restart)
restart
;;
*)
echo "{start|stop|restart}"
esac



安装PHP(FastCGI)

-- 1. 下载PHP --

cd /usr/local/src/
wget http://cn2.php.net/get/php-5.2.3.tar.bz2/from/cn.php.net/mirror
tar jxvf php-5.2.3.tar.bz2


cd php-5.2.3

-- 2. configure --

./configure --prefix=/usr/local/php-5.2.3 \
--with-config-file-path=/usr/local/php-5.2.3/etc \
--enable-fastcgi \
--enable-force-cgi-redirect \
--with-curl \
--with-gd \
--with-ldap \
--with-snmp \
--enable-zip \
--enable-exif \
--with-pdo-mysql \
--with-pdo-pgsql \

make
make test
make install


其它有用的模块

--enable-pcntl

-- 3. 符号连接 --

ln -s /usr/local/php-5.2.3 /usr/local/php
ln -s /usr/local/php/bin/php /usr/local/bin/php

-- 4. php.ini --

cp php.ini-dist /usr/local/php/etc/php.ini

-- 5. env --

PHP_FCGI_CHILDREN=384

-- 6. 使用 php -v FastCGI 安装情况 --

php -v 或 php-cgi -v

显示(cgi-fcgi)表示正确

# cd /usr/local/php/
# bin/php -v
PHP 5.2.2 (cgi-fcgi) (built: May 25 2007 15:50:28)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies


(cgi-fcgi)不能正常工作

PHP 5.2.2 (cli) (built: May 25 2007 15:50:28)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies


使用 php -m 或php-cgi -m 查看PHP Modules

# bin/php -m
[PHP Modules]
cgi-fcgi
ctype
date
dom
filter
gd
hash
iconv
json
ldap
libxml
mssql
pcre
PDO
pdo_mysql
pdo_sqlite
posix
Reflection
session
SimpleXML
snmp
SPL
SQLite
standard
tokenizer
xml
xmlreader
xmlwriter
zip

[Zend Modules]


- apt-get install -

$ sudo apt-get install php5 php5-cli php5-cgi


找到 fastcgi.server 去掉注释

bin-path 改为PHP程序安装目录

fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",#这个文件如果不存在,需要touch一下
"bin-path" => "/usr/local/php/bin/php"
)
)
)


- 下面例子更复杂一些 -

-- 1. /usr/local/lighttpd/etc/lighttpd.conf --

include /usr/local/lighttpd/etc/php-fastcgi.conf

-- 2. /usr/local/lighttpd/etc/php-fastcgi.conf --



fastcgi.server = ( ".php" =>
( "localhost" =>
( "socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php/bin/php",
"min-procs" => 1,
"max-procs" => 5,
"max-load-per-proc" => 4,
"idle-timeout" => 20
)
)
)


-- 3. PHP FastCGI环境测试 --

echo " <?php phpinfo(); ?>" > /www/pages/index.php

curl http://127.0.0.1/index.php


更多内容可访问:
http://www.zenw.org
http://doc.zenw.org
http://doc.zenw.org/linux
http://doc.zenw.org/mysql
http://doc.zenw.org/developer

[解决办法]


重复发帖了吧?

感谢分享
[解决办法]
新手学习

读书人网 >应用服务器

热点推荐