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
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?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? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#?./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 = 5index-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_rewrite,mod_access,mod_fastcgi,
mod_simple_vhost,mod_cgi,mod_compress,mod_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
轉載于:https://www.cnblogs.com/chenwenbiao/archive/2011/08/01/2124020.html
總結
以上是生活随笔為你收集整理的CentOS+lighttpd+php+mysql (fastcgi)环境的搭建(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Sharepoint Designer
- 下一篇: Winform开发中另一种样式的OutL