busybox filesystem httpd php-5.5.31 sqlite3 webserver

简介: /******************************************************************** * busybox filesystem httpd php-5.5.31 sqlite3 webserver * 声明: * 本文主要是记录使用httpd、php5、sqlite3搭建php web服务器。
/********************************************************************
 *      busybox filesystem httpd php-5.5.31 sqlite3 webserver
 * 声明:
 *     本文主要是记录使用httpd、php5、sqlite3搭建php web服务器。
 *
 *                                 2016-1-24 深圳 南山平山村 曾剑锋
 *******************************************************************/

一、参考文章:
    1. Run busybox httpd with php
        https://box.matto.nl/busyboxphp.html
    2. Sqlite undefined reference to `sqlite3_open' error in Netbeans C++ on Ubuntu, Integrating SQLite into Netbeans C++ Ubuntu
        http://stackoverflow.com/questions/3463438/sqlite-undefined-reference-to-sqlite3-open-error-in-netbeans-c-on-ubuntu-in
    3. 嵌入式WEB服务器移植三部曲之PHP的移植
        http://blog.csdn.net/cos_sin_tan/article/details/7734278
    4. Real210 编译sqlite错误:.//libsqlite3.a(sqlite3.o): In function `unixDlSym’:
        http://www.jyguagua.com/?p=965
    5. 成功移植SQLite3到ARM Linux开发板
        http://www.myir-tech.com/bbs/thread-6189-1-1.html
    6. ARM上linux终端操作SQLITE,退格键问题
        http://www.programgo.com/article/61872541163/
    7. 用busybox做一个简单的文件系统 
        http://blog.chinaunix.net/uid-9688646-id-3346880.html
    8. Using SQLite3 with PHP
        http://babbage.cs.qc.cuny.edu/courses/cs903/2013_02/using_sqlite3.html

二、测试busybox httpd:
    1. cat /www/index.html
        <h1>Welcome to Tinyfs</h1>
        <p>zengjf</p>   
    2. shell命令:/usr/sbin/httpd -vv -f -h /www/
    3. 查看ARM板IP:
        [zengjf@root www]# ifconfig eth0
        eth0      Link encap:Ethernet  HWaddr 1E:ED:19:27:1A:B3  
                  inet addr:10.0.1.52  Bcast:10.0.1.255  Mask:255.255.255.0
                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                  RX packets:39 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000 
                  RX bytes:4990 (4.8 KiB)  TX bytes:4050 (3.9 KiB)

        [zengjf@root www]# 
    4. PC机浏览器访问:http://10.0.1.52/
        经验证获取到了正确信息,Vim里贴不上图,就不贴图了。
    5. shell响应如下:
        [zengjf@root www]# /usr/sbin/httpd -vv -f -h /www/
        10.0.1.50:55185: url:/
        10.0.1.50:55185: response:200
