CentOS+lighttpd+php+mysql (fastcgi)环境的搭建(转)

       呵呵!觉得有必要把今晚的装lighttpd的经验和过程给记录下来! 第一次写这样的文章,有什么不足的地方请高手们指出并给与修正!下面开始!

 

第一步:系统的安装! 菜鸟的朋友们,可以先去linux系统的初级教程,再来看我的文章!

               跳过。我用的是CentOS5.5的!


二步:下载mysql并安装,地址是:http://www.mysql.com/downloads/mysql/5.1.html#downloads(需要用邮箱注册),现在最新版是                           5.1.54 的,我用的是5.0.56。

              #  /usr/sbin/groupadd mysql

             #  /usr/sbin/useradd   mysql  mysql

            #  tar -xzvf  mysql-5.0.56.tar.gz

           # cd  mysql-5.0.56

           #./configure  --prefix=/opt/mysql   --with-ldflags-client=-all-static  --with-ldflags-mysqld=-all-static   --with-assembler  --with-unix-socket-path=/opt/mysql/tmp/mysql.sock    --with-thread-safe-client  --with-mysqld-user=mysql     -with-extra-charsets=utf8,gbk,gb2312     --with-charset=utf8              (还有很多参数,读者可以根据自己的实际需要,带上哪些参数)。

        #make  &&  make  install

        安装完成之后要做的事情:

             1.拷贝mysql配置文件到/etc目录下,根据你的服务器的配置选择相应的配置文件,然后重名为my.cnf。

                  #cp  support-files/my-medium.cnf   /etc/my.cnf

             2.建立初始化数据库:

                  #cd   /opt/mysql

                  #./bin/mysql_install_db   

             3.更改相关目录的权限:

                   # chown  -R   root   .

                  # chgrp    -R   mysql   .

                  # chown    -R   mysql   var

             看看能不能启动起来:

                 #  /opt/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

 

                                

第三步 :从lighttpd官方网站上下载lighttpd软件,下载地址是:

                http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.28.tar.gz

      现在最新版本的是1.4.28的,下载下来之后对其进行解压:

                    # groupadd  lighttpd 

                    #useradd  -s  /sbin/nologin  -M -g lighttpd  lighttpd

                   #tar  -xzvf  lighttpd-1.4.28.tar.gz

                  #cd lighttpd-1.4.28

                 #./configure  --prefix=/opt/lighttpd  --with-pcre    --with-openssl    --with-mysql=/opt/mysql/bin/mysql_config

                # make && make install

 

         在第二步中要注意的有几点:

              a、--with-pcre  :lighttpd需要pcre的支持,你要确定你的系统已经装了pcre和pcre-devel软件包!不然他会报错的!

                      #yum   install   pcre

                      #yum install pcre-devel 

 

             b、--with-openssl :这个参数根据你的需要选择加不是不加,如果需要ssl支持的话,那你要确定你的系统中已经装了openssl和openssl-devel。

                     #yum  install  openssl

                    #yum  install  openssl-devel

 

              c、--with-mysql=/opt/mysql/bin/mysql_config  :  这个参数要特别注意,本人刚开始装的时候,误认为是mysql的安装目录,其实不是的,这里是mysql_config文件的路径。

 

              d、如果你遇到了bzip2的错误,你再把bzip2和bzip2-devel两个软件包装上。

                  #yum install bzip2

                  #yum  install  bzip2-devel

除了上述几个错误,基本上没有其他错误了!即使有其他的错误,只要能看得懂上面的错误提示,也没有什么大问题!安装完成之后,需要拷贝几个文件:

                 #  cd  lighttpd-1.4.28/doc/config

                 #mkdir -p /opt/lighttpd/etc

                 #  cp  lighttpd.conf  /opt/lighttpd/etc/

                #  cp  modules.conf  /opt/lighttpd/etc

                # cp  -a  conf.d/  /opt/lighttpd/etc

                # mkdir  -p /opt/lighttpd/run 

                # mkdir  -p  /opt/lighttpd/cache

                # mkdir  -p  /opt/lighttpd/logs

                # chown -R  lighttpd  /opt/lighttpd/

