windows平台搭建lighttpd+php+sqlite

时间:2025-04-27 14:06:37

(一)php

1. 下载及安装

http://www.appservnetwork.com/

从上面的网址下载appserv-win32-2.5.10并安装,在安装的时候,仅仅选择安装php。

由于,我们仅仅使用当中的php。

这所以这样做。是由于AppServ中的php,里面包括了php_pdo.dll这个库。

如果安装后,php的路径为:C:/AppServ/php5

将C:/AppServ/php5/php.ini-recommended复制到C:\WINDOWS文件夹下。并改名为php.ini。

将c:/AppServ/php5/ext以下的php_pdo.dll与php_pdo_sqlite.dll复制到C:/WINDOWS文件夹下。

将C:/WINDOWS/php.ini中,例如以下两行的凝视去掉。

extension=php_pdo.dll

extension=php_pdo_sqlite.dll

(二)lighttpd for windows

1. 下载并安装

能够从下面网址下载

http://lighttpd.dtech.hu/LightTPD-1.4.35-1-IPv6-Win32-SSL.exe

只是,这个网址好像非常卡。要是下载不了,能够从****下载。在下已经将此程序上传。

http://download.****.net/detail/crazycoder8848/8172761

windows下的安装。就不用说了。

2. 配置

进入lighttpd安装文件夹,打开conf文件夹下的lighttpd.conf,做例如以下配置

a)打开cgi功能

当然,你也能够依据须要,打开其它的功能。我改动后的server.modules例如以下。

server.modules              = (

                                "mod_access",

                                "mod_accesslog",

#                               "mod_alias",

#                               "mod_auth",

                                "mod_cgi",

#                               "mod_cml",

#                               "mod_compress",

#                               "mod_evasive",

#                               "mod_evhost",

#                               "mod_expire",

#                               "mod_extforward",

#                               "mod_fastcgi",

#                               "mod_flv_streaming",

#                               "mod_magnet",

#                               "mod_mysql_vhost",

#                               "mod_proxy",

                                "mod_redirect",

                                "mod_rewrite",

#                               "mod_rrdtool",

#                               "mod_scgi",

#                               "mod_secdownload",

#                               "mod_setenv",

#                               "mod_simple_vhost",

#                               "mod_ssi",

                                "mod_status",

#                               "mod_trigger_b4_dl",

#                               "mod_userdir",

#                               "mod_usertrack",

#                               "mod_webdav"

                               )

b) 设置一些路径,如果网页内容在c:/www文件夹中

server.document-root        = "C:/www"

#### php解析器的路径加上

cgi.assign                 = ( ".php" => "C:/AppServ/php5/php-cgi.exe",

                               ".pl"  => "C:/Perl/perl.exe",

                               ".cgi" => "C:/Perl/perl.exe" )

4. 启动lighttpd

执行LightTPD安装文件夹中的LightTPD.exe就可以

(三)sqlite

从下面网址下载一个sqlite-shell,用于创建一个数据库,用于測试环境是否已经搭建成功。

http://www.sqlite.org/2014/sqlite-shell-win32-x86-3080701.zip

下载后。解压得到sqlite3.exe。能够将他复制到C:\WINDOWS文件夹下,这样在dos下运行时更方便。

(四)測试

a)

在dos下,进入c:/www/databases文件夹,创建一个数据库

C:\www\databases>sqlite3  test.db

SQLite version 3.8.7.1 2014-10-29 13:59:56

Enter ".help" for usage hints.

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);

sqlite> select * from my_friends;

tom|22

liyan|21

sqlite> .quit

C:\www\databases>

b) 在c:/www/cig-bin文件夹下,创建一个php脚本haha.php。内容例如以下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>



<body>

<?php

    //phpinfo();

    echo "hello  我的第一个php脚本<br>";

    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']."<br>";

    }



?>

</body>

</html>

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

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

假设在调试php程序时,遇到问题,能够打开c:/windows/php.ini。设置例如以下内容,以打开php的报错功能:

error_reporting = E_ALL & ~E_NOTICE

display_errors = On