三、编译、安装、测试php-5.5.31
    1. ./configure -host=arm-linux-gnueabihf -prefix=/usr/local/php -disable-all -enable-pdo -with-sqlite3 -with-sqlite -with-pdo-sqlite -with-zlib -without-iconv
    2. make
        1. 错误
            ext/sqlite3/libsqlite/sqlite3.o: In function `unixDlError':
            /home/Qt/rootfs/busybox/php/php-5.5.31/ext/sqlite3/libsqlite/sqlite3.c:31521: undefined reference to `dlerror'
            ext/sqlite3/libsqlite/sqlite3.o: In function `unixDlClose':
            /home/Qt/rootfs/busybox/php/php-5.5.31/ext/sqlite3/libsqlite/sqlite3.c:31552: undefined reference to `dlclose'
            ext/sqlite3/libsqlite/sqlite3.o: In function `unixDlSym':
            /home/Qt/rootfs/busybox/php/php-5.5.31/ext/sqlite3/libsqlite/sqlite3.c:31548: undefined reference to `dlsym'
            ext/sqlite3/libsqlite/sqlite3.o: In function `unixDlOpen':
            /home/Qt/rootfs/busybox/php/php-5.5.31/ext/sqlite3/libsqlite/sqlite3.c:31507: undefined reference to `dlopen'
            collect2: error: ld returned 1 exit status
            make: *** [sapi/cli/php] Error 1
        2. 解决方法:
            修改Makefile中的:
                EXTRA_LIBS = -lcrypt -lcrypt -lrt -lz -lm -lcrypt -lcrypt 
            为:
                EXTRA_LIBS = -lcrypt -lcrypt -lrt -lz -lm -lcrypt -lcrypt -ldl
        3. 效果:
            end_closures.lo Zend/zend_float.lo Zend/zend_string.lo Zend/zend_signal.lo Zend/zend_generators.lo Zend/zend_objects.lo Zend/zend_object_handlers.lo Zend/zend_objects_API.lo Zend/zend_default_classes.lo Zend/zend_execute.lo main/internal_functions_cli.lo sapi/cgi/cgi_main.lo sapi/cgi/fastcgi.lo -lcrypt -lcrypt -lrt -lz -lm -lcrypt -lcrypt -ldl  -o sapi/cgi/php-cgi

            Build complete.
            Don't forget to run 'make test'.
    3. sudo make install
    4. 拷贝PC机/usr/local/php目录下文件到:<filesystem root>/usr/local/php
    5. 配置httpd.conf:
        cat /etc/httpd.conf
            *.php:/usr/local/php/bin/php-cgi
    6. cat /www/test.php
        <?
            phpinfo();
        ?>
    7. PC机浏览器访问:http://10.0.1.52/test.php
        1. 报错现象:
        This PHP CGI binary was compiled with force-cgi-redirect enabled. This means that a page will only be served up if the REDIRECT_STATUS CGI variable is set, e.g. via an Apache Action directive.
        For more information as to why this behaviour exists, see the manual page for CGI security.
        For more information about changing this behaviour or re-enabling this webserver, consult the installation file that came with this distribution, or visit the manual page.
        2. 解决办法:
            将force-cgi-redirect设置disable。
    8. 查看php.ini位置:
        [zengjf@root /usr/local/php/bin]# ./php-cgi -i | grep ini
        <tr><td class="e">Configuration File (php.ini) Path </td><td class="v">/usr/local/php/lib </td></tr>
        <tr><td class="e">Loaded Configuration File </td><td class="v">/usr/local/php/lib/php.ini </td></tr>
        <tr><td class="e">Scan this dir for additional .ini files </td><td class="v">(none) </td></tr>
        <tr><td class="e">Additional .ini files parsed </td><td class="v">(none) </td></tr>
        <tr><td class="e">user_ini.cache_ttl</td><td class="v">300</td><td class="v">300</td></tr>
        <tr><td class="e">user_ini.filename</td><td class="v">.user.ini</td><td class="v">.user.ini</td></tr>
        <tr><td class="e">Classes </td><td class="v">AppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, CallbackFilterIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, GlobIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException </td></tr>
    9. 配置php.ini:
        cat /usr/local/php/lib/php.ini
            cgi.force_redirect = 0
            cgi.redirect_status_env ="yes";
    10. PC机浏览器访问:http://10.0.1.52/test.php
        经验证获取到了正确信息,Vim里贴不上图,就不贴图了。
    11. shell响应如下:
        [zengjf@root /usr/local/php/lib]# /usr/sbin/httpd -vv -f -h /www/
        10.0.1.50:58652: url:/
        10.0.1.50:58652: response:200
        10.0.1.50:58656: url:/test.php

