Newbie config problems with Apache Perl MySQL

Newbie config problems with Apache Perl MySQL

Post by Lorenzo Gord » Thu, 13 Dec 2001 01:13:40



Hi,

I have Red Hat 7 installed and running.
I also have the bundled Apached and Perl (seemingly) running o.k.
I have installed MySQL, and the DBI/DBD-MySQL modules.
They all seem o.k.:

I can my Perl script from the command line, and it will succcessfully
retireve the data from the mySQL DB.

I can run a simple Perl script through the server and that also works
o.k. (returns basic environment variables, prints hello, edits html
template, etc.)

But I am having lots of problems running the Perl script to access the
MySQL DB through the Apache server.
The error I get is the following 500 error:

-----
Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request

etc etc
-------

I checked the error log, which says the DBI->connect command failed,
and that it could no conenct to the local MySQL server (everything
here is running through the local server) through socket
'/var/lib/mysql/mysql.sock' (111)

Like I say, I have run the code from the command line (with the CGI
element) and it will connect to the MySQL DB without any difficulty.

I am quite new to both Linux and Apache: could someone please point
out what is going on here?
If it is an internal configuration error, then which bit, and what do
I need to do? (I have searched through the httpd.conf file and can
find nothing obvious)

Any pointers are very much appreciated,

Lorenzo.

P.S. - Here is a copy of the (very basic) Perl script:

--------
#!/usr/bin/perl

use CGI;
use DBI;

$dbh = DBI->connect("DBI:mysql:one_db", "serf", "readonly")
|| die "Could not connect to database: $DBI::errorstr\n";

$sqlstatement = "SELECT * FROM Names;";

$sth = $dbh->prepare($sqlstatement);
$sth->execute ||
      die "Could not execute SQL statement ... maybe invalid?";



 
 
 

Newbie config problems with Apache Perl MySQL

Post by Dr Hackenbus » Thu, 13 Dec 2001 05:22:29



Quote:> Hi,

You may be getting '500' because you do not generate the
required HTTP headers on stdout before the error message
(or does that go out on stderr?). Not sure if Module CGI
provides an over-ridden 'die'. Does the error message
appear in the error_log ?

The script needs to work as a stand-alone Perl program
before it can run as a CGI. Try that first.

When you go to run it as a CGI, you have to account for
changes to Environment variables and file permissions.

> -----
> Internal Server Error

> The server encountered an internal error or misconfiguration and was
> unable to complete your request

> etc etc
> -------

> I checked the error log, which says the DBI->connect command failed,
> and that it could no conenct to the local MySQL server (everything
> here is running through the local server) through socket
> '/var/lib/mysql/mysql.sock' (111)

> Like I say, I have run the code from the command line (with the CGI
> element) and it will connect to the MySQL DB without any difficulty.

> I am quite new to both Linux and Apache: could someone please point
> out what is going on here?
> If it is an internal configuration error, then which bit, and what
do
> I need to do? (I have searched through the httpd.conf file and can
> find nothing obvious)

> Any pointers are very much appreciated,

> Lorenzo.

> P.S. - Here is a copy of the (very basic) Perl script:

> --------
> #!/usr/bin/perl

> use CGI;
> use DBI;

> $dbh = DBI->connect("DBI:mysql:one_db", "serf", "readonly")
> || die "Could not connect to database: $DBI::errorstr\n";

> $sqlstatement = "SELECT * FROM Names;";

> $sth = $dbh->prepare($sqlstatement);
> $sth->execute ||
>       die "Could not execute SQL statement ... maybe invalid?";





 
 
 

Newbie config problems with Apache Perl MySQL

Post by Lorenzo Gord » Thu, 13 Dec 2001 08:50:20


Thanks for replying.

What I posted was not the entire Perl script, because the error
appears related to teh first call relating to the $dbh variable.

I do finish off the script with:

print ("Content-Type: Text/HTML\n\n");
print $results;

($results is my template page).

When i output the tempalte page without the code relating to $dbh, it
parses through the Apache server fine.
Any other ideas?

TIA,
Lorenzo.

> You may be getting '500' because you do not generate the
> required HTTP headers on stdout before the error message
> (or does that go out on stderr?). Not sure if Module CGI
> provides an over-ridden 'die'. Does the error message
> appear in the error_log ?

> The script needs to work as a stand-alone Perl program
> before it can run as a CGI. Try that first.

> When you go to run it as a CGI, you have to account for
> changes to Environment variables and file permissions.

> > -----
> > Internal Server Error

> > The server encountered an internal error or misconfiguration and was
> > unable to complete your request

> > etc etc
> > -------

> > I checked the error log, which says the DBI->connect command failed,
> > and that it could no conenct to the local MySQL server (everything
> > here is running through the local server) through socket
> > '/var/lib/mysql/mysql.sock' (111)

> > Like I say, I have run the code from the command line (with the CGI
> > element) and it will connect to the MySQL DB without any difficulty.

> > I am quite new to both Linux and Apache: could someone please point
> > out what is going on here?
> > If it is an internal configuration error, then which bit, and what
> do
> > I need to do? (I have searched through the httpd.conf file and can
> > find nothing obvious)

> > Any pointers are very much appreciated,

> > Lorenzo.

> > P.S. - Here is a copy of the (very basic) Perl script:

> > --------
> > #!/usr/bin/perl

> > use CGI;
> > use DBI;

> > $dbh = DBI->connect("DBI:mysql:one_db", "serf", "readonly")
> > || die "Could not connect to database: $DBI::errorstr\n";

> > $sqlstatement = "SELECT * FROM Names;";

> > $sth = $dbh->prepare($sqlstatement);
> > $sth->execute ||
> >       die "Could not execute SQL statement ... maybe invalid?";




 
 
 

1. Apache build via DSO with PHP3, Mod-perl & MySQL problem

Hi all,

Usually I build Apache statically using apaci to include php3 & modperl.
MySQL gets included when compiling in php (using --with-mysql). However,
I've recently wanted to try to add support for Java servlets (using
Resin1.1), and Resin wants to work via DSO (ie. LoadModule line in the
apache httpd.conf), so I'm trying to rebuild the whole thing in this way.

I can get Apache, Resin & PHP to install. However, whenever I
include --with-mysql in the ./configure line for php, and then attempt to
start apache, it won't start :o(

What is the proper sequence of commands to build everything using DSO?

I'm using Apache 1.3.12, PHP3.0.15, Mod-Perl 1.21, MySQL3.22.32 and Resin
1.1.

Kelv

2. kernel debugger for 2.2.14

3. Newbie ->Mysql & perl

4. X font closest to "fixedsys" on Windows

5. Quandry: locking tables & server crashes (Apache, Perl, MySQL)

6. Transparent remote access

7. PERL / MySQL and Apache

8. Box software for linux

9. apache, mysql, perl - giving users access

10. Which packages to load with apache, php, perl, mysql, xml

11. Newbie Basic Config Problem - RH 7.3 + Apache 1.3.23

12. Apache-Perl Config Error

13. How to config Apache for using perl ?