Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 659
user3026793 Avatar asked Nov 24 '13 08:11

user3026793


People also ask

How do I configure Apache to run CGI scripts?

Let's make it executable by typing a sudo chmod +x /var/www/cgi-bin/loggedin.sh and hit enter. We need to turn on an SELinux Boolean to allow CGI scripts. Type in clear and then type in sudo setsebool -P httpd_enable_cgi 1 and hit enter. Now let's restart Apache.


2 Answers

Try with this command:

sudo a2enmod cgi

Then restart apache!

like image 125
tops Avatar answered Oct 10 '22 03:10

tops


I encountered this problem when trying to setup bugzilla in Ubuntu 14.04 @Andrew's answer was helful and so was @Kevin's links.. so other than enabling cgi, ensure that perl's module for apache2 is installed. You can do this by:

sudo apt-get install libapache2-mod-perl2

This will automatically enable the module as well as restart apache server. If not do that manually.

Don't have enough rep to upvote both of you, so thanks.

like image 45
kaykae Avatar answered Oct 10 '22 03:10

kaykae