FreeBSD: Configuring Apache to permit CGI

In httpd.conf file make sure the "cgi" LoadModule directive has not been commented out.
A correctly configured directive may look like this:


<IfModule mpm_prefork_module>
        LoadModule cgi_module libexec/apache24/mod_cgi.so
</IfModule>

Explicitly using Options to permit CGI execution
To allow CGI program execution for any file ending in .cgi in users' directories, you can use the following configuration.


<VirtualHost *:80>
    DocumentRoot "/usr/local/www/apache24/e"
    ServerName www.example.com
    ErrorLog "/var/log/e-error_log"
    CustomLog "/var/log/e-access_log" common

    <Directory "/usr/local/www/apache24/e/">
       Order allow,deny
       Allow from all
       Require all granted
       Options +ExecCGI
       AddHandler cgi-script .cgi
    </Directory>
</VirtualHost>


<Directory "/home/*/public_html">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

If you wish designate a cgi-bin subdirectory of a user's directory where everything will be treated as a CGI program, you can use the following.


<Directory "/home/*/public_html/cgi-bin">
Options ExecCGI
SetHandler cgi-script
</Directory>

A example to Monitor CPU Temperature

cputemp.cgi

#!/bin/sh
set -f
echo "Content-type: text/plain; charset=iso-8859-1"
echo
date
echo
sysctl dev.cpu | grep temperature
exit 0

Comments

Popular posts from this blog

Python3 + Django + uWSGI + Nginx On FreeBSD

arduino最小構成 (atmega328/8MHz/3.3V/内部クロック)FT232RLにてブートローダーの書き込み