linux,lighttpd,php,mysql环境搭建

linux,lighttpd,php,mysql环境搭建

1.       什么是CGI程序?

Common gateway interface,通用网关接口。首先,任何遵守CGI标准的、由web服务器执行的、能从web服务器接收信息发送到浏览器或者能发送信息给服务器的程序就是CGI程序,CGI程序能在任何特定的服务器上运行。

简单的说,它是沟通HTML表单和服务器端程序的接口,是可以被其他语言所应用的一个规范集。

2.       Lighttpd简介

Lighttpd是一开源且轻量级的web server,支持fastCGICGI Auth,输出压缩(output compress)URL重写Alias等重要功能。

Lighttpd使用fastcgi方式运行php,它会使用很少的php进程响应很大的并发。

3.       安装步骤(LinuxLighttpdmysqlphp

a)       下载各个软件

系统环境:Centos 6.2

Lighttpdlighttpd-1.4.24

Phpphp-5.2.10

Mysqlmysql-5.1.60

b)       安装Lighttpd

tar xvf lighttpd-1.4.24.tar.gz

cd lighttpd-1.4.24

./configure --prefix=/opt/lighttpd

make

make install

c)       配置Lighttpd

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

mkdir –p /var/www/htdocs               用来存放网站

mkdir /opt/lighttpd/log                  用来存放日志

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

vi lihttpd  修改所在路径为 lighttpd="/etc/lighttpd/lighttpd.conf"

 

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

cp doc/rc.lighttpd.redhat /etc/rc.d/init.d/lighttpd

编辑:

将#lighttpd="/usr/sbin/lighttpd"

修改为:lighttpd="/opt/lighttpd/sbin/lighttpd"

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

chkconfig lighttpd on

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

1)修改默认目录路径

设置错误日志文件路径

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

设置访问日志文件路径

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

2)修改端口号 (默认为80

#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/

d)       安装php

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/ 

./configure --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 

最后按照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/

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  install

e)       配置php

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

f)        lighttpdphp关联

修改php.ini

vim /opt/php/lib/php.ini

cgi.fix_pathinfo=1

查找register_globals = Off,把off改成On

再查找short_open_tag = Off,把off改成On

在查找extension=php_mbstring.dll把前面"#"号都去了,这样才能启动这条参数的功能。

比如要使PHP支持mysql,那么就要吧extension=php_mysql.dll前面的"#"去掉。

修改lighttpd.conf

vim /etc/lighttpd/lighttpd.conf

lighttpd的主配置文件里,修改与php相关联的内容

server.modules(24)

取消需要用到模块的注释:mod_rewritemod_accessmod_fastcgimod_simple_vhostmod_cgimod_compressmod_accesslog是一般需要用到的。 

设置网站根目录路径

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

找到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"

        )

    )

)  

g)       进行测试

/var/www/htdocs/中创建一个文件index.php,编辑内容如下:

phpinfo();

?>

启动服务lighttpd

在地址栏输入

127.0.0.1:81/index.php

即可打开一个页面

h)       mysql安装

tar

cd

./configure --prefix=/opt/mysql

make

make install

i)         配置mysql

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

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

chmod 755 /etc/rc.d/init.d/mysqld

useradd mysql

chown –R mysql:mysql /opt/mysql

chown –R mysql:mysql /etc/my.cnf

修改/etc/my.cnf文件,配置端口号(3306)和socket/tmp/mysql.sock

./bin/mysql_install_db --basedir=/opt/mysql --datadir=/opt /mysql/data --user=mysql(初始化数据库)

 

mysqllighttpdphp的相关联,仅仅在安装php ./configure 加上

--with-mysql=/opt/mysql/ 就可以了。

 

之后启动

/etc/init.d/mysqld start

修改密码

/opt/mysql/bin/mysqladmin –u root password “My_Own_Password”

登录mysql

/opt/mysql/bin/mysql –u root –p

j)         测试phpmysql相连接

先在mysql中创建一个数据库”mydb”,然后修改刚才的index.php文件

$dbhost = ‘localhost’;

$dbuser = ‘root’;

$dbpassword = ‘My_Own_Password’;

$dbname = ‘mydb’;

$connect = mysql_connect($dbhost, $dbuser, $dbpassword, $dbname);

if($connect) {

     echo “succeed”;

} else {

     echo “failed”;

}

?>

之后在浏览器中输入127.0.0.1:81/index.php,如果成功的话,就说明数据库连接成功。

4.       什么是fastCGI

fastCGI首先是为了解决CGI的性能问题而提出的。每当服务器接收到CGI程序请求时,服务器创建一个进程,处理完毕之后,将结果返回,然后该进程终止。fastCGI是对CGI的改良,它是在web服务器启动的时候或者是在客户第一次请求的时候创建进程,它处理完客户端请求之后并不终止,而是等待下一个请求。而且,fastCGI可以分布式在不同的计算机上,这样可以提高性能,提高访问速度。

但是fastCGI也有一些不足,PHP-CGI解释器每进程消耗725内存,将这个数字乘以50100就是很大的内存数。

5.       什么是PHP-CGI

PHP-CGIPHP自带的fastCGI管理器。

6.       ./configure的参数具体含义

在安装过程当中,configure的参数比较多。configure是一个脚本,它是一个脚本配置程序,这个参数比较多。

注意:在服务启动之后,为了检查服务,一般主要检查3个地方:

(1)多次查看进程的pid,看看它们是不是一样的;

(2)查看端口号,看是否已经存在;

(3)查看log日志,看看是不是有问题存在。 



参考资料:

1.       http://hi.baidu.com/tian%C2%BD%C0%DA/blog/item/d75201da9024636ad1164e1b.html

2.       http://wenku.baidu.com/view/17ba372bcfc789eb172dc8b9.html

3.       http://blog.csdn.net/zccst/article/details/4494298

4.       PHP Compilation Errors and Fixeshttp://log.hnb.cn/archives/110.html

5.       LinuxMysql安装与配置http://wenku.baidu.com/view/d0bd1022aaea998fcc220e64.html

6.       http://www.china125.com/faq/host/154.htm

7.       http://blog.csdn.net/besthyq/article/details/1575819

8.       http://www.mike.org.cn/articles/what-is-cgi-fastcgi-php-fpm-spawn-fcgi/


 搭建web服务器.doc  

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(3659) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值