openwrt 安装 php sqlite


安装PHP

PMBLOG是一个简单的静态博客程序,只需要PHP,不需要数据库的支持,这对于小内存小功耗的路由来说是再友好不过的。下面我就讲讲如何安装PMBLOG。

首先我们需要下载PHP及其相关的一些扩展。

opkg updateopkg install php5 php5-cgi php5-mod-mcrypt php5-mod-curl php5-mod-hash php5-mod-json

配置PHP

编辑php.ini文件

vi /etc/php.ini

其中将

;extension = ctype.so;extension = curl.so;extension = hash.so;extension = json.so

三个前面的;去掉,用以启用扩展

并将;date.timezone =修改为date.timezone = Asia/Shanghai,并将;doc_root="/www"修改为;doc_root="/www/root"

如果你没有设置过系统时区的话还需要设置系统时区。打开LUCI界面,进入系统 - 系统属性 - 基本设置中将时区改为Asia/Shanghai

最后你需要安装一个时区信息软件包,否则系统无法识别时区。

opkg install zoneinfo-asia

uhttpd配置端口转发

接着需要配置端口转发。由于默认的是LUCI占用80端口,但我比较喜欢80端口放网站,所以我将LUCI挪到了8080端口,而PHP则使用80端口。

vi /etc/config/uhttpd

将第5行的0.0.0.0:80修改为0.0.0.0:8080

option rfc1918_filter 1这一句在前面加上#号注释掉

同时在文件末尾增加如下代码

config uhttpd web
    list    listen_http 0.0.0.0:80
    option  home    /www/root
    option  cgi_prefix  /cgi-bin
    option  index_page  "index.html index.php"
    list    interpreter ".php=/usr/bin/php-cgi"

保存后重启uhttpd

/etc/init.d/uhttpd restart

上传PMBLOG程序

上传PMBLOG程序到/www/root文件夹下,并按照HowToInstall的指导配置好config.php文件。

WEB访问PMBLOG程序目录即可大功告成!









-------------------------------------------------------------------------------------------  底下是比较复杂的,多安装sqlite  。一般上面的就可以实现了,亲测可用

2、安装程序
php5
php5-cgi
php5-mod-ctype
php5-mod-hash
php5-mod-pdo
php5-mod-pdo-sqlite
php5-mod-session
php5-mod-sqlite
php5-mod-sqlite3
php5-mod-tokenizer
php5-mod-xml

编辑/etc/opkg.conf,加入如下一行:
dest udisk /mnt/sda1/ipk

使用下面命令把软件安装到U盘:
opkg update
opkg install -d udisk php5 php5-cgi php5-mod-ctype php5-mod-hash php5-mod-pdo php5-mod-pdo-sqlite php5-mod-session php5-mod-sqlite php5-mod-sqlite3 php5-mod-tokenizer php5-mod-xml

opkg install -d udisk php5-mod-curl php5-mod-gd php5-mod-mbstring php5-mod-mcrypt php5-mod-ftp php5-mod-openssl php5-mod-json php5-mod-iconv 

opkg install -d udisk zoneinfo-core zoneinfo-asia zoneinfo-simple



建立软连接,不然会找不到对应的库和配置文件:
cd /etc
ln -s /mnt/sda1/ipk/etc/php.ini php.ini
ln -s /mnt/sda1/ipk/etc/php5 php5
cd /usr/lib
ln -s /mnt/sda1/ipk/usr/lib/libpcre.so.0.0.1 libpcre.so.0
ln -s /mnt/sda1/ipk/usr/lib/libpcreposix.so.0.0.0 libpcreposix.so.0
ln -s /mnt/sda1/ipk/usr/lib/libsqlite.so.0.8.6 libsqlite.so.0      
ln -s /mnt/sda1/ipk/usr/lib/libsqlite3.so.0.8.6 libsqlite3.so.0
ln -s /mnt/sda1/ipk/usr/lib/libxml2.so.2.7.8 libxml2.so.2      
ln -s /mnt/sda1/ipk/usr/lib/libz.so.1.2.3 libz.so        
ln -s /mnt/sda1/ipk/usr/lib/php php
cd /usr/bin
ln -s /mnt/sda1/ipk/usr/bin/php-cgi php-cgi


3、配置php
修改/etc/php.ini。
去掉下面行前面注释:

extension=curl.so

extension=mbstring.so

extension=gd.so

extension=ctype.so

extension=hash.so

json

ioncv
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=session.so
extension=tokenizer.so
extension=xml.so
extension=xmlreader.so
extension=xmlwriter.so
修改行:
short_open_tag = On
;doc_root = "/www" 
date.timezone = Asia/Shanghai

4、配置uhttpd
在/etc/config/uhttpd最后添加:
config uhttpd web
list listen_http 0.0.0.0:88
option home /mnt/sda1/ipk/www
option index_page index.php
list interpreter ".php=/usr/bin/php-cgi"
88为访问端口,/mnt/overlay/www为放置网页的目录,这些都可以修改。
然后重启uhttpd:
/etc/init.d/uhttpd restart

