HostOnNet Blog

Enabling CGI/Perl scripts in Ubuntu Apache 2

Looking for Linux Server Admin or WordPress Expert? We can help.

Apache 2 in Ubuntu is configured to work with .pl/.cgi scripts by default. But it won’t work as cgi module is not loaded. To activate CGI scripts, you need to run

sudo a2enmod cgi
sudo service apache2 restart

Apache configuration used for localhost in my PC is

userName@fwhlin:~$ cat /etc/apache2/sites-available/000-default.conf
<VirtualHost 127.0.0.1:80>
        ServerAdmin webmaster@localhost
        SetEnv APP_ENV "dev"

        DocumentRoot /home/userName/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/userName/www/>
                Options All 
                AllowOverride All
                Require all granted
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /home/userName/www/cgi-bin/

        <Directory "/home/userName/www/cgi-bin/">
                AllowOverride None
                Require all granted
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        AddHandler cgi-script .cgi .pl


        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
userName@fwhlin:~$ 

Posted in Apache

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.