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