5、环境测试
先写个简单的index.php网页上传到/mnt/sda1/ipk/www测试部署情况。
index.php代码示例:



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WEB环境部署测试</title>
<style type="text/css">
<!--
BODY{text-align:center;} 
TABLE{BORDER-COLLAPSE:collapse;}
TD,TH {BORDER:1px solid #000000;}
TH{BACKGROUND-COLOR:yellowgreen;FONT-WEIGHT:bold;}
-->
</style>
</head>
<body>
<h2>Congratulations on your success.</h2>
<table width="700" cellspacing="1" cellpadding="3">
    <tr><th colspan="2">服务器信息</th></tr>
    <tr>
       <td>主机名</td>
       <td><?=$_SERVER['SERVER_NAME']?></td>
    </tr>
    <tr>
       <td>主机地址</td>
       <td><?=$_SERVER['SERVER_ADDR'].":".$_SERVER['SERVER_PORT']?></td>
    </tr>
    <tr>
       <td>服务器软件</td>
       <td><?=$_SERVER['SERVER_SOFTWARE']?></td>
    </tr>
    <tr>
       <td>网站主目录</td>
       <td><?=$_SERVER["DOCUMENT_ROOT"]?></td>
    </tr>
    <tr><th colspan="2">SQLite 连接测试</th></tr>
    <tr>
       <td>SQLite</td>
       <td><?=function_exists("sqlite_close")?YES." / ".sqlite_libversion():NO?></td>
    </tr>
    <tr>
       <td>连接数据库(内存)</td>
       <td><b><? $db = sqlite_open(":memory:");?><?=($db?"<font color=green>连接正常</font>":"<font color=red>连接失败</font>");?><? sqlite_close ($db);?></b></td>
    </tr>
</table>
</body>
</html>

在浏览器中输入:
http://192.168.1.1:88/




上面安装如果遇到   Timezone database is corrupt    we selected the timezone 'UTC' 问题   按以下方法处理

把上面的 

opkg remove -d udisk php5 php5-cgi php5-mod-ctype php5-mod-hash php5-mod-pdo php5-mod-pdo-sqlite php5-mod-session php5-mod-sqlite php5-mod-sqlite3 php5-mod-tokenizer php5-mod-xml php5-mod-curl php5-mod-gd php5-mod-mbstring php5-mod-mcrypt php5-mod-ftp php5-mod-openssl php5-mod-json php5-mod-iconv 

opkg remove -d udisk zoneinfo-core zoneinfo-asia zoneinfo-simple


opkg install  zoneinfo-core zoneinfo-asia zoneinfo-simple

opkg install  php5 php5-cgi php5-mod-ctype php5-mod-hash php5-mod-pdo php5-mod-pdo-sqlite php5-mod-session php5-mod-sqlite php5-mod-sqlite3 php5-mod-tokenizer php5-mod-xml php5-mod-curl php5-mod-gd php5-mod-mbstring php5-mod-mcrypt php5-mod-ftp php5-mod-openssl php5-mod-json php5-mod-iconv  php5-mod-sockets

extension=ctype.so                                                                                                                                                                                                                                                            
extension=curl.so                                                                                                                                                                                                                                                             
;extension=dom.so                                                                                                                                                                                                                                                             
;extension=exif.so                                                                                                                                                                                                                                                            
extension=ftp.so                                                                                                                                                                                                                                                              
extension=gd.so                                                                                                                                                                                                                                                               
;extension=gmp.so                                                                                                                                                                                                                                                             
extension=hash.so                                                                                                                                                                                                                                                             
extension=iconv.so                                                                                                                                                                                                                                                            
extension=json.so                                                                                                                                                                                                                                                             
;extension=ldap.so                                                                                                                                                                                                                                                            
extension=mbstring.so                                                                                                                                                                                                                                                         
extension=mcrypt.so                                                                                                                                                                                                                                                           
;extension=mysql.so                                                                                                                                                                                                                                                           
extension=openssl.so                                                                                                                                                                                                                                                          
;extension=pcre.so                                                                                                                                                                                                                                                            
extension=pdo.so                                                                                                                                                                                                                                                              
;extension=pdo-mysql.so                                                                                                                                                                                                                                                       
;extension=pdo-pgsql.so                                                                                                                                                                                                                                                       
extension=pdo_sqlite.so                                                                                                                                                                                                                                                       
;extension=pgsql.so                                                                                                                                                                                                                                                           
extension=session.so                                                                                                                                                                                                                                                          
;extension=soap.so                                                                                                                                                                                                                                                            
extension=sockets.so                                                                                                                                                                                                                                                          
extension=sqlite.so                                                                                                                                                                                                                                                           
extension=sqlite3.so                                                                                                                                                                                                                                                          
extension=tokenizer.so                                                                                                                                                                                                                                                        
extension=xml.so                                                                                                                                                                                                                                                              
;extension=xmlreader.so                                                                                                                                                                                                                                                       
;extension=xmlwriter.so


对,就是重新安装到 内存中,不安装到u盘上,装U盘就是一个坑,php装完总共不到10m


你可能感兴趣的:(openwrt 安装 php sqlite)