安裝配置Linux+lighttpd+mysql+PHP(FastCGI)

http://blog.csdn.net/zccst/article/details/4494298 轉賬

安裝配置Linux+lighttpd+mysql+PHP(FastCGI) .
分類: Linux-web服務器搭建 2009-08-28 17:38 3758人閱讀 評論(0) 收藏 舉報 

安裝配置Linux+lighttpd+mysql+PHP(FastCGI)
作者:zccst

Linux系統:CentOS 5.3

前面的話
本文詳細介紹了Linux+lighttpd+mysql+PHP(FastCGI)方式的安裝配置過程。全文按三大塊內容詳細闡述,分別是1,lighttpd,mysql,PHP安裝過程。2,三者之間的關聯配置。3,簡單測試。以下是詳細內容。


注1:由於技術日新月異,不同軟件間難免會出現異步,即便同步,不同時期發行的版本之間也會存在不兼容。比如,PHP從5.3.0開始,支持fastcgi的方式,已經發生改變。對於lighttpd,從1.4.23開始,也調整了佈局,根本沒有/bin目錄,更談不上/bin/spawn-cgi。如果你使用最新版本軟件,卻按照以前的方法進行安裝配置,肯定會出錯。


本文使用版本:

lighttpd  1.4.18

mysql    5.1.30

php       5.2.10

注2:所有用到源碼安裝的軟件,都沒有給出下載過程,而是直接使用。原因自明。

Lighttpd,mysql,PHP安裝過程
安裝lighttpd-1.4.18

一、安裝

1, Pcre

(1) 下載。

ftp://ftp.pbone.net/mirror/www.startcom.org/AS-4.0.0/os/i386/StartCom/RPMS/pcre-devel-4.5-3.2.SEL4.i386.rpm

(2) 安裝。rpm -ivh pcre-devel-4.5-3.2.SEL4.i386.rpm --nodeps(強制安裝)

(3) 輸入rpm -qa |grep pcre

  返回結果:pcre-4.5-3 或 pcre-devel-4.5-3.2.SEL4 表示已經成功安裝

2, lighttpd

tar

cd

./configure --prefix=/opt/lighttpd

make

make install

 

二、配置

mkdir /etc/lighttpd/         #用來存放主配置文件

mkdir -p /var/www/htdocs  #用來存放網站

mkdir /opt/lighttpd/log      #用來存放日誌


cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd

vi lihttpd  修改所在路徑爲 lighttpd="/opt/lighttpd/sbin/lighttpd"

cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf

vi  lighttpd.conf(修改主配置文件)

(1)修改默認目錄路徑

設置錯誤日誌文件路徑

server.errorlog = "/opt/lighttpd/logs/lighttpd.error.log" (43行)

設置訪問日誌文件路徑

accesslog.filename = "/opt/lighttpd/logs/access.log" (116行)

(2)把#server.port                = 81 前的#去掉

(3)用什麼權限來運行lighttpd

server.username = "lighttpd"

server.groupname = "lighttpd"

從安全角度來說,不建議用root權限運行web server,可以指定普通用戶權限。

(4)#$HTTP["url"] =~ "/.pdf$" {

# server.range-requests = "disable"

#}


創建lighttpd用戶

useradd lighttpd

chown –R lighttpd:lighttpd /opt/lighttpd/

chown –R lighttpd:lighttpd /var/www/htdocs/


三、啓動並測試。由於下面還要安裝其它軟件,可暫不測試。

啓動命令:

/opt/lighttpd/sbin/lighttpd –f /etc/lighttpd/lighttpd.conf

查看端口(81)

netstat –ln|more

安裝mysql-5.1.30

一、安裝

tar

cd

./configure –prefix=/opt/mysql

make

make install

二、配置

1, 修改主配置文件

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

將/etc/my.cnf文件中的skip-federated註釋掉


2,添加mysql用戶

useradd mysql

chown –R mysql:mysql /opt/mysql          (主文件夾)

chown –R mysql:mysql /etc/my.cnf          (主配置文件)

注:權限問題非常重要,稍不注意就會出錯。

三、啓動

1, 生成mysql用戶數據庫和表文件

./mysql_install_db --user=mysql

運行之後在/opt/mysql/下會生成var/文件夾,現更改其屬主。

chown –R mysql:mysql /opt/mysql/var

2, 啓動服務器端。

./mysqld_safe --defaults-file=/etc/my.cnf &

3, 用客戶端登錄訪問數據庫

./mysql –u root –p

四、使用

第一次登陸密碼爲空,直接按回車就可以使用數據庫了。
 

安裝php-5.2.10

一、安裝

1,GD庫(共6 + 1 = 7個),爲了減少篇幅,具體執行略去,需要注意的地方已標出。

(1)zlib       

(2)jpeg6      mkdir /opt/jpeg6/

