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

來源:互聯網
上載者:User
(一)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,內容如下:





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


?>







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

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.