I can not execute my CGI files in my virtual host

December 3, 2018 3.3k views
Apache Perl Arch Linux

Hi everyone!

I can not execute my CGI files in my virtual host, this is the configuration of my file:
/etc/apache2/conf-available/serve-cgi-bin.conf

<IfModule mod_alias.c>
        <IfModule mod_cgi.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfModule mod_cgid.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfDefine ENABLE_USR_LIB_CGI_BIN>

ScriptAlias "/cgi-bin/" "/var/www/814.pe/public_html/cgi-bin/"
#Modified by me - start
#<Directory "/var/www/814.pe/public_html/cgi-bin/">
#                       AllowOverride None
#                       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
#                       AddHandler cgi-script .cgi .pl
#                       Require all granted
#                       SetHandler cgi-script
#               </Directory>
#Modified by me - end

<Directory "/var/www/814.pe/public_html/cgi-bin/mt/">
Options +ExecCGI
AddHandler cgi-script .cgi .pl
</Directory>

and this is the conf of my domain in which I try to run the scripts:
/etc/apache2/sites-available/814.pe.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin daniel@814.pe
        ServerName 814.pe
        ServerAlias www.814.pe
        DocumentRoot /var/www/814.pe/public_html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        # Include conf-available/serve-cgi-bin.conf

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =www.814.pe [OR]
        RewriteCond %{SERVER_NAME} =814.pe
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

#Modified by me - start
#ScriptAlias /cgi-bin/ /var/www/814.pe/public_html/cgi-bin/
#<Directory "/var/www/814.pe/public_html/cgi-bin/">
#                        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
#                        AddHandler cgi-script .cgi .pl
#                       AllowOverride None
#                       Require all granted
#                </Directory>
#Modified by me - end

</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

This is what i get in console apache error log:
Browser say: "Internal Server Error"
Console say: "[cgi:error] [pid 20550] [client 190.216.190.76:34913] End of script output before headers: test.cgi"

The problem gets worse if I decide to run the files in a folder inside my CGI-BIN folder:
Browser say: Not Found"
Console say: "script not found or unable to stat: /var/www/814.pe/public_html/cgi-bin/mt/test.cgi"

Whai i really need is make run this CGI files inside of a directory calls mt

Im using APACHE on Ubuntu 14.04.5 x64

Thnak you so much for oyur help guys.

3 Answers

What's the content of the fille cgi-bin/test.cgi?

  • is this:

    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    
    print "<html><head><title>Hello There...</title></head>";
    
    print "<body>";
    
    print "<h1>Hello, World.</h1><hr>";
    print "<p>This is some regular text.</p>";
    print "<p>The possibilities are great.</p>";
    
    print "</body></html>";
    

    Not important content, just try to run CGI-FIles

    • The error implies two things. Permissions are off to a degree that the "header" is not sent (hence the error "End of script output before headers"). Or that the CGI script itself doesn't send headers at all. So you have the header printed at the top of the script. What are the permissions on the file test.cgi file and directory?

App this to cgi.test the script works
chmod 755 /var/www/814.pe/public_html/cgi-bin/test.cgi

Is not the only CGI file in there, for example, to this cgi file:
[cgi:error] [pid 20563] [client 190.216.190.76:56449] End of script output before headers: mt-wizard.cgi

For others files in there I get this:
[cgi:error] [pid 20562] [client 190.216.190.76:52929] AH01215: (8)Exec format error: exec of '/var/www/814.pe/public_html/cgi-bin/index.html' failed

  • So test.cgi works OK now, correct?

    Can you run "perl mt-wizard.cgi" from the command line? What's the output?

I did, look like I need to install all those libraries

Can't locate MT/Bootstrap.pm in @INC (you may need to install the MT::Bootstrap module) (@INC contains: lib /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at /var/www/814.pe/public_html/cgi-bin/mt-wizard.cgi line 11.
BEGIN failed--compilation aborted at /var/www/814.pe/public_html/cgi-bin/mt-wizard.cgi line 11.
  • Yeah those can lead to the headers error. Re-run the script again after you install the libs until you get a clean output.

Have another answer? Share your knowledge.