Sources : http://httpd.apache.org/docs/2.4/howto/cgi.html
Prérequis
Installation
nano /usr/local/apache2/conf/httpd.conf
- Modifications dans httpd.conf
#Décommenter la ligne du module # cgid_module LoadModule cgid_module modules/mod_cgid.so
<IfModule alias_module> ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/" </IfModule>
<IfModule cgid_module> # # ScriptSock: On threaded servers, designate the path to the UNIX # socket used to communicate with the CGI daemon of mod_cgid. # Dans notre cas, le serveur Apache n'utilise pas les thread. Pas besoin ici. # Scriptsock cgisock </IfModule>
# /usr/local/apache2/cgi-bin should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. <Directory "/usr/local/apache2/cgi-bin"> AllowOverride None Options ExecCGI SetHandler cgi-script Require all granted </Directory>
<IfModule mime_module>
# ...
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
# Décommenter la ligne ci-dessous et ajouter .pl
AddHandler cgi-script .cgi .pl
[...]
- Pour tester si le module CGI est actif, on va utiliser et renommer les fichiers situés dans /usr/local/apache2/cgi-bin. Attention, penser à remettre ensuite à l’état d’origine !!!
chmod a+x /usr/local/apache2/cgi-bin/*
- Editer chaque fichier (printenv et test-cgi), et indiquer la première ligne avec:
path/to/perl = #!/usr/lib/perl5 (pour printenv)
path/to/sh = #!/bin/sh (pour test-cgi)
- Renommer les fichiers en .pl
- Tester : http://localhost/cgi-bin/test-cgi.pl
On devrait obtenir une page de test qui ressemble à ça :
CGI/1.0 test script report: argc is 0. argv is . SERVER_SOFTWARE = Apache/2.4.3 (Unix) PHP/5.4.8 SERVER_NAME = x.x.x.x GATEWAY_INTERFACE = CGI/1.1 SERVER_PROTOCOL = HTTP/1.1 SERVER_PORT = 80 REQUEST_METHOD = GET HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 PATH_INFO = PATH_TRANSLATED = SCRIPT_NAME = /cgi-bin/test-cgi.pl QUERY_STRING = REMOTE_HOST = REMOTE_ADDR = x.x.x.x REMOTE_USER = AUTH_TYPE = CONTENT_TYPE = CONTENT_LENGTH =