Getting Started with CGI and Apache on Debian GNU/Linux

1 篇文章 0 订阅
1 篇文章 0 订阅

https://blog.csdn.net/zoomdy/article/details/89348939
https://blog.csdn.net/z896435317/article/details/77863030
https://blog.csdn.net/zjhqlmzldx/article/details/83615256
https://blog.csdn.net/u011728480/article/details/51871298
http://httpd.apache.org/docs/2.2/howto/cgi.html

Debian GNU/Linux 10 (buster)
https://blog.csdn.net/u011728480/article/details/51871298

cat /etc/apache2/
ls

sites-enabled    mods-enabled    conf-enabled

vim /sites-enabled/000-default.conf

# Include conf-available/serve-cgi-bin.conf                                            # modified and deleted '#'
Include conf-available/serve-cgi-bin.conf                                               
:wq
# http://httpd.apache.org/docs/2.2/howto/cgi.html

vim /mods-enabled/mime.load

LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
LoadModule cgid_module /usr/lib/apache2/modules/mod_cgid.so
LoadModule cgi_module /usr/lib/apache2/modules/mod_cgi.so             # add
:wq

vim /mods-enabled/dir.conf

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.py index.sh index.rb
:wq
# http://httpd.apache.org/docs/2.2/howto/cgi.html

vim /conf-enabled/serve-cgi-bin.conf

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
# default directory is /usr/lib/cgi-bin/
# ScriptAlias /cgi-bin/ /var/www/cgi-bin/ 
# configure cgi-bin directory is /var/www/cgi-bin/ 
AddHandler cgi-script .cgi .pl .py .sh .rb                                                      # add
:wq

sudo /etc/init.d/apache2 restart
service apache2 restart

# http://httpd.apache.org/docs/2.2/howto/cgi.html
Writing a CGI program
My first CGI program with C/C++, Perl, Python, Shell, Ruby

which gcc g++ gfortran sh bash perl ruby python


index.pl

#!/usr/bin/env perl
print "Content-type: text/html\n\n";
print "Hello, World."; 
chmod a+x index.pl
./index.pl

index.py

#!/usr/bin/env python
print "Content-type: text/html\n\n";
print "Hello, World."; 
chmod a+x index.py
./index.py

index.c

#include <stdio.h>
int main(int argc, char* argv[]) {
            printf("Content-type: text/html\n\n");
            printf("Hello, World.\n");
            return 0;
}
gcc index.c -o index.cgi
./index.cgi

 index.sh

#!/usr/bash
echo "Content-type: text/html\n\n";
echo "Hello, World.";
chmod a+x index.sh
./index.sh

index.rb 

#!/usr/bin/env ruby
# one way
# puts "Content-type: text/html\n\n"
# puts "<html><body>This is a test</body></html>"
# puts "Hello, World."
# another way
require 'cgi'
cgi = CGI.new
puts cgi.header
puts "<html><body>This is a test</body></html>"
chmod a+x index.rb
./index.rb


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值