|Think about Loose Coupling|
puzzling problem with access to DB when using mod_perlby ted.byers (Scribe)
|on Dec 28, 2012 at 04:25 UTC||Need Help??|
ted.byers has asked for the
wisdom of the Perl Monks concerning the following question:
I followed one set of instructions for writing a handler for use with mod_perl. Here is what I added to the end of apache2.conf (on Ubuntu 12.04):
And here is the handler package code:
Obviously, the example I followed did not involve the use of DBI. If the DBI code is commented out, the Hello handler works as the example implied (though I successfully extended the example to include getting the request parameters).
I know the above example does not (yet) do anything with $dbh. I first wanted to see if I could successfully connect to the DB before running any queries. Alas, I could not take this further because Apache gives me a 500 error. On examining the logs, I see the following entry (after a timestamp)): "DBI connect ('database==192.168.2.24','rejbyers',...) failed: Access denied for user 'rejbyers'@'localhost' (using password: YES) at /home/ted/modperlhandler/Hello.pm line 22."
Now, to verify that the database server is in fact reachable, I wrote the following CGI script and placed it in /usr/lib/cgi-bin (on Ubuntu):
This CGI script worked as expected. Hence, the puzzle. On the same Ubuntu (virtual) machine, my mod_perl handler fails to connect to the database server, but my cgi script, using the same credentials, does connect to the database server. Why?
As an aside, I have, in addition to mod_perl, fastcgi enabled, and Apache::DBI is installed (and, unless I misunderstood the configuration instructions, apache's httpd server is configured to use it). My worry is that all the instructional materials for using Apache::DBI and fastcgi that I have found are quite old. While I am still studying effective use of mod-perl, do fastcgi and Apache::DBI remain good options? If so, how do they fit with what I have been doing with CGI and what I am trying to learn for using mod_perl?