Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2883664
  • 博文数量: 674
  • 博客积分: 17881
  • 博客等级: 上将
  • 技术积分: 4849
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 10:15
文章分类

全部博文(674)

文章存档

2013年(34)

2012年(146)

2011年(197)

2010年(297)

分类: LINUX

2010-07-17 09:53:34

如何让mini_httpd支持php


那天听清茶说再搞mini_httpd,可是cgi跑不起来,反正我那天也有空,所以自己也下载了一个mini_httpd玩玩.
(把过程写下来,让有类似需求的兄弟少走弯路,
嘿嘿,还有就是自己比较的健忘~~~)


下载代码,解压缩,然后
make
make install
呵呵,很顺利,很方便
(看看版本:
/usr/local/sbin/mini_httpd -V
mini_httpd/1.19 19dec2003
)
mkdir /mini_httpd
mkdir /mini_httpd/wwwroot
useradd mini
chown -R mini:mini /mini_httpd
su - mini

然后写一个 /mini_httpd/mini.conf
port=8080
dir=/mini_httpd/wwwroot
cgipat=**.php
user=mini
pidfile=/mini_httpd/mini_httpd.pid
logfile=/mini_httpd/mini_httpd.log

接着启动mini_httpd
/usr/local/sbin/mini_httpd  -C /mini_httpd/mini.conf

顺利启动,不过有警告(先不研究这个)
/usr/local/sbin/mini_httpd: started as root without requesting chroot(), warning only

打开我放在/mini_httpd/wwwroot下的index.htm ,没问题
可是info.php却执行不了啊~~~
cat /mini_httpd/wwwroot/info.php
#!/usr/bin/php
phpinfo();
?>;

出现这样的提示:

Security Alert! The PHP CGI cannot be accessed directly.

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.


看到 force-cgi-redirect 这个东西,马上到/etc/php.ini 里面找,果然是有,马上修改为
cgi.force_redirect = Off

然后再访问info.php

可惜还是出错~~~ 出现提示:

No input file specified.

 


还是上google搜索搜索吧, 搜索 mini_httpd php
果然找到解决的线索了~~

^_^,还是牛人多啊,牛人说:
In the past there have been issues with mini_httpd and php, mainly because php relies on the presence of certain environment variables which, while not strictly demanded by the RFCs, are provided by Apache and many other 'major' web servers. To make a long story short, I wrote a small patch for mini_httpd-1.19.
大致是说在过去,mini_httpd和php在一起运行是有问题,因为php需要依赖几个特定的环境变量才可以在mini_httpd下工作,但是这几个环境变量不是RFCs严格要求一定要有的,只有Apache和其他几个主流的web server才提供的.不过为了让大家使用方便,牛人写了一个补丁给大家.
而且为了方便很多象我一样不会打不定的菜鸟使用方便,还给出了打好不定的min_httpd下载.

原话是:
For those shy of patching software, here's the pre-patched source code. Please bear in mind that this is not meant as some kind of code forking, and when in doubt, please download and use the source on the official mini_httpd web site.


哈哈,正是我要的东西~~~
马上下载安装~~
看看版本:
/usr/local/sbin/mini_httpd -V
mini_httpd/1.19/bhoc 23sep2004


还是用原来的mini.conf文件启动mini_httpd

/usr/local/sbin/mini_httpd  -C /mini_httpd/mini.conf

再次访问info.php,一切都正常了!

 

如何让mini_httpd支持php


我自己琢磨出来了。
在这里写出来方法和观点,给大家参考、讨论:
=================================

在minihttpd下面,php是作为CGI来运行的;

因此,所有的php文件都应该和用perl等其他语言写出来的CGI脚本一样:

php脚本的属性应该是:chmod a+x *.php

php文件的内容,从第一行:
#!/usr/bin/php
##解释程序!!
;
输出 html 头!
;
;

..................

其中,在引用GET、POST 变量的时候,也不能依照PHP的用法,而是CGI的用法!!

但是,PHP的简单容易使用的优点都没有啦!考虑到他是解释执行、代码容易泄露的缺点,我还要他来干什么啊!!还不如用C来写呢!

 

ok,以后再研究里面的chroot~~

 

下面是我加的:

   在移植到ARM板的过程中,主要有如下几个问题:

 

  • 使用的编译器arm-linux-gcc 3.3.2
  1. 在编译mini_httpd时,首先更换环境变量,将第一编译环境指向ARM编译环境,必须将MAKEFILE文件中的编译器修改成arm-linux-gcc.
  2. 编译PHP编译时碰到一个问题,有一个错误,该产生错误处屏蔽掉(好像该处只是专门为IBM提供的),编译通过,目标文件在spai/cgi或者cli下,5.5M的巨无霸,使用arm-linux-strip 压缩,大小为1.2M
  3. 将上面两个文件移植到目标板文件系统中,注意mini_httpd的配置文件(mini_https.conf)内容必须修改成目标机的相应内容.其中屏蔽掉chroot,以及一些日志设置. 
  4. 运行时PHP提示缺少一个动态库libnsl.so.1,该库是交叉编译器的/lib下的文件,最终的库为libnsl-3.3.2.so,libnsl.so.1是一个链接,将该库拷贝到目标机文件系统的lib下,注意名称修改为libnsl.so.1
  5. 将php文件的属性一定要修改好,注意PHP针对的PHP文件运行是按照CGI方式运行的,所以所有的PHP文件属性必须修改成可运行的

阅读(3214) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~