To enable perl-cgi or php in linux webserver


In one of my earlier posts, I had given the details of the process of configuring a webserver in linux. I had also mentioned enabling perl cgi and php. I would like to add a few more details along with examples in the present post.

In the file /etc/apache2/mods-available/userdir.conf
replace
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
with
Options MultiViews Indexes SymLinksIfOwnerMatch +ExecCGI
To check if the php is enabled in webserver copy the following lines
in /usr/lib/cgi-bin/testfile.php (path in ubuntu linux only)
<!--?php phpinfo(); ?>-->
Run the file in browser by
http://localhost/cgi-bin/testfile.php

To enable perl-cgi add the following lines at the end of the file

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>

restart the apache server by

sudo /etc/init.d/apache restart

Copy a sample perl-cgi script test.cgi in /usr/lib/cgi-bin check if it works. Here is test.cgi

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Environment\n";
foreach (sort keys %ENV)
{
print "$_: $ENV{$_}
\n";
}
1;

The script can be run by

http://localhost/cgi-bin/test.cgi

Advertisements

One thought on “To enable perl-cgi or php in linux webserver

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s