openwrt 安裝 php sqlite


安裝PHP

PMBLOG是一個簡單的靜態博客程序,只須要PHP,不須要數據庫的支持,這對於小內存小功耗的路由來講是再友好不過的。下面我就講講如何安裝PMBLOG。php

首先咱們須要下載PHP及其相關的一些擴展。css

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

配置PHP

編輯php.ini文件html

vi /etc/php.ini

其中將mysql

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

三個前面的;去掉,用以啓用擴展nginx

並將;date.timezone =修改成date.timezone = Asia/Shanghai,並將;doc_root="/www"修改成;doc_root="/www/root"git

若是你沒有設置過系統時區的話還須要設置系統時區。打開LUCI界面,進入系統 - 系統屬性 - 基本設置中將時區改成Asia/Shanghaigithub

最後你須要安裝一個時區信息軟件包,不然系統沒法識別時區。web

opkg install zoneinfo-asia

uhttpd配置端口轉發

接着須要配置端口轉發。因爲默認的是LUCI佔用80端口,但我比較喜歡80端口放網站,因此我將LUCI挪到了8080端口,而PHP則使用80端口。sql

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  。通常上面的就能夠實現了,親測可用

二、安裝程序
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


三、配置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

四、配置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

五、環境測試
先寫個簡單的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

相關文章
相關標籤/搜索