第四步:接下来,再安装php,下载地址是:http://cn.php.net/get/php-5.3.5.tar.gz/from/this/mirror,最新版的是5.3.5的,我用的是5.2.16                 的。安装php之前要做一些准备:(需要的软件包很多,因为我们不是实际应用,所以我有的软件包没提到)基本的几个软件包有                 以下几个:jpeg和jpeg-devel ,png  和png-devel,freetype和freetype-devel,libxml2和libxml2-devel,gd和gd-devel,libiconv,                  zlib和zlibdevel,mhash,libmcrypt等等。

                可以用yum安装的几个就不讲了。下面几个编译安装的(有的可以不安装的!)

                                                                             #  tar zxvf libiconv-1.13.tar.gz

                                                                             #  cd libiconv-1.13/

                                                                            # ./configure --prefix=/usr/local             

                                                                            #  make

                                                                            #  make install

                                                                            #   cd ../

                                                                      

                                                                          #  tar zxvf libmcrypt-2.5.8.tar.gz 

                                                                          #  cd libmcrypt-2.5.8/

                                                                          # ./configure

                                                                          #  make  &&  make install

                                                                          #  /sbin/ldconfig

                                                                          #  cd libltdl/

                                                                          # ./configure --enable-ltdl-install

                                                                         #  make  &&  make install 

                                                                         #   cd http://www.cnblogs.com/ 

           

                                                                        #   tar zxvf mhash-0.9.9.9.tar.gz

                                                                         #  cd mhash-0.9.9.9/

                                                                         # ./configure

                                                                          # make  &&  make install

            在php安装过程中报错的时候,看它是不是提示哪个包没有安装,如是这样的话,就缺哪个软件包就安装哪个咯!安装php:

                       # tar -xzvf php-5.2.16.tar.gz

                    给 php打个补丁(php-5.2.16-fpm-0.5.14.diff.gz:php进程管理器)下载地址:

                                        http://php-fpm.org/downloads/php-5.2.16-fpm-0.5.14.diff.gz

                     #  gzip -cd php-5.2.16-fpm-0.5.14.diff.gz > patch -d php-5.2.16 -p1 

                      # cd php-5.2.16

                        #  ./configure  --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets

                      #  make  && make install

第五步:一些基本的配置:lighttpd 主配置文件lighttpd.conf文件的大致内容如下(红色代表修改过,蓝色代表要注意一下配置):

··································#######################################################################
##
## Some Variable definition which will make chrooting easier.
##
## if you add a variable here. Add the corresponding variable in the
## chroot example aswell.
##var.log_root    = "/opt/lighttpd/logs"
var.server_root = "/opt/lighttpd"
var.state_dir   = "/opt/lighttpd/run"
var.home_dir    = "/opt/lighttpd"
var.conf_dir    = "/opt/lighttpd/etc"##
## Some additional variables to make the configuration easier
##

##
## Base directory for all virtual hosts
##
## used in:
## conf.d/evhost.conf
## conf.d/simple_vhost.conf
## vhosts.d/vhosts.template
##var.vhosts_dir  = server_root + "/vhosts"##
## Cache for mod_compress
##
## used in:
## conf.d/compress.conf
##var.cache_dir   = "/opt/lighttpd/cache"##
## Base directory for sockets.
##
## used in:
## conf.d/fastcgi.conf
## conf.d/scgi.conf
##var.socket_dir  = home_dir + "/sockets"##
#######################################################################

#######################################################################
##
## Load the modules.include "modules.conf"##
#######################################################################

#######################################################################
##
##  Basic Configuration
## ---------------------
##server.port = 88##
## Use IPv6?
##
##server.use-ipv6 = "enable"

##
## bind to a specific IP
##server.bind = "192.168.1.2"##
## Run as a different username/groupname.
## This requires root permissions during startup. 
##server.username  = "lighttpd"
server.groupname = "lighttpd"## 
## enable core files.
##
#server.core-files = "disable"

##
## Document root
##server.document-root = server_root + "/htdocs"##
## The value for the "Server:" response field.
##
## It would be nice to keep it at "lighttpd".
##
#server.tag = "lighttpd"

##
## store a pid file
##server.pid-file = state_dir + "/lighttpd.pid"##
#######################################################################

#######################################################################
##
##  Logging Options
## ------------------
##
## all logging options can be overwritten per vhost.
##
## Path to the error log file
##server.errorlog             = log_root + "/error.log"##
## If you want to log to syslog you have to unset the 
## server.errorlog setting and uncomment the next line.
##
#server.errorlog-use-syslog = "enable"

##
## Access log config
##include "conf.d/access_log.conf"##
## The debug options are moved into their own file.
## see conf.d/debug.conf for various options for request debugging.
##include "conf.d/debug.conf"##
#######################################################################

#######################################################################
##
##  Tuning/Performance
## --------------------
##
## corresponding documentation:
## http://www.lighttpd.net/documentation/performance.html
##
## set the event-handler (read the performance section in the manual)
##
## possible options on linux are:
#### select
## poll
## linux-sysepoll
##
## linux-sysepoll is recommended on kernel 2.6.
##
server.event-handler = "linux-sysepoll"##

