openWRT 系统安装 Web服务器 ( sqlite3 + php5 + lighttpd )

路由硬件: Mediatek MT7628AN

路由固件: OpenWrt Chaos Calmer 15.05.1


安装步骤:

1. sqlite3 安装

opkg update
opkg install libsqlite3 sqlite3-cli

2. 安装 php5

opkg install php5 php5-cgi php5-cli php5-fastcgi 
opkg install php5-mod-sqlite3 php5-mod-pdo php5-mod-pdo-sqlite 
opkg install php5-mod-session  php5-mod-ctype php5-mod-gd 
opkg install php5-mod-sockets php5-mod-mcrypt php5-mod-mbstring
opkg install php5-mod-curl php5-mod-iconv php5-mod-json

opkg install zoneinfo-core zoneinfo-asia

3. 修改 /etc/php.ini

$vi /etc/php.ini

修改:
doc_root = "/your_website_root"
date.timezone = "Asia/Shanghai"

4. 修改openWRT 默认的 uhttpd 服务配置文件

#vi /etc/config/uhttpd

修改: 
list listen_http 0.0.0.0:80 --> list listen_http 0.0.0.0:8081
list listen_http [::]:80 --> list listen_http [::]:8081 

修改保存后,重启uhttpd,即把其原来Web 80 监听端口改为 8081
#/etc/init.d/uhttpd restart

 5. 安装 lighttpd

opkg install lighttpd lighttpd-mod-fastcgi lighttpd-mod-access 
opkg install lighttpd-mod-alias lighttpd-mod-redirect lighttpd-mod-rewrite lighttpd-mod-evasive

6. 修改 lighttpd 配置

#vi /etc/lighttpd/lighttpd.conf

修改后文件内容
server.modules = (
        "mod_access",
        "mod_alias",
        "mod_redirect",
        "mod_rewrite",
        "mod_fastcgi",
        "mod_evasive"
)

server.document-root        = "your_website_root"
server.upload-dirs          = ( "/tmp" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "http"
server.groupname            = "www-data"

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

url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
evasive.max-conns-per-ip=18

### Options that are useful but not always necessary:
#server.chroot               = "/"
server.port                 = 80
#server.bind                 = "localhost"
#server.tag                  = "lighttpd"
#server.errorlog-use-syslog  = "enable"
#server.network-backend      = "write"

### Use IPv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl"

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

fastcgi.server  = (".php"=>
        ((
                "socket"=>"/tmp/php-fastcgi.socket",
                "bin-path"=>"/usr/bin/php-fcgi",
                "bin-environment"=>(
                        "PHP_FCGI_CHILDREN"=>"2",
                        "PHP_FCGI_MAX_REQUESTS"=>"1000"
                ),
                "min-procs"=>1,
                "max-procs"=>2,
                "idle-timeout"=>20
        ))
)

include       "/etc/lighttpd/mime.conf"
include_shell "cat /etc/lighttpd/conf.d/*.conf"

7. 安装用户组及用户操作软件支持

opkg install shadow-groupadd shadow-common 
opkg install shadow-usermod shadow-useradd

8. 添加 http 用户组, 以及加入 http 用户组

groupadd www-data
usermod -G www-data http

注:  此文 件目录 '/var/log/lighttpd/error.log' 属 www-data 用户组;

9. 对应的 web 目录, 用 chown, chgrp 将其更改为 http 用户组和用户

chown -R http website_root
chgrp -R www-data website_root

10. 如上述操作正确,openWRT 系统上的 lighttpd + php5 + sqlite3 WEB/SERVER 安装完成,可正常使用。

你可能感兴趣的:(openWRT)