4

This is my program:

[root@localhost cgi-bin]# locate first.pl 
/home/Ram/Desktop/work/first.pl
/usr/local/apache2/cgi-bin/first.pl
[root@localhost cgi-bin]# cd /usr/local/apache2/cgi-bin/
[root@localhost cgi-bin]# vi first.pl 
#!/usr/bin/perl -w
use warnings;
use warnings;
use CGI;
print "content-type: text/html\n\n";
print "<h2>Hello, World!</h2>\n";

I am calling the script from my browser like this:

http://localhost/usr/local/apache2/cgi-bin/first.pl

I didn't get output, but I'm getting an error:

Not Found

The requested URL /usr/local/apache2/cgi-bin/first.pl was not found on this server.

Apache/2.2.15 (CentOS) Server at localhost Port 80

I checked in web browser whether the Apache web server is working or not by using :

https://localhost

It us showing the welcome page.

How do I resolve this error?

6
  • can you add your virtual host configuration Commented Feb 11, 2014 at 10:08
  • no httpd.conf or if your virtual host has a separate config file include it Commented Feb 11, 2014 at 10:12
  • Try runnning "chmod 755 /usr/local/apache2/cgi-bin/first.pl" Commented Feb 11, 2014 at 10:13
  • can you tell me how to see the httpd.conf Commented Feb 11, 2014 at 10:14
  • @Mark Setchell in browser??? Commented Feb 11, 2014 at 10:15

3 Answers 3

6

You basically need to change two files after installing apache2 on linux.

Go to terminal and set the following configs:

  1. sudo vim /etc/apache2/sites-enabled/000-default.conf and add the follwing:

    <Files ~ "\.(pl|cgi)$">
        SetHandler perl-script
        PerlResponseHandler ModPerl::PerlRun
        Options +ExecCGI
        PerlSendHeader On
    </Files>
    
  2. sudo vim /etc/apache2/apache2.conf and add the following:

    <Directory /var/www/cgi-bin/> AddHandler cgi-script .cgi .pl Options FollowSymLinks ExecCGI AllowOverride None </Directory>

After adding these two config changes, write a perl script, place it in the cgi-bin directory, and then give it sufficient privileges (sudo chmod 755 <filename>)

Finally, restart apache2: sudo apache2ctl restart

Screenshots: default.conf apache2.conf

Sign up to request clarification or add additional context in comments.

Comments

6

Yes, the above process works but the easy way is:

  1. Enable the CGI- sudo a2enmod cgi
  2. Restart the Apache and it works -service apache2 restart
  3. Run the cgi file http://localhost/cgi-bin/1.sh

Best Of Luck !!

Comments

0

In your web configuration (httpd.conf or your virtual host configuration file) you should have the following fragment:

ScriptAlias /cgi-bin/ /etc/local/apache2/cgi-bin/
<Directory "/etc/local/apache2/cgi-bin">
   Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
</Directory>

restart the server, don't forget to chmod +x /usr/local/apache2/cgi-bin/first.pl and then load http://localhost/cgi-bin/first.pl

This assumes that either there are no virtual hosts in your config, or that the virtual host you configured is the default one. See the apache docs if needed.

6 Comments

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" # # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> this is only have
These /usr/local/apache2/conf/httpd.conf and /usr/local/apache2/conf/original/httpd.conf are only there in machine
on which one to check httpd.conf? please let me know
I would think it's /usr/local/apache2/conf/httpd.conf, but in any case, why not try one, and if it doesn't work try the other one?
was there a question hidden in your previous comment? ;--)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.