四、编译、安装、测试sqlite3:
    1. ./configure --host=arm-linux-gnueabihf --prefix=/usr/local/sqlite
    2. make
    3. sudo make install
        1. 报错:
            libtool: install: /usr/bin/install -c .libs/libsqlite3.a /usr/local/sqlite/lib/libsqlite3.a
            libtool: install: chmod 644 /usr/local/sqlite/lib/libsqlite3.a
            libtool: install: arm-linux-gnueabihf-ranlib /usr/local/sqlite/lib/libsqlite3.a
            ./libtool: line 1720: arm-linux-gnueabihf-ranlib: command not found
            make[1]: *** [install-libLTLIBRARIES] Error 127
            make[1]: Leaving directory `/home/Qt/rootfs/busybox/sqlite/sqlite-autoconf-3100200'
            make: *** [install-am] Error 2
        2. 解决方法:
            是由于使用了sudo,导致环境变丢失,用su切换到root用户,再重新设置环境变量来解决。
    4. 拷贝/usr/local/sqlite中的文件到<filesystem root>下对应的目录。
    5. 建立软链接:ln -s /bin/sqlite3 /bin/sqlite
    6. 不能使用退格键(backspace):
        1. 错误现象:
            [zengjf@root ~]# sqlite
            SQLite version 3.10.2 2016-01-20 15:27:19
            Enter ".help" for usage hints.
            Connected to a transient in-memory database.
            Use ".open FILENAME" to reopen on a persistent database.
            sqlite> shw^H^H^H^H^H
        2. 解决方法:
            终端执行shell命令:stty erase ^H
    7. 在ARM板上运行效果如下:
        [zengjf@root ~]# sqlite
        SQLite version 3.10.2 2016-01-20 15:27:19
        Enter ".help" for usage hints.
        Connected to a transient in-memory database.
        Use ".open FILENAME" to reopen on a persistent database.
        sqlite> .show
                echo: off
                 eqp: off
          explain: off
             headers: off
                mode: list
           nullvalue: ""
              output: stdout
        colseparator: "|"
        rowseparator: "\n"
               stats: off
               width: 
        sqlite> .quit
        [zengjf@root ~]# 
    8. cat /www/teatdb.php
        <?
            $db = new SQLite3('my_database') or die('Unable to open database');
            $query = <<<EOD
              CREATE TABLE IF NOT EXISTS users (
                username STRING PRIMARY KEY,
                password STRING)
        EOD;    # 这里一定要顶格
            $db->exec($query) or die('Create db failed');
            $query = <<<EOD
              INSERT INTO users VALUES ( 'zengjf', 'root' )
        EOD;    # 这里一定要顶格
            $db->exec($query) or die("Unable to add user $user");
            $result = $db->query('SELECT * FROM users') or die('Query failed');
            while ($row = $result->fetchArray())
            {
              echo "User: {$row['username']}\nPasswd: {$row['password']}\n";
            }
        ?>
    9. PC机浏览器访问:http://10.0.1.52/testdb.php
        经验证获取到了正确信息,Vim里贴不上图,就不贴图了。
    10. shell响应如下:
        [zengjf@root ~]# 
        127.0.0.1:54905: url:/
        127.0.0.1:54905: response:200
        10.0.1.50:51536: url:/testdb.php
    11. 可能错误:
        1. Fatal error: Class 'SQLiteDatabase' not found in /www/testdb.php on line 3
        2. 这是由于移植的sqlite3,可能这里使用的是sqlite的接口,
           使用sqlite3的接口可以避免这个错误。

 

目录
相关文章
|
SQL 存储 PHP
PHP中使用SQLite数据库
SQLite是一种轻量级数据库引擎,数据以文件存储,支持SQL操作。PHP可连接SQLite执行CRUD操作。
359 4
|
Shell Serverless PHP
函数计算 php 运行环境添加 pdo_sqlite 扩展
编译pdo_sqlite并添加到函数计算php运行环境
906 0
函数计算 php 运行环境添加 pdo_sqlite 扩展
|
PHP 数据库 数据库管理
Run busybox httpd with php, sqlite
/*********************************************************************************** * Run busybox httpd with php, sqlite * ...
1521 0
|
Ubuntu PHP Apache
ubuntu下为php安装sqlite模块
apt-get install php5-sqlite 之后重启apache就行啦 sudo /etc/init.d/apache2 restart 修改配置 sudo gedit /etc/php5/apache2/php.ini
1938 0
|
3月前
|
关系型数据库 MySQL PHP
PHP和Mysql前后端交互效果实现
本文介绍了使用PHP连接MySQL数据库的基本函数及其实现案例。内容涵盖数据库连接、选择数据库、执行查询、获取结果等常用操作,并通过用户登录和修改密码的功能实例,展示了PHP与MySQL的交互过程及代码实现。
284 0
PHP和Mysql前后端交互效果实现
|
8月前
|
关系型数据库 MySQL Linux
查看Linux、Apache、MySQL、PHP版本的技巧
以上就是查看Linux、Apache、MySQL、PHP版本信息的方法。希望这些信息能帮助你更好地理解和使用你的LAMP技术栈。
399 17
|
前端开发 关系型数据库 MySQL
PHP与MySQL动态网站开发实战指南####
【10月更文挑战第21天】 本文将深入浅出地探讨如何使用PHP与MySQL构建一个动态网站,从环境搭建到项目部署,全程实战演示。无论你是编程新手还是希望巩固Web开发技能的老手,都能在这篇文章中找到实用的技巧和启发。我们将一起探索如何通过PHP处理用户请求,利用MySQL存储数据,并最终呈现动态内容给用户,打造属于自己的在线平台。 ####
532 0
|
9月前
|
关系型数据库 MySQL PHP
源码编译安装LAMP(HTTP服务,MYSQL ,PHP,以及bbs论坛)
通过以上步骤,你可以成功地在一台Linux服务器上从源码编译并安装LAMP环境,并配置一个BBS论坛(Discuz!)。这些步骤涵盖了从安装依赖、下载源代码、配置编译到安装完成的所有细节。每个命令的解释确保了过程的透明度,使即使是非专业人士也能够理解整个流程。
251 18
|
10月前
|
关系型数据库 MySQL 网络安全
如何排查和解决PHP连接数据库MYSQL失败写锁的问题
通过本文的介绍,您可以系统地了解如何排查和解决PHP连接MySQL数据库失败及写锁问题。通过检查配置、确保服务启动、调整防火墙设置和用户权限,以及识别和解决长时间运行的事务和死锁问题,可以有效地保障应用的稳定运行。
397 25
|
12月前
|
SQL 关系型数据库 MySQL
PHP与MySQL的高效交互:从基础到实践####
本文深入探讨了PHP与MySQL数据库之间的高效交互技术,涵盖了从基础连接到高级查询优化的全过程。不同于传统的摘要概述,这里我们直接以一段精简代码示例作为引子,展示如何在PHP中实现与MySQL的快速连接与简单查询,随后文章将围绕这一核心,逐步展开详细讲解,旨在为读者提供一个从入门到精通的实战指南。 ```php <?php // 数据库配置信息 $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "test_db"; // 创建连接 $conn = new mysqli($se
315 31