首页 > 代码库 > fedora linux平台下搭建lighttpd+php+sqlite

fedora linux平台下搭建lighttpd+php+sqlite

(一)lighttpd

1. 安装

yum install lighttpd

安装完成后,系统中应该多了一个用户lighttpd和组lighttpd。这个用户,默认是不允许登陆的。

我们修改/etc/passwd,将lighttpd修改为如下形式。

lighttpd:x:489:470:lighttpd web server:/home/lighttpd/:/bin/bash

注意,你所看到的数字可能不是489,470,这个没关系,也不用改,保持原来的值即可。


2. 为lighttpd用户创建一个目录,将网站的内容放进去

mkdir   /home/lighttpd

chown lighttpd:lighttpd   /home/lighttpd

创建相关子目录,并放入网站的内容。

注意,/home/lighttpd以lighttpd目录中的各种操作,都以lighttpd用户的身份来完成。否则,lighttpd运行时可能会出现权限问题。

su lighttpd

cd /home/lighttpd

mkdir www

mkdir www/cgi-bin 

mkdir www/databases 

mkdir www/images 

mkdir www/log

好了,现在可以往各个目录里放内容了,网页,图片,php脚本,sqlite数据库文件等。

index.html就放到www目录下。


3. 配置

修改lighttpd的配置文件  /etc/lighttpd/lighttpd.conf

a)打开cgi功能

当然,你也可以根据需要,打开其他的功能。我修改后的server.modules如下。

server.modules              = (
                                "mod_rewrite",
                                "mod_redirect",
#                               "mod_alias",
                                "mod_access",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
#                               "mod_fastcgi",
#                               "mod_proxy",
#                               "mod_simple_vhost",
#                               "mod_evhost",
#                               "mod_userdir",
                                "mod_cgi",
                                "mod_compress",
#                               "mod_ssi",
                                "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )

b) 默认的文件名

这里把default.xxx也给加上。

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm", "default.php" )


c) 设置一些路径

server.document-root        = "/home/lighttpd/www/"

## where to send error-messages to
server.errorlog             = "/home/lighttpd/www/log/error.log"

accesslog.filename          = "/home/lighttpd/www/log/access.log"


#### php解析器的路径加上
cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".php" => "/usr/bin/php" )


4. 启动lighttpd

service lighttpd start


5. 设置lighttpd开机自动启动

chkconfig --add lighttpd


(二)sqlite

这个简单,直接安装一下就行了。

yum install  sqlite


(三)php

1. 编译及安装

下载php源码包

http://ar2.php.net/distributions/php-5.6.3.tar.bz2

将源码包拷贝到 /root目录下

然后进入/root目录,执行如下命令序列

tar -xjf php-5.6.3.tar.bz2 

cd php-5.6.3

./configure  --prefix=/usr --with-config-file-path=/etc --enable-libxml --with-libxml-dir=/usr/lib --with-sqlite3 --enable-pdo --with-pdo-sqlite CLAGS=-O2

make; make install


需要注意的是,这种编译方式,支持访问sqlite3的方式为pdo方式。这种方式,不需要依赖任何extension


(四)测试

a) 

用lighttpd用户,进入/home/lighttpd/www/databases目录,创建一个数据库

[lighttpd@localhost databases]$ sqlite3 test.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table my_friends(name varchar(10), age smallint);
sqlite> insert into my_friends values(‘tom‘,22);
sqlite> insert into my_friends values(‘liyan‘,21);

输入ctrl+d退出sqlite shell


b) 用lighttpd用户,进入cig-bin目录,创建一个php脚本haha.php,内容如下:

<!DOCTYPE html>
<html>
<body>

<?php
//phpinfo();
echo "hello  我的第一个php脚本\n";
echo getcwd();


$file_db = new PDO(‘sqlite:../databases/test.db‘);
$result = $file_db->query(‘SELECT * FROM my_friends‘);


foreach($result as $row) 
{
    echo " name: ".$row[‘name‘]." ";
}


?>


</body>
</html>



c) 用浏览器访问haha.php看看效果吧 :)

http://ip_of_lighttpd/cgi-bin/haha.php


如果在调试php程序时,遇到问题,可以打开/etc/php.ini,设置如下内容,以打开php的报错功能:

error_reporting = E_ALL & ~E_NOTICE

display_errors = On


fedora linux平台下搭建lighttpd+php+sqlite