在CentOS5.4中安装Lighttpd+MySQL+PHP5 (LLMP)

三月 4, 2010 by · Leave a Comment 

Lighttpd是一款安全,高效,基于标准且为高速环境设计的web服务器。这篇教程将教你如何在一台CentOS 5.4中安装Lighttpd+PHP5(FastCGI模式)+MySQL。

我已经测试无误,你可以放心使用。

1 前言备注

在这篇教程中,我使用的主机名为server1.example.com,ip地址是192.168.0.100。这些设置可能与你想要的有所不同,所以你必须在适当的地方修改一下。

2安装MySQL 5.0

用下列命令安装MySQL:

yum install mysql mysql-server

然后我们为MySQL创建系统启动链接(这样的话,MySQL就会随着系统启动而启动),并启动MySQL服务器:

chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

运行

mysqladmin -u root password yourrootsqlpassword
mysqladmin -h server1.example.com -u root password yourrootsqlpassword

来为root用户设置一个密码(否则任何人都可以访问你的MySQL数据库!)

3安装

Lighttpd并没有在CentOS 5.4的官方源中,RPMforge源中有(请参看see http://dag.wieers.com/rpm/FAQ.php#B2)我们安装RHEL5的RPMforge包,同样适用于CentOS5.4:

如果你是一个x86_64位的系统:

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

如果你是i386的系统:

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

然后,我们使用下列命令安装Lighttpd:

yum install lighttpd

现在配置下系统使得Apache能够随着系统启动而启动…并启动它:

chkconfig --levels 235 lighttpd on
/etc/init.d/lighttpd start

现在打开浏览器,访问http://192.168.0.100,你就应该能看到下列页面了。

在CentOS 5.4中Lighttpd的默认文档路径在is /srv/www/lighttpd(在这里里没有index.html文件在文件夹里,所以会出现404错误),配置文件在is /etc/lighttpd/lighttpd.conf。

4安装 PHP5

我们让PHP5在Lighttpd中以FastCGI的模式工作,因此我们安装lighttpd-fastcgi 和 php-cli包:

yum install lighttpd-fastcgi php-cli

5 配置 Lighttpd 和 PHP5

要使Lighttpd支持PHP5,我们必须修改两个文件,, /etc/php.ini 和 /etc/lighttpd/lighttpd.conf.首先我们打开/etc/php.ini文件,并在文件的最后加入这一行line cgi.fix_pathinfo = 1:

然后打开/etc/php.ini文件,并在文件的最后加入这一行line cgi.fix_pathinfo = 1:

vi /etc/php.ini
[...]
cgi.fix_pathinfo = 1

然后我们打开open /etc/lighttpd/lighttpd.conf,然后取消注释”mod_fastcgi”,在server.modules部分:

vi /etc/lighttpd/lighttpd.conf
[...]
server.modules              = (
#                               "mod_rewrite",
#                               "mod_redirect",
#                               "mod_alias",
                                 "mod_access",
#                               "mod_cml",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
                                 "mod_fastcgi",
#                               "mod_proxy",
#                               "mod_simple_vhost",
#                               "mod_evhost",
#                               "mod_userdir",
#                               "mod_cgi",
#                               "mod_compress",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )
[...]

然后,向下翻滚,我们同样取消注释掉fastcgi.server参数-确保你在socket中使用/tmp/php-fastcgi.socket:

[...]
#### fastcgi module
## read fastcgi.txt for more info
## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server             = ( ".php" =>
                               ( "localhost" =>
                                 (
                                   "socket" => "/tmp/php-fastcgi.socket",
                                   "bin-path" => "/usr/bin/php-cgi"
                                 )
                               )
                            )
[...]

然后我们重启Lighttpd:

/etc/init.d/lighttpd restart

6 测试PHP5/获取PHP5安装后的详细信息

网站的默认文档路径是 /srv/www/lighttpd。我们现在在这个文件夹中创建一个小型PHP(info.php)文件,并在;浏览器中访问它。这个文件会显示关于PHP安装的大量的细节,例如PHP的版本。

vi /srv/www/lighttpd/info.php
<?php
phpinfo();
?>

现在我们在浏览器中访问这个文件(例如http://192.168.0.100/info.php):

正如你所看到的一样,PHP5已经正常工作了,并且在Server API这一行中显示的Apache是以Apache2.0 Handler模式工作的。如果你向下翻页,你将会看到已经安装了PHP5的所有的模块。MySQL没有在这里列出来,也就意味着目前PHP5并不支持 MySQL。

7 让PHP5支持MySQL

我们安装php-mysql这个包既可以使MySQL支持php了。在这里最好也安装其他的PHP5模块,这些模块也许你会在其他的应用中用到。你可以使用下列命令先搜索一下PHP5的模块:

yum search php

选取你需要的模块,并使用下列命令安装它们:

yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

现在重启Lighttpd:

/etc/init.d/lighttpd restart

现在在浏览器中刷新http://192.168.0.100/info.php,并再次翻到模块部分。你就应该能在这里找到很多新模块,其中就包括了MySQL模块。

About admin

注意:

1、本站启用了审核机制,你的留言可能稍后才会显示,请不要重复提交,谢谢。
2、留言时的头像是Gravatar提供的服务。想设置的看这里
3、评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha