Cgi files not executing

Hello,
I have some CGI files written in Perl (extension .cgi) in the cgi-bin directory, but instead of executing, it shows the file content.
If anyone knows how to solve this, please help.

if I am not mistaken, there is no native support for cgi/perl anymore for quite some time. the cgi-bin folder is more or less a leftover from the days of vesta where the php cgi wrapper had it’s home, if you used that instead of prefork/modphp…

if you want to run cgi/perl you most likely need to enable additional stuff within apache like adding additional handlers for the file types and setting an alias for that folder/path.

maybe someone from the community can help with that, I haven’t used it in ages… sorry.

Thank you. I thought that if it’s there, it should work and I’m forgetting something. It’s no problem at all, I’ll just rewrite that file in php;)
Thank you again for clearing this up for me.

1 Like

Sorry for reopening this old thread. ^^’
But I’ve got the same question. I’ve got a ton of Perl scripts I’m using. Basically my whole website is written in Perl.
And unfortunately I couldn’t find a really good manual explaining on how to enable Perl/CGI in Apache.
I’m planning to migrate my existing website from a managed hosted provider (where execution of Perl scripts is allowed in any directory) to a root server. To ease the setup I installed HestiaCP.
With HestiaCP a few things are different (EG different locations of the configuation files) and I must admit, that my knowledge of Apache, NGINX and so on is not that deep…
Otherwise I could have installed everything on my own and wouldn’t use a Control Panel. :slight_smile:

Does anyone know how to enable Perl/CGI scirpts (ending .pl and .cgi) in combination of HestiaCP or knows a good manual to do so?
mod_perl is installed and I also enabled the CGI and Perl modules in Apache2.
Unfortunately the main source ( https://perl.apache.org ) of information seems to be outdated. :frowning:

Thanks a lot!

If you are running on either Debian or Ubuntu, SSH into your server as root and type “a2enmod cgi”. Then restart the apache server with “systemctl restart apache2”.
The cgi module is enabled by default on CentOS and Fedora. Hope this helps others who are old perl throwbacks like myself.

Thanks. :slight_smile:

Meanwhile I managed to do that. However you also need to adjust the apache configuration files to allow CGI/Perl scripts to be executed.

Can you guide me on how to configure Apache to allow cgi scripts? Thanks

I am not exactly sure what I did completely.

In my enabled Apache2 Modules I have fcgid, perl & cgid.
If they are already installed, you may need to enable them using a2enmod
EG: a2enmod perl

Then you have to build a custom apache template file following this: Web Templates and FastCGI/Proxy Cache | Hestia Control Panel

Here are the two I am using for https/non-https:
Since I have several domains running on this server, all showing the same stuff I am using the <directory to point to the digioso.tk directory.
On default settings you should probably use %domain% instead of digioso.tk

root@digioso:/usr/local/hestia/data/templates/web/apache2/php-fpm# cat digioso.stpl
#=========================================================================#
# Default Web Domain Template                                             #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS   #
# https://docs.hestiacp.com/admin_docs/web.html#how-do-web-templates-work #
#=========================================================================#

<VirtualHost %ip%:%web_ssl_port%>

    RewriteEngine on
    ServerName %domain_idn%
    %alias_string%
    ServerAdmin %email%
    DocumentRoot %sdocroot%
    ScriptAlias /cgi-bin/ %home%/%user%/web/digioso.tk/public_html/cgi-bin/
    Alias /vstats/ %home%/%user%/web/%domain%/stats/
    Alias /error/ %home%/%user%/web/%domain%/document_errors/
    #SuexecUserGroup %user% %group%
    CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
    CustomLog /var/log/%web_system%/domains/%domain%.log combined
    ErrorLog /var/log/%web_system%/domains/%domain%.error.log
    <Directory /home/digioso/web/digioso.tk/public_html>
        AddHandler perl-script .pl .cgi
        PerlResponseHandler ModPerl::Registry
        PerlOptions +ParseHeaders
        Options +Includes -Indexes +ExecCGI +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        SSLRequireSSL
        Allow from all
    </Directory>
    <Directory %home%/%user%/web/%domain%/stats>
        AllowOverride All
    </Directory>
    <Directory %sdocroot%>
        AllowOverride All
        SSLRequireSSL
        Options +Includes -Indexes +ExecCGI
        </Directory>
    SSLEngine on
    SSLVerifyClient none
    SSLCertificateFile %ssl_crt%
    SSLCertificateKeyFile %ssl_key%
    %ssl_ca_str%SSLCertificateChainFile %ssl_ca%

    <FilesMatch \.php$>
        SetHandler "proxy:%backend_lsnr%|fcgi://localhost"
    </FilesMatch>
    SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

    IncludeOptional %home%/%user%/conf/web/%domain%/%web_system%.ssl.conf_*
    IncludeOptional /etc/apache2/conf.d/*.inc
</VirtualHost>

root@digioso:/usr/local/hestia/data/templates/web/apache2/php-fpm# cat digioso.tpl
#=========================================================================#
# Default Web Domain Template                                             #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS   #
# https://docs.hestiacp.com/admin_docs/web.html#how-do-web-templates-work #
#=========================================================================#

<VirtualHost %ip%:%web_port%>

    RewriteEngine on
    ServerName %domain_idn%
    %alias_string%
    ServerAdmin %email%
    DocumentRoot %docroot%
    ScriptAlias /cgi-bin/ %home%/%user%/web/digioso.tk/public_html/cgi-bin/
    Alias /vstats/ %home%/%user%/web/%domain%/stats/
    Alias /error/ %home%/%user%/web/%domain%/document_errors/
    #SuexecUserGroup %user% %group%
    CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
    CustomLog /var/log/%web_system%/domains/%domain%.log combined
    ErrorLog /var/log/%web_system%/domains/%domain%.error.log

    IncludeOptional %home%/%user%/conf/web/%domain%/apache2.forcessl.conf*

<Directory /home/digioso/web/digioso.tk/public_html>
        AddHandler perl-script .pl .cgi
        Options +Includes -Indexes +ExecCGI +FollowSymLinks +MultiViews
        PerlResponseHandler ModPerl::Registry
        PerlOptions +ParseHeaders
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    <Directory %home%/%user%/web/%domain%/stats>
        AllowOverride All
    </Directory>
    <Directory %sdocroot%>
        AllowOverride All
        Options +Includes -Indexes +ExecCGI
    </Directory>

    <FilesMatch \.php$>
        SetHandler "proxy:%backend_lsnr%|fcgi://localhost"
    </FilesMatch>
    SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

    IncludeOptional %home%/%user%/conf/web/%domain%/%web_system%.conf_*
    IncludeOptional /etc/apache2/conf.d/*.inc
</VirtualHost>

root@digioso:/usr/local/hestia/data/templates/web/apache2/php-fpm#

1 Like