##
server.network-backend = "linux-sendfile"


##
server.max-fds = 2048

##
## Stat() call caching.
##
## lighttpd can utilize FAM/Gamin to cache stat call.
##
## possible values are:
## disable, simple or fam.
##
server.stat-cache-engine = "simple"

##
## Fine tuning for the request handling
##
## max-connections == max-fds/2 (maybe /3)
## means the other file handles are used for fastcgi/files
##server.max-connections = 1024##
## How many seconds to keep a keep-alive connection open,
## until we consider it idle. 
##
## Default: 5
###server.max-keep-alive-idle = 5


index-file.names += (
  "index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)##
## deny access the file-extensions
##
## ~    is for backupfiles from vi, emacs, joe, ...
## .inc is often used for code includes which should in general not be part
##      of the document-root
url.access-deny             = ( "~", ".inc" )

##
## disable range requests for pdf files
## workaround for a bug in the Acrobat Reader plugin.
####$HTTP["url"] =~ "\.pdf$" {
##  server.range-requests = "disable"
##}##
## url handling modules (rewrite, redirect)
##
## defaults to /var/tmp as we assume it is a local harddisk
##server.upload-dirs = ( "/var/tmp" )##
#######################################################################


#######################################################################
##
##  SSL Support
## ------------- 
##
#

····························

对modules.conf取消需要用到模块的注释,mod_rewritemod_accessmod_fastcgi

mod_simple_vhostmod_cgimod_compressmod_accesslog是一般需要用到的。modules.conf文件内容如下:

#######################################################################
##
##  Modules to load
## -----------------
##
## at least mod_access and mod_accesslog should be loaded
## all other module should only be loaded if really neccesary
##
## - saves some time
## - saves memory
##
## the default module set contains:
##
## "mod_indexfile", "mod_dirlisting", "mod_staticfile"
##
## you dont have to include those modules in your list
##
## Modules, which are pulled in via conf.d/*.conf
##
## NOTE: the order of modules is important.
##
## - mod_accesslog     -> conf.d/access_log.conf
## - mod_compress      -> conf.d/compress.conf
## - mod_status        -> conf.d/status.conf
## - mod_webdav        -> conf.d/webdav.conf
## - mod_cml           -> conf.d/cml.conf
## - mod_evhost        -> conf.d/evhost.conf
## - mod_simple_vhost  -> conf.d/simple_vhost.conf
## - mod_mysql_vhost   -> conf.d/mysql_vhost.conf
## - mod_trigger_b4_dl -> conf.d/trigger_b4_dl.conf
## - mod_userdir       -> conf.d/userdir.conf
## - mod_rrdtool       -> conf.d/rrdtool.conf
## - mod_ssi           -> conf.d/ssi.conf
## - mod_cgi           -> conf.d/cgi.conf
## - mod_scgi          -> conf.d/scgi.conf
## - mod_fastcgi       -> conf.d/fastcgi.conf
## - mod_proxy         -> conf.d/proxy.conf
## - mod_secdownload   -> conf.d/secdownload.conf
## - mod_expire        -> conf.d/expire.conf
##

server.modules = (
  "mod_access","mod_alias",
  "mod_auth",
  "mod_evasive",
  "mod_redirect",
  "mod_rewrite",
  "mod_setenv",
  "mod_usertrack",)

##
#######################################################################

#######################################################################
##
##  Config for various Modules
##

·····························

配置lighttpd和php和通信(fastcgi):

# vi /opt/lighttpd/etc/conf.d/fastcgi.conf

#######################################################################

##
##  FastCGI Module 
## --------------- 
##
## http://www.lighttpd.net/documentation/fastcgi.html
##
server.modules += ( "mod_fastcgi" )

##
## PHP Example
##For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.##
## The number of php processes you will get can be easily calculated:

·······················

······················

## chrooted webserver + external PHP
##
## $ spawn-fcgi -f /usr/bin/php-cgi -p 2000 -a 127.0.0.1 -C 8
##
## webserver chrooted to /srv/www/
## php running outside the chroot
fastcgi.server = ( 
  ".php" => (( 
    "host" => "127.0.0.1",
    "port" => "9000",
    "docroot" => "/opt/lighttpd/htdocs/"
  )))#server.chroot = "/opt/lighttpd"
#server.document-root = "/opt/lighttpd/htdocs/"
#

##
#######################################################################


载自:http://hi.baidu.com/keguichao/blog/item/e8fcb810c424a2d4a6ef3f64.html

posted on 2011-08-01 16:35  奋斗者  阅读(3242)  评论(0)    收藏  举报

导航