Setup Apache for Perl and CGI

Setup Apache for Perl and CGI

Setup Apache for Perl and CGI

If you have some older Perl apps that you want to keep going instead of re-write them, here’s the basic process of setting up apache, testing the perl scripts, and then executing them via CGI.

login, and su to root

Root shell prompt on the web2 Apache server

edit the apache configuration for the Instance in question

mkdir cgi and chmod 775 cgi in the user's home directory

from here add the following to the bottom on the config file:

<Directory “/var/www/html/websitename/cgi/”>
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl
</Directory>

make sure to restart the apache instance after making this change.

you must also create the “cgi” folder in that directory.

Same screenshot: mkdir cgi and chmod 775 cgi

vi helloworld.pl

vi helloworld.pl in the cgi directory

add the following code:

helloworld.pl Perl script with #!/usr/bin/perl and print hello world

from here need to test first if the perl script works normally

perl helloworld.pl printing hello world

Great, it works, now we need to make it work with CGI

chmod +x helloworld.pl

so… the print “content-type” that makes it web executable, note that this must be placed BEFORE any other commands

We also need to make the file executable:

Same screenshot: chmod +x helloworld.pl to make the script executable

now if we go to our website, and point it to the cgi bin:

http://sitename/cgi/helloworld.pl

we should now see:

Same chmod +x helloworld.pl screenshot repeated under the browser test step

That’s it!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Install Apache on CentOS 6.4 | Disable Apache Version

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *