/***********************************************************************************
* Run busybox httpd with php, sqlite
*
*
* 2016-1-20 深圳 南山平山村 曾剑锋
**********************************************************************************/ 文章出处:
Run busybox httpd with php
https://box.matto.nl/busyboxphp.html Run busybox httpd with php For many purposes a light webserver is good enough. This page looks into running httpd from busybox with php and sqlite.
在绝大多数的场合下,一个轻量级的web服务器足以应付。这篇文章阐述如何使用busybox的httpd、php、sqlite来搭建一个web服务器。 一、Busybox httpd
.The following actions will be explained below:
. Compile busybox with httpd.
. Create a directory as document root.
. Test httpd.
. Compile busybox with httpd.
. Create a directory as document root.
As an example, create the directory /var/www and put some html-documents into this directory.
. Test httpd:
Now run
/usr/sbin/httpd -vv -f -h /var/www/
This will run httpd in the forground. Because of the -vv switch messages will be displayed here. Now open a webbrowser to the ip-address of your machine and check the messages. . 接下来将解释如下内容:
. 编译选中了了httpd的busybox;
. 创建web服务器根目录;
. 测试httpd服务器;
. 编译选中了了httpd的busybox;
. 创建一个目录用于存放web文件;
例如:创建一个叫"/var/www"的目录,并将一些html文件放入其中;
. 测试httpd服务器:
运行如下shell命令:
/usr/sbin/httpd -vv -f -h /var/www/
如上命令会运行httpd服务器。-vv参数会将一些信息打印出来。打开web浏览器并访问你自己电脑的ip地址,检查web服务器打印的信息。
二、Install php5-cgi
. The following actions will be explained below.
. Put php5-cgi in /usr/bin and make sure the needed libraries are installed.
. Create /etc/httpd.conf
. Check php.ini
. Test httpd with php.
. When ldd is installed on the busybox system this can be used to check if any libraries are missing:
ldd /usr/bin/php5-cgi
If ldd is not installed, then find out which libraries are missing by running /usr/bin/php5-cgi on the commandline.
. /etc/httpd.conf
Put the following in /etc/httpd.conf:
*.php:/usr/bin/php5-cgi
. Check php.ini
Check which ini-file is used
Check contents of the ini-file
. Check which ini-file is used
Check which ini-file is used by php5-cgi with the following command:
php5-cgi -i | grep ini
. Check contents of the ini-file
Check that the ini-file contains the following lines:
cgi.force_redirect =
cgi.redirect_status_env ="yes";
. Test httpd with php.
. Create a test.php-file with phpinfo in it.
. cat /var/www/test.php
<?
phpinfo();
?>
. Stop the httpd if it is still running with Ctrl-C and restart it.
/usr/sbin/httpd -vv -f -h /var/www/
. Now point your browser to the test.php file.
. You should see something like this:
phpinfo in busybox <丢失图片>
. If the webserver does not show something like this but throws an error message, then check the messages from the -vv switch. . 接下来的内容主要介绍如下内容:
. 将php5-cgi放入/usr/bin目录下,并确保需要的库都安装了;
. 创建/etc/http.conf文件;
. 检查php.ini文件;
. 使用php测试httpd服务器。
. 如果在busybox文件系统里安装了ldd,那么可以使用它来检查任何丢失的库:
ldd /usr/bin/php5-cgi
如果ldd没有被安装,那就只能通过命令行运行/usr/bin/php5-cgi来检查丢失的库。
. 修改/etc/httpd.conf:
将如下内容加入/etc/http.conf文件中
*.php:/usr/bin/php5-cgi
. 检查php.ini文件:
. 检查那个init-file被使用了;
. 检查init-file中的内容;
. 检查那个init-file被使用了:
通过下面这个命令来检查那个init-file被php5-cgi使用了:
php5-cgi -i | grep ini
. 检查init-file中的内容:
检查init-file中下面这两行内容:
cgi.force_redirect =
cgi.redirect_status_env = "yes";
. 使用php测试httpd
. 创建test.php文件,在里面写入phpinfo:
. cat /var/www/test.php
<?
phpinfo();
?>
. 如果httpd还在运行的话,通过Ctrl-C停止httpd,通过下面命令重新运行。
/usr/sbin/httpd -vv -f -h /var/www/
. 指定浏览器访问test.php文件;
. 你可以看到如下内容:
phpinfo in busybox <丢失图片>
. 如果web服务器给出如上内容,并且抛出了一个错误信息,那么请检查web服务器-vv给出的信息。 三、Run the webserver from startup
Now change your startup script to start the httpd at system start. Put something like the following line in your startup-scripts.
/usr/sbin/httpd -h /var/www/ 现在你可以在你的开机脚本中加入开启httpd服务器的代码,如下:
/usr/sbin/httpd -h /var/www/ 四、Add SQLite to php
. Now that our webserver is up and running and is able to parse php scripts, it is time to add a database to the system.
. In many cases we don't need all the power that comes with MySQL. SQLite is a great alternative in those cases.
. Add libsqlite
. Add php5-sqlite
. Restart httpd
. Add libsqlite
Add the following files to /usr/lib:
. libsqlite.so.
. libsqlite3.so.
. Add php5-sqlite
Add the following files to /etc/php5/cgi/conf.d:
pdo_sqlite.ini
sqlite.ini
sqlite3.ini
. Restart the webserver and do some testing
First we make a testfile testdb.php with a small script that creates a database and a table, puts some data in the database and retrieves it.
<?
// create new database (OO interface)
$db = new SQLiteDatabase("testdb"); // create table names and insert sample data
$db->query("BEGIN;
CREATE TABLE names (id INTEGER PRIMARY KEY, name CHAR());
INSERT INTO names (name) VALUES('Foo');
INSERT INTO names (name) VALUES('Bar');
COMMIT;"); // retrieve the data
$result = $db->query("SELECT * FROM names");
// iterate through the retrieved rows
while ($result->valid()) {
// fetch current row
$row = $result->current();
print_r($row);
echo "<br />";
// proceed to next row
$result->next();
} ?>
. Stop httpd if it is still running.
. Now run
/usr/sbin/httpd -vv -f -h /var/www/
. And point your browser to testdb.php
. See the messages to check everything is OK.
. If everything is working OK, kill the webserver and start it without the -vv and without the -f switches. . 现在我们的web服务器能够正常的运行,并解析php脚本,是时候在系统中添加数据库了。
. 在很多情况下,我们并不需要MySQL所有的功能,SQLite是不二的选择,接下来涉及如下内容:
. 添加sqlite库;
. 添加php5对sqlite的支持;
. 重启httpd服务器;
. 添加sqlite库:
往/usb/lib中添加sqlite库:
. libsqlite.so.
. libsqlite3.so.
. 添加php5对sqlite支持库:
往/etc/php5/cgi/conf.d中添加如下文件:
. pdo_sqlite.ini;
. sqlite.ini;
. sqlite3.init;
. 重启并测试httpd服务器:
. 创建一个testdb.php文件;
. 在testdb.php文件中加入如下内容:
. testdb.php创建了一个表,加入了一些内容,然后查询它;
<?
// create new database (OO interface)
$db = new SQLiteDatabase("testdb"); // create table names and insert sample data
$db->query("BEGIN;
CREATE TABLE names (id INTEGER PRIMARY KEY, name CHAR());
INSERT INTO names (name) VALUES('Foo');
INSERT INTO names (name) VALUES('Bar');
COMMIT;"); // retrieve the data
$result = $db->query("SELECT * FROM names");
// iterate through the retrieved rows
while ($result->valid()) {
// fetch current row
$row = $result->current();
print_r($row);
echo "<br />";
// proceed to next row
$result->next();
} ?>
. 如果httpd服务器还在运行,那么就关闭它;
. 然后运行如下命令:
/usr/sbin/httpd -vv -f -h /var/www/
. 指定浏览器访问testdb.php文件;
. 查看信息是否正确;
. 如果所有的都正常,那么关闭web服务器,去掉-vv和-f参数,重启。 五、Create a lightweight LXC Linux container with busybox httpd and php
The instructions above where used to create a lightweight LXC container. The container system is based on busybox with dropbear. The busybox httpd is used as an webserver. This is great for light usage (like developing php applications. Busybox and dropbear were compiled from source while php5-cgi and the needed libraries were copied from a Debian installation. 如上的操作说明主要适用于创建一个轻量级的LXC(Linux Container)容器。这个容器系统是基于busybox和dropbear(轻量的sshd服务器)。busybox用于web服务器。这是非常有用的(就像开发php应用。Busybox和dropbear使用源代码编译,php5-cgi和需要的库都是从Debian中拷贝的)。

Run busybox httpd with php, sqlite的更多相关文章

  1. busybox filesystem httpd php-5.5.31 sqlite3 webserver

    /******************************************************************** * busybox filesystem httpd php ...

  2. 第七章 Rolling update

    7.1 实践 apiVersion: apps/v1beta1 kind: Deployment metadata: name: httpd spec: replicas: 3 template: m ...

  3. 在Fedora8上配置Apache Httpd

    原以为Fedora8我安装的是最简版本,于是去Apache Httpd官网下一个httpd,但是速度很成问题,现在还没有下完. 打开Fedora8的光盘,里面有httpd-2.2.6.3-3.i386 ...

  4. buildroot httpd php

    /******************************************************************** * buildroot httpd php * 说明: * ...

  5. busybox filesystem matrix-gui-2.0 undefined function json_encode()

    /******************************************************************************** * matrix-gui-2.0 u ...

  6. httpd基础

    hpptd http服务器应用 http服务器程序 httpd apache nginx lighttpd 应用程序服务器 IIS .asp tomcat .jsp jetty 开源的servlet容 ...

  7. 项目——基于httpd镜像演示Dockerfile所有的指令

    基于httpd镜像演示Dockerfile所有的指令: 第一步:创建Dockerfile工作目录 [root@localhost harbor]# mkdir /test [root@localhos ...

  8. apache主配置文件httpd.conf详解

    [root@lamp conf]# vi httpd.conf.bak 1 # 2 # This is the main Apache HTTP server configuration file. ...

  9. k8s中运行busybox

    简介 参考百度百科 BusyBox 是一个集成了三百多个最常用Linux命令和工具的软件. BusyBox 包含了一些简单的工具,例如ls.cat和echo等等,还包含了一些更大.更复杂的工具,例gr ...

随机推荐

  1. POJ 1680 Fork() Makes Trouble

    原题链接:http://poj.org/problem?id=1680 对这道题,我只能说:我不知道题目是什么意思,但是AC还是没有问题的. 看来题目半天没明白fork()怎么个工作,但是看样例(根据 ...

  2. Matlab与科学计算的基本运算

    各种允许的比较关系 >, >=, <, <=, ==,~=, find(), all(), any() 例:>> A=[1,2,3;4,5,6;7,8,0]A = ...

  3. setDepthStencilState

    cgfx->hlsl StencilFunc={always,1,0xff}->setDepthStencilState(DepthState,0) StencilFunc={always ...

  4. PHP创建XML文件讲解

    <?php   #code by coder_apex 2007-6-15   #自动生成一个如下的XML文件   #   #       <?xml version="1.0& ...

  5. Even Fibonacci numbers

    --Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting ...

  6. mac os 下如何清除/切换svn eclipse插件的用户

    以mac os x为例(Unix/Linux类似), 1.打开命令行窗口,即用户的根目录(用户的home目录) $ ls -al ... drwxr-xr-x   6 linxyz  staff   ...

  7. POJ1159Palindrome

    http://poj.org/problem?id=1159 题意 : 给定一个字符串,问最少插入多少字符,使该字符串变成回文串 思路 : 设原字符串序为X,逆序列为Y,则最少需要补充的字母数 = X ...

  8. 【转载】jxl操作excel 字体 背景色 合并单元格 列宽等 .

    package com.email.jav; import java.io.File;import java.io.IOException;import java.net.URL; import jx ...

  9. lintcode:Fibonacci 斐波纳契数列

    题目: 斐波纳契数列 查找斐波纳契数列中第 N 个数. 所谓的斐波纳契数列是指: 前2个数是 0 和 1 . 第 i 个数是第 i-1 个数和第i-2 个数的和. 斐波纳契数列的前10个数字是: 0, ...

  10. 【PSR规范专题(1)】PSR-0+namespace+spl_autoload_register实现框架模型

    了解命名空间 namespace是PHP5.3版本加入的新特性,用来解决在编写类库或应用程序时创建可重用的代码如类或函数时碰到的两类问题: 用户编写的代码与PHP内部的类/函数/常量或第三方类/函数/ ...