Enabling CGI/Perl scripts in Ubuntu Apache 2

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