I can not execute my CGI files in my virtual host

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 mod_cgid.c>
                Define ENABLE_USR_LIB_CGI_BIN

        <IfDefine ENABLE_USR_LIB_CGI_BIN>

ScriptAlias "/cgi-bin/" "/var/www/"
#Modified by me - start
#<Directory "/var/www/">
#                       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/">
Options +ExecCGI
AddHandler cgi-script .cgi .pl

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

<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.

        DocumentRoot /var/www/

        # 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} [OR]
        RewriteCond %{SERVER_NAME}
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

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

# 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] 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/”

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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

Can't locate MT/ 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/ line 11.
BEGIN failed--compilation aborted at /var/www/ line 11.

App this to cgi.test the script works chmod 755 /var/www/

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

For others files in there I get this: [cgi:error] [pid 20562] [client] AH01215: (8)Exec format error: exec of ‘/var/www/’ failed

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