Cannot run cgi, show plain text only (Ubuntu 13.10 Apache 2.4)

user3026793 picture user3026793 · Nov 24, 2013 · Viewed 29.9k times · Source

I just install Ubuntu 13.10 and I am trying to install Apache. But when I tried to run a perl file in cgi-bin, the browser showed only plain text.

My default.conf of Apache is below:

    AddHandler cgi-script .cgi .pl
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +Indexes +ExecCGI +MultiViews +SymLinksIfOwnerMatch
            #Order allow,deny
            Require all granted
            Allow from all
    </Directory>

This is my perl cgi file:

    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    print "<html>\n";
    print "<title> PERL CGI</title>\n";
    print "<body>";
    print "hello perl-cgi!!!!!!!";
    print "</body>";
    print "</html>\n";

I have turned on the Handler in mime.conf The file is in /usr/lib/cgi-bin, and I run it as http not file:///. I have also installed mod_perl. I am new to Apache. I have searched for several hours, try endless Apache configurations, read Apache document but still cannot solve it. Is it because the "+ExecCGI" code has some problem? I saw another person also meet similar problem after updating Ubuntu 12.04 to 13.10. Maybe Ubuntu is the problem? Please help. The Apache configuration and Ubuntu permission almost drive me mad.

Answer

tops picture tops · Dec 9, 2013

Try with this command:

sudo a2enmod cgi

Then restart apache!