Debian下安装lighttpd

2015-02-11 10:34:57    2015-02-11 15:59:57

现在大部分的VPS上好像都用Apache和Nginx比较多,对lighttpd的关注貌似不多,其实比起来,lighttpd的性能不比nginx差到哪里去,lighttpd安装和配置相对简单,方便易用,比Apache要节省资源多了,所以非常适合在小内存的低端VPS上使用。在安装前可以先使用我前面写的命令来清理VPS

安装Lighttpd

在Debian安装lighttpd,只需要一条命令就够了

apt-get install lighttpd

安装PHP

这时候,用浏览器打开VPS的地址,应该就能够看到默认的网页了。不过现在一般的网站都需要PHP的支持,所以还需要安装PHP。把能装的都装上:

apt-get install php5-cgi php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-xsl

新建用户名

接下来先新建一个用户名lighttpd专门给它用:

useradd -d /home/lighttpd -m -s /bin/bash lighttpd

配置Lighttpd

再来修改lighttpd的配置文件,改成如下:

server.modules = (
        "mod_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
        "mod_rewrite",
        "mod_fastcgi",
)

server.port                 = 80
server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "lighttpd"
server.groupname            = "lighttpd"

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm",
                               " index.lighttpd.html" )

url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

include_shell "/usr/share/lighttpd/use-ipv6.pl"

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

fastcgi.server += ( ".php" =>
        ((
                "bin-path" => "/usr/bin/php-cgi",
                "socket" => "/tmp/php.socket",
                "max-procs" => 3,
                "bin-environment" => (
                        "PHP_FCGI_CHILDREN" => "5",
                        "PHP_FCGI_MAX_REQUESTS" => "10000"
                ),
                "bin-copy-environment" => (
                        "PATH", "SHELL", "USER"
                ),
                "broken-scriptfilename" => "enable"
        ))
)

其中的max-procs参数和PHP_FCGI_CHILDREN的数量可以视需要自己更改

修改权限

保存后再修改一下lighttpd log的权限

chown -R lighttpd:lighttpd /var/log/lighttpd

重启Lighttpd

最后再重启一下lighttpd,就大功告成了

service lighttpd restart

这时候可以去/var/www目录下随便写一个hello world之类的index.php文件,测试一下能不能正常显示。

这样,一个由lighttpd建立起来的基本php网络架构就完成了。

安装MySQL支持

如果还需要MySQL的支持,也很简单,只需要再加上一条命令就行了:

apt-get install mysql-server

注:现在mysql-server默认的好像是5.5版本,我试了在128/256的小内存VPS上装会出错,网上有人报同样的错误,不过除了安装5.1版本外,好像也没什么解决方案,所以对小内存的机子来说,上面这条命令就要变成apt-get install mysql-server-5.1

如果还需要PHP对MySQL的支持,那就需要再运行

apt-get install php5-mysql