1

When I try to run a CGI script in my browser, the /var/log/apache2/error.log file says:

[Wed Jan 03 22:12:36.302682 2018] [cgi:error] [pid 5308] [client
::1:54384] AH01215: (13)Permission denied: exec of
'/var/www/cgi/invoker.cgi' failed: /var/www/cgi/invoker.cgi

My .cgi file is inside the /var/www/cgi folder and contains:

#!/bin/bash 
java Main

Main.java contains(It creates a .class file after "javac Main.java"):

public class Main {

    public static void main(String[] args) {

        String content = "Content-Type:html/css\n\n";
        String html = "<html>\n" +
                "<body>\n" +
                "<h1>Hi, what's up?</h1>\n" +
                "</body>\n" +
                "</html>";
        System.out.println(content);
        System.out.println(html);
    }
}

/etc/apache2/ports.conf contains:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80 

<IfModule ssl_module>    

Listen 443  

</IfModule> 

<IfModule mod_gnutls.c> 

Listen 443  

</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

At the top of /etc/apache2/apache2.conf I added:

ServerName localhost

/etc/apache2/sites-enabled/000-default.conf contains:

<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 webmaster@localhost
    DocumentRoot /var/www/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


ScriptAlias /cgi/ /var/www/cgi/
<Directory "/var/www/cgi">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

    # 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
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Also, is the .cgi files supposed to be .cgi or .sh and why when I set it to executable, the browser starts downloading it, instead of showing the HTML? I have made this work, but it was before I reinstalled my Linux Mint. I have tried everything and if somebody can fix this for me, it would be great ;)

4
  • do you have permission to run the script invoker.cgi?
    – Reimeus
    Jan 3, 2018 at 20:38
  • 1
    ls -l to check if the script has execute permissions
    – MikeJ
    Jan 3, 2018 at 20:39
  • 1
    Make sure your file invoker.cgi has execute permission for the Apache process (also check it does not have write permission). Make sure the file has linux line endings (not DOS). Make sure suexec is not messing things up.
    – SQL Hacks
    Jan 3, 2018 at 20:40
  • @SQLHacks how can I give execute permissions for the Apache process
    – iccaka
    Jan 3, 2018 at 20:51

1 Answer 1

1

Make the script executable with chmod 755 /var/www/cgi/invoker.cgi.

1
  • When I enter "localhost:80/cgi/invoker.cgi", the browser starts downloading the file instead of showing the HTML
    – iccaka
    Jan 5, 2018 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.