转移主机,使用了自己搭建的系统,响应速度方面Lighttpd口碑不错,决定使用 Lighttpd来构建新的主机。
安装完一基本的debian系统之后,先做一下系统升级。使用命令:
aptitude update
aptitude upgrade
然后开始安装Lighttpd,php5,mysql,这里参考了文章:
Installing Lighttpd With PHP5 And MySQL Support On Debian Etch
Lighttpd是一个安全,快速,标准兼容的Web伺服器,速度是其关键优点 ,因此适合对速度要求较高的场合。本教程介绍如何在Debian上安装lighttpd,安装并整合php5(通过fastcgi )和MySQL。
1、参数准备
这里主机域名以www.nufang.info为例,假设ip为192.168.1.6。
2、首先安装Lighttpd。
aptitude install lighttpd
系统会自动下载并安装lighttpd,并自动启动。
安装完毕,我们通过查看192.168.1.6可以看到下面的页面,表示lighttpd已经正常运行起来了。
默认情况下lighttpd的网页根目录和apache一样是/var/www,配置文件放在/etc/lighttpd/lighttpd.conf
3、安装php
lighttpd支持php使用的是cgi的方式。因此这里我们安装php-cgi。
aptitude install php5-cgi
4、配置lighttpd来支持php
php的配置文件php.ini放在/etc/php/cgi目录。
vim /etc/php5/cgi/php.ini
然后找到cgi.fix_pathinfo,修改为:
cgi.fix_pathinfo = 1
(cgi.fix_pathinfo的默认值就是1)
lighttpd的配置文件目录(/etc/lighttpd)有两个目录:conf-available conf-enabled .
这里conf-available方的是可以使用的配置模板,conf-enabled是已经启动的配置。如果希望lighttpd加载某个模块,只要将conf-available中的配置copy到conf-enabled中即可。
ls /etc/lighttpd/conf-available/
我们看到显示结果是:
05-auth.conf 10-proxy.conf 10-ssi.conf 10-userdir.conf
10-cgi.conf 10-rrdtool.conf 10-ssl.conf README
10-fastcgi.conf 10-simple-vhost.conf 10-status.conf
察看fastcgi配置的内容
more /etc/lighttpd/conf-available/10-fastcgi.conf
内容如下:
## FastCGI programs have the same functionality as CGI programs,
## but are considerably faster through lower interpreter startup
## time and socketed communication
##
## Documentation: /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
## http://www.lighttpd.net/documentation/fastcgi.htmlserver.modules += ( “mod_fastcgi” )
## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server = ( “.php” =>
((
“bin-path” => “/usr/bin/php-cgi”,
“socket” => “/tmp/php.socket”,
“max-procs” => 2,
“idle-timeout” => 20,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “4″,
“PHP_FCGI_MAX_REQUESTS” => “10000″
),
“bin-copy-environment” => (
“PATH”, “SHELL”, “USER”
),
“broken-scriptfilename” => “enable”
)))
lighttpd已经为我们写好了配置,没有什么好修改的,那么直接拷贝到conf-enabled即可:
cp /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-enabled
配置完毕。
下面我们检查一下结果是否正确。
首先重新启动lighttpd。
/etc/init.d/lighttpd restart
在/var/www/目录下新建一个php 脚本 info.php
vim /var/www/info.php
然后键入内容
<?php phpinfo(); ?>
在浏览器中输入192.168.1.6/info.php。应该可以看到熟悉的phpinfo页面。
5、安装mysql
aptitude install mysql-server mysql-client
然后初始化一下root密码
mysqladmin -u root password yourrootpassword.
yourrootpassword这里换成自己的root密码
核对结果
mysql -u -root -p
然后输入自己的密码,看能否正常登陆,可以正常登陆,表明安装成功,当然不放心也可以show database;
6、安装php的一些组件
aptitude search php5
我们可以看到大量的相关组件,按照需要选择其中的一些来安装。其中常用的php5-mysql php5-gd php5-imagick php5-xsl php5-xmlrpc。
然后安装这些组件:
aptitude install php5-mysql php5-gd php5-imagick php5-xsl php5-xmlrpc
系统会自动安装,安装完成后重新启动lighttpd就自动加载这些组件了。
/etc/init.d/lighttpd restart
然后我们再看192.168.1.6/info.php,此时已经列出mysql等组件的支持了