其实,你只需要1分钟就能建立一个LNMP环境。需要Debian或者Ubuntu作为系统。


# wget http://github.com/lowendbox/lowendscript/raw/master/setup-debian.sh
...
# bash setup-debian.sh system
...
# bash setup-debian.sh exim4
...
# bash setup-debian.sh nginx
...
# bash setup-debian.sh mysql
...
# bash setup-debian.sh php
...
# bash setup-debian.sh wordpress blog.example.com

来源是著名的LEB Script。如果你和我一样也喜欢Lighttpd,可以参考一下方法,在3台Debian 32位的VPS上测试通过。

首先设置基本系统和MySQL

先选择最快的源

# apt-get install netselect-apt
...
# netselect-apt -n
...
# cp sources.list /etc/apt/sources.list
# apt-get update && apt-get upgrade

我比较懒,直接用了LEB Script:

# bash setup-debian.sh system
...
# bash setup-debian.sh exim4
...
# bash setup-debian.sh mysql
然后搞定Lighttpd和PHP
# apt-get install lighttpd

Lighttpd的 simple-vhost 模块是否启用

# lighttpd-enable-mod simple-vhost

然后建立虚拟主机,因为simple-vhost模块,所以这一步很简单,比Nginx简单多了,这是我喜欢Lighttpd的一个原因。

mkdir -p /var/www/hi.insraq.me/html

然后去你的域名注册商添加一条A记录,比如我,把@hi.insraq.com@解析到我的VPS的IP,直接通过hi.insraq.com访问网站了。

接着搞定PHP
# apt-get install php5-cgi php5-mysql php5-curl

然后修改配置,我喜欢用vim,如果不习惯可以用nano:

vi /etc/lighttpd/conf-enabled/10-cgi-php.conf

添加以下的的配置:

server.modules += ("mod_cgi")
cgi.assign = (".php" => "/usr/bin/php5-cgi")

重启一下

/etc/init.d/lighttpd force-reload

然后就应该可以处理PHP了。由于MySQL在第一步已经搞定,所以LLMP的环境就完成了。

这是我的内存占用:

root@insraq:~# free
             total       used       free     shared    buffers     cached
Mem:       1048576      23516    1025060          0          0          0
-/+ buffers/cache:      23516    1025060
Swap:            0          0          0
再补充一下phpMyAdmin的建立
apt-get install phpmyadmin

他会让你选服务器,什么都别选,我们要自己配置。

# vi /etc/lighttpd/conf-enabled/hi.insraq.me.conf

加入以下内容:

$HTTP["host"] == "hi.insraq.me" {
    alias.url += ("/phpmyadmin" => "/usr/share/phpmyadmin")    
    server.error-handler-404 = "/index.php"
}

第二行其实和phpMyAdmin没关系,而是可以解决WordPress和TextPattern等等很多CMS的Clean URL,不需要可以注释掉。

另外,为了安全考虑,关闭Lighttpd的目录列表。

# vi /etc/lighttpd/lighttpd.conf

把下面这行注释掉

#server.dir-listing = "enable"

现在我把英文站完全迁移到了hi.insraq.com,内存占用保持在30MB以下。

             total       used       free     shared    buffers     cached
Mem:        393216      27448     365768          0          0          0
-/+ buffers/cache:      27448     365768
Swap:            0          0          0