web development in perl, mod_perl
while not exactly a perl expert, i have written some programs that create graphs, access databases, read log files, and web pages that live in the cgi-bin directory so i would consider myself knowledgable of the basics.
however, i would like to use perl more, especially as a replacement for php, the basket of which i would not like to place all my metaphorical programming eggs. especially in the area of web design, i want to be able to use perl in all the same ways i can use php currently.
so how do you write web pages in perl that do not have to be in the cgi-bin directory to work? somewhere in some previous post, i posed the question: why can php pages work anywhere but perl pages only in this one directory?
it turns out there is a way to let perl scripts be executed from anywhere in the web directory (well, sort of, read on...). just as there is a php module for apache, there is also a perl module for apache. in the case of my fedora core 5 box running apache 2, mod_perl version 2 is already loaded. basically all i have to do is configure apache to recognize it. this is how:
under /etc/httpd/, there exists conf/httpd.conf which is the main apache config file. this in turn includes all the files that end in .conf in the conf.d/ directory. one of these files is perl.conf. in this file, the "Alias" line and the section specifying the directory where the perl scripts will live must be uncommented. The path to that directory must be altered in both places as well. apache needs to be restarted then.
the directory where the perl scripts will live should not be the root web directory (/var/www/html/) but should be a subdirectory of this. i created a directory named "perl-bin" (/var/www/html/perl-bin) but any name will do- just be sure this is the directory referred to in the perl.conf file. apache now expects everything in this directory to be a perl script. a regular old html file will not be served by apache but a file named "hello.html" that is actually a perl script will be.
place a perl file with a .pl, .cgi, .html,... extension in this directory and it will now be rendered correctly. the file starts like this:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
then contains a PRINT handle which the html is fed into. i cannot post this all because blogger will actually try to render the html.
the obvious gains of this approach are (a) files can be located in a user-named directory other than cgi-bin and (b) files can have a .html extension (not restricted to .pl and .cgi). however, the limitation that the perl scripts must be segregated to an exclusively-perl-scripts directory still exists in contrast to the quality of php scripts to be run from any directory and alongside files of other types.
however, i would like to use perl more, especially as a replacement for php, the basket of which i would not like to place all my metaphorical programming eggs. especially in the area of web design, i want to be able to use perl in all the same ways i can use php currently.
so how do you write web pages in perl that do not have to be in the cgi-bin directory to work? somewhere in some previous post, i posed the question: why can php pages work anywhere but perl pages only in this one directory?
it turns out there is a way to let perl scripts be executed from anywhere in the web directory (well, sort of, read on...). just as there is a php module for apache, there is also a perl module for apache. in the case of my fedora core 5 box running apache 2, mod_perl version 2 is already loaded. basically all i have to do is configure apache to recognize it. this is how:
under /etc/httpd/, there exists conf/httpd.conf which is the main apache config file. this in turn includes all the files that end in .conf in the conf.d/ directory. one of these files is perl.conf. in this file, the "Alias" line and the section specifying the directory where the perl scripts will live must be uncommented. The path to that directory must be altered in both places as well. apache needs to be restarted then.
the directory where the perl scripts will live should not be the root web directory (/var/www/html/) but should be a subdirectory of this. i created a directory named "perl-bin" (/var/www/html/perl-bin) but any name will do- just be sure this is the directory referred to in the perl.conf file. apache now expects everything in this directory to be a perl script. a regular old html file will not be served by apache but a file named "hello.html" that is actually a perl script will be.
place a perl file with a .pl, .cgi, .html,... extension in this directory and it will now be rendered correctly. the file starts like this:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
then contains a PRINT handle which the html is fed into. i cannot post this all because blogger will actually try to render the html.
the obvious gains of this approach are (a) files can be located in a user-named directory other than cgi-bin and (b) files can have a .html extension (not restricted to .pl and .cgi). however, the limitation that the perl scripts must be segregated to an exclusively-perl-scripts directory still exists in contrast to the quality of php scripts to be run from any directory and alongside files of other types.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home