mkdir /opt/jpeg6/bin/

mkdir /opt/jpeg6/lib/

mkdir /opt/jpeg6/include/

mkdir /opt/jpeg6/man/

mkdir /opt/jpeg6/man1/

mkdir /opt/jpeg6/man/man1/
 

--prefix=/opt/jpeg6/ --enable-shared --enable-static(注:添加參數)

           make install-lib

(3)libpng    

(4)freetype   --prefix=/opt/freetype/

(5)libxml2   cp xml2-config /usr/bin
(6)fontconfig  --prefix=/opt/fontconfig  --with-freetype-config=/opt/freetype/bin/freetype-config

 

注:如果在安裝fontconfig時, ./configure  出現以下錯誤

checking for LIBXML2... configure: error: Package requirements (libxml-2.0 >= 2.6) were not met:

No package 'libxml-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you

installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBXML2_CFLAGS

and LIBXML2_LIBS to avoid the need to call pkg-config.

See the pkg-config man page for more details.

 

解決辦法:

yum install libxml2-devel

 

最後按照GD,把上面6個關聯起來,順序與上面對應:

(7)gd         --prefix=/opt/gd --with-zlib-dir --with-jpeg=/opt/jpeg6/ --with-png-dir --with-freetype=/opt/freetype/ --with-libxml2-dir --with-fontconfig=/opt/fontconfig/

可選安裝:curl  libxslt

 

2,php

tar

cd

./configure  --prefix=/opt/php    --enable-fastcgi  --enable-force-cgi-redirect  --with-mysql=/opt/mysql/  --with-gd=/opt/gd/    --with-libxml-dir

make

make test

注:如果在make test時出現以下錯誤

cannot restore segment prot after reloc permission denied
 

問題原因:權限問題。

解決辦法:

1,編輯/etc/sysconfig/selinux,找到:

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - SELinux is fully disabled.

SELINUX=enforcing

如果SELINUX已經是 SELINUX=disabled,那麼就不用改了,否則就把SELINUX=enforcing 註釋掉,新加一行:

SELINUX=disabled

保存,退出。

2,在你保證SElinux 被disabled後.還執行下chcon -t texrel_shlib_t

如: chcon -t texrel_shlib_t /路徑/路徑/名字.so   (這個文件視具體執行文件.)

兩步後,應該就ok了。

再次make test ,順利完成!~~~

 make  install

 二、配置

cp php.ini-dist /opt/php/lib/php.ini

 
三者之間的關聯配置
 

一、在php的主配置文件裏,修改與lighttpd相關聯的內容

cgi.fix_pathinfo=1 ,把前面的註釋 ; 去掉,再把後面的值改爲1。保存退出。

 

二、在lighttpd的主配置文件裏,修改與php相關聯的內容

1,server.modules(在24行)

取消需要用到模塊的註釋,mod_rewrite,mod_access,mod_fastcgi,

mod_simple_vhost,mod_cgi,mod_compress,mod_accesslog是一般需要用到的。

 
2, 設置網站根目錄路徑

server.document-root    = "/var/www/htdocs/"

 

3,找到fastcgi的定義

#### 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" => "/var/run/lighttpd/php-fastcgi.socket",

            "bin-path" => "/opt/php/bin/php-cgi"

        )

    )

)

 

三、       mysql與lighttpd、php相關聯.(此處不需任何修改)

僅僅在安裝php時 ./configure 加上 --with-mysql=/opt/mysql/ 就可以了。


vi /opt/lib/php.ini
查找register_globals = Off,把off改成On
再查找short_open_tag = Off,把off改成On
在查找extension=php_mbstring.dll把前面"#"號都去了,這樣才能啓動這條參數的功能。
比如要使PHP支持mysql,那麼就要吧extension=php_mysql.dll前面的"#"去掉。

簡單測試
 

首先關閉安裝lighttpd時,啓動的進程,然後重新啓動lighttpd

/opt/lighttpd/sbin/lighttpd –f /etc/lighttpd/lighttpd.conf


注:如果重啓出現以下錯誤

2009-08-28 16:59:07: (mod_fastcgi.c.900) bind failed for: unix:/var/run/lighttpd/php-fastcgi.socket-0 No such file or directory

2009-08-28 16:59:07: (mod_fastcgi.c.1336) [ERROR]: spawning fcgi failed.

2009-08-28 16:59:07: (server.c.895) Configuration of plugins failed. Going down.

問題原因:版本不兼容問題。

解決辦法:

cd /var/run

mkdir lighttpd

重啓lighttpd,成功啓動!~~~

 cd  /var/www/htdocs

vi  test.php

<?php

phpinfo();

?>

保存退出後。

在瀏覽器裏輸入:http://本機ip/test.php

如果顯示PHP頁面表示已經安裝成功!~~~
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章