您的位置:首页 > 理论基础 > 计算机网络

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

2010-04-26 17:23 483 查看
安装配置Linux+lighttpd+mysql+PHPFastCGI

作者: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:所有用到源码安装的软件,都没有给出下载过程,而是直接使用。原因自明。

LighttpdmysqlPHP安装过程
安装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)libxml2cp 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页面表示已经安装成功!~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: