Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9874 Discussions

How to enable CGI module of lighttpd server on Galileo

YZhan71
Novice
3,149 Views

【English - 英文】

Hi,

I have a problem on using CGI of lighttpd of yocto linux on Galileo.

I have installed the yocto linux on SD card and boot Galileo from it, and I have a CGI test program written in Python located in /www/pages/cgi

print("Content-type:text/html\n\n")

print('')

print('')

print('')

print('')

print('Hello, World!')

print('')

print('')

and I have change its mode:

chmod 755 test.py

In order to enable the CGI module, I modified file /etc/lighttpd.conf like this:

server.modules = (

...

"mod_cgi",

...

(I deleted the '# ' before "mod_cgi" to enable it)

However, after rebooting Galileo, I typed the address of CGI program for example:

http://192.168.0.4:80/cgi/test.py http://192.168.0.4:80/cgi/test.py

"403 - Forbidden" is displayed on browser.

It doesn't work.

Seems that the CGI module of lighttpd is not exist...

How can I enable the CGI module of lighttpd?

Need I compile the whole OS to enable the CGI module of lighttpd?

Thanks.

【Chinese - 中文】

大家过年好~

我在SD卡里面烧写了官方提供的yocto linux,

并且用Python写了一段测试用的CGI程序,位于/www/pages/cgi,代码如下:

print("Content-type:text/html\n\n")

print('')

print('')

print('')

print('')

print('Hello, World!')

print('')

print('')

赋予其可执行权限:

chmod 755 test.py

我想使用Python编写的CGI程序去处理POST/GET请求,因此修改配置文件/etc/lighttpd.conf如下:

server.modules = (

...

"mod_cgi",

...

(删除了注释)

但重启Galileo板子之后,浏览器访问这个py脚本,会提示"403-Foridden",反正就是跑不起来……

感觉官方提供的Yocto镜像根本就没有CGI模块啊……

所以我想问问大家,如何启用lighttpd的CGI模块?是不是需要从头开始编译系统?

谢谢~

(论坛里如果有懂汉语的朋友我们可以认识一下o(^▽^)o)

0 Kudos
1 Solution
YZhan71
Novice
937 Views

【English - 英文】

I have solved this problem by myself...

The CGI module was not installed in yocto linux. So I installed it and enabled it. Very easy.

In order to download software needed, I bought a wlan adapter "Intel Corporation Centrino Advanced-N 6205 AGN" and enabled Wi-Fi connection following the instructions provided by this page: https://software.intel.com/en-us/node/519955 IoT - Connecting to a Wi-Fi Network | Intel® Software

After establishing connection to Internet, Input command line

opkg install lighttpd-module-cgi

and wait.

Modify the configuration file of lighttpd /etc/lighttpd.conf like that:

server.modules = (

...

"mod_cgi",

...

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".py" )

...

cgi.assign = ( ".pl" => "/usr/bin/perl",

".cgi" => "/usr/bin/perl",

".py" => "/usr/bin/python" )

I modified the port number of lighttpd to 81 for convenience.

Type and execute the command:

lighttpd -f /etc/lighttpd.conf

I make a directory /www/pages/cgi-bin and put test.py in it. The content of test.py is

# !/usr/bin/env python

# -*- coding: utf-8 -*-

import commands

import cgi

import os

print('Content-Type:text/html\n\n')

print('"')

print('CGI TEST / CGI测试')

print('

by mikukonai@IntelCommunity

')

print('')

print('

Shell Command Test: Reading BMP280 Barometer

')

print('

以下是Shell命令执行测试:读取BMP280传感器返回的气压数据

')

print( commands.getoutput('/home/root/bmp280/bmp280_pressure') )

Test it, and It works!

Hope this helps to anyone in need

【Chinese - 中文】

最后我自己解决了这个问题……其实很简单,CGI模块没有安装而已。

淘宝上买了一块网卡,型号是 Centrino Advanced-N 6205 AGN,按照这个页面 https://software.intel.com/en-us/node/519955 IoT - Connecting to a Wi-Fi Network | Intel® Software 的说明联网。

联网后执行如下命令,安装cgi模块:

opkg install lighttpd-module-cgi

修改配置文件 /etc/lighttpd.conf 如下,以启用CGI:

server.modules = (

...

"mod_cgi",

...

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".py" )

...

cgi.assign = ( ".pl" => "/usr/bin/perl",

".cgi" => "/usr/bin/perl",

".py" => "/usr/bin/python" )

为了方便我把lighttpd的端口改成了81。(因为我不知道如何重启lighttpd(捂脸哭))

载入修改后的配置文件:

lighttpd -f /etc/lighttpd.conf

新建目录 /www/pages/cgi-bin 并将 test.py 置于其中,代码如下:

# !/usr/bin/env python

# -*- coding: utf-8 -*-

import commands

import cgi

import os

print('Content-Type:text/html\n\n')

print('"')

print('CGI TEST / CGI测试')

print('

by mikukonai@IntelCommunity

')

print('')

print('

Shell Command Test: Reading BMP280 Barometer

')

print('

以下是Shell命令执行测试:读取BMP280传感器返回的气压数据

')

print( commands.getoutput('/home/root/bmp280/bmp280_pressure') )

测试,成功!

希望能帮到您

View solution in original post

3 Replies
FTinetti
Honored Contributor I
937 Views

Hi mikukonai,

I've not used lighttpd-python CGI, I've used an "only-python" setting:

a) start a python web server with CGI enabled, with the command line:

python -m CGIHTTPServer > pythonsrvr.out 2> pythonsrvr.err &

b) use it

Please let me know in case these instructions are not complete enough for you, I can try to make a small complete example.

HTH,

Fernando.

YZhan71
Novice
937 Views

Thank you very much.

I referred other documentations such as https://docs.python.org/2.7/library/cgihttpserver.html 20.20. CGIHTTPServer — CGI-capable HTTP request handler — Python 2.7.13 documentation

I tried it and managed to start the server with CGI.

But I still don't know how to enable CGI module of lighttpd

CGIHTTPServer has a worse performance than other servers.

YZhan71
Novice
938 Views

【English - 英文】

I have solved this problem by myself...

The CGI module was not installed in yocto linux. So I installed it and enabled it. Very easy.

In order to download software needed, I bought a wlan adapter "Intel Corporation Centrino Advanced-N 6205 AGN" and enabled Wi-Fi connection following the instructions provided by this page: https://software.intel.com/en-us/node/519955 IoT - Connecting to a Wi-Fi Network | Intel® Software

After establishing connection to Internet, Input command line

opkg install lighttpd-module-cgi

and wait.

Modify the configuration file of lighttpd /etc/lighttpd.conf like that:

server.modules = (

...

"mod_cgi",

...

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".py" )

...

cgi.assign = ( ".pl" => "/usr/bin/perl",

".cgi" => "/usr/bin/perl",

".py" => "/usr/bin/python" )

I modified the port number of lighttpd to 81 for convenience.

Type and execute the command:

lighttpd -f /etc/lighttpd.conf

I make a directory /www/pages/cgi-bin and put test.py in it. The content of test.py is

# !/usr/bin/env python

# -*- coding: utf-8 -*-

import commands

import cgi

import os

print('Content-Type:text/html\n\n')

print('"')

print('CGI TEST / CGI测试')

print('

by mikukonai@IntelCommunity

')

print('')

print('

Shell Command Test: Reading BMP280 Barometer

')

print('

以下是Shell命令执行测试:读取BMP280传感器返回的气压数据

')

print( commands.getoutput('/home/root/bmp280/bmp280_pressure') )

Test it, and It works!

Hope this helps to anyone in need

【Chinese - 中文】

最后我自己解决了这个问题……其实很简单,CGI模块没有安装而已。

淘宝上买了一块网卡,型号是 Centrino Advanced-N 6205 AGN,按照这个页面 https://software.intel.com/en-us/node/519955 IoT - Connecting to a Wi-Fi Network | Intel® Software 的说明联网。

联网后执行如下命令,安装cgi模块:

opkg install lighttpd-module-cgi

修改配置文件 /etc/lighttpd.conf 如下,以启用CGI:

server.modules = (

...

"mod_cgi",

...

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".py" )

...

cgi.assign = ( ".pl" => "/usr/bin/perl",

".cgi" => "/usr/bin/perl",

".py" => "/usr/bin/python" )

为了方便我把lighttpd的端口改成了81。(因为我不知道如何重启lighttpd(捂脸哭))

载入修改后的配置文件:

lighttpd -f /etc/lighttpd.conf

新建目录 /www/pages/cgi-bin 并将 test.py 置于其中,代码如下:

# !/usr/bin/env python

# -*- coding: utf-8 -*-

import commands

import cgi

import os

print('Content-Type:text/html\n\n')

print('"')

print('CGI TEST / CGI测试')

print('

by mikukonai@IntelCommunity

')

print('')

print('

Shell Command Test: Reading BMP280 Barometer

')

print('

以下是Shell命令执行测试:读取BMP280传感器返回的气压数据

')

print( commands.getoutput('/home/root/bmp280/bmp280_pressure') )

测试,成功!

希望能帮到您

Reply