View previous topic :: View next topic |
Author |
Message |
zion1459 Tux's lil' helper
Joined: 12 Mar 2003 Posts: 146
|
Posted: Sat May 03, 2003 7:12 am Post subject: apache wont connect to mysql using perl |
|
|
Hi.
I've emerged apache2 and it works great. Also installed mysql but from the tar ball from their website since when I emerged it a compile error accured.
Apache works great and the same goes for mysql.
but when I create a perl script that connects to the mysql server it simply doesn't work. Now I haven't coded the script wrong I know that.
I've not been using apache for long and not with perl before... is there some special post install procedures I need to do, some modules or something which needs to be installed before apache can allow a perl script to connect to mysql?
connecting to the mysql manually goes smoothly... |
|
Back to top |
|
|
slartibartfasz Veteran
Joined: 29 Oct 2002 Posts: 1462 Location: Vienna, Austria
|
Posted: Sat May 03, 2003 11:21 am Post subject: |
|
|
u have to make sure that the script has proper permissions to connect to mysql - not only the name and pwd are important but also the host... if mysql allows connections from localhost that doesnt mean that i allows connections from your.host.org ....
if this doesnt help u, u have to post the apache and mysql logs and the script here... _________________ To an engineer the glass is neither half full, nor half empty - it is just twice as big as it needs to be. |
|
Back to top |
|
|
esammer Retired Dev
Joined: 05 Apr 2003 Posts: 155 Location: NY, US
|
Posted: Sat May 03, 2003 11:21 am Post subject: |
|
|
There's nothing special you have to do to get a script to connect to mysql. Apache knows nothing about mysql - the script does, so it's not an Apache issue. Here's an example of a common database connection to mysql:
Code: |
use strict;
use DBI;
my $dbh = DBI->connect("dbi:mysql:mydatabase", "myusername", "mypassword") or
die "Database error: $DBI::errstr\n";
## statements go here
$dbh->disconnect();
|
You should always use 'or die...' so you can see if errors occur. Scripts calling die will log to the Apache error log. Without knowing more about your script or configuration, I can't go much beyond that. You should make sure your code is right because Apache won't "stop" a script from connecting to a database. Here's some common things to check:
1. Do any scripts work?
2. What gets logged in the error log (with the above code)?
3. Are you connecting via an external ip from perl (1.2.3.4) or using a local connection? It matters because mysql might be denying external connections. (Hint. Check the mysql permission tables).
4. Is the DBD::mysql module installed and finding all shared libraries ok?
Give that a shot and you might get a bit closer. When in doubt, look for examples, check logs, and read the docs.
HTH. |
|
Back to top |
|
|
zion1459 Tux's lil' helper
Joined: 12 Mar 2003 Posts: 146
|
Posted: Sat May 03, 2003 12:25 pm Post subject: |
|
|
This is what apache says:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
DBI is installed (emerge DBI) .. so I guess there must be a problem finding the shared libraries. How do I correct this? |
|
Back to top |
|
|
esammer Retired Dev
Joined: 05 Apr 2003 Posts: 155 Location: NY, US
|
Posted: Sat May 03, 2003 12:48 pm Post subject: |
|
|
Well, you're going to have to provide a bit more information than that. What is logged to the error log? Try what I said in my previous post... |
|
Back to top |
|
|
slartibartfasz Veteran
Joined: 29 Oct 2002 Posts: 1462 Location: Vienna, Austria
|
Posted: Sat May 03, 2003 12:49 pm Post subject: |
|
|
do:
Code: |
tail -f /var/log/apache2/error_log
|
and watch the output while u execute the script - if u dont understand the output post it here.. _________________ To an engineer the glass is neither half full, nor half empty - it is just twice as big as it needs to be. |
|
Back to top |
|
|
zion1459 Tux's lil' helper
Joined: 12 Mar 2003 Posts: 146
|
Posted: Sat May 03, 2003 12:59 pm Post subject: |
|
|
ok.. this is from the err_log... don't really understand what it means:
(me f33ls like a total n00b :O :S this aint healthy lmao)
[Sat May 03 14:56:09 2003] [error] [client 127.0.0.1] Premature end of script headers: test.pl |
|
Back to top |
|
|
esammer Retired Dev
Joined: 05 Apr 2003 Posts: 155 Location: NY, US
|
Posted: Sat May 03, 2003 1:03 pm Post subject: |
|
|
It looks like you have a syntax error in your script. Give this a shot on the command line:
Code: | # perl -cw /path/to/my/script.pl |
That will tell you where in your script the errors are. You should be able to run the script on the command line as well, which will help with debugging.
Check out www.perl.com for info on common CGI debugging methods.
HTH. |
|
Back to top |
|
|
zion1459 Tux's lil' helper
Joined: 12 Mar 2003 Posts: 146
|
Posted: Sat May 03, 2003 3:47 pm Post subject: |
|
|
omg! I feel so fscking lame right now hehe..
first time it didn't work there was an error in my mysql configurations..
and this time it was a script error... just didn't think it cuz debugging didn't give me any errors.. I had forgotten
"print "Content type: test/html\r\n\r\n;"
in a big document which prints tons from a database to the screen.. no wonder it didn't work lmao.
I hate when something so obvious is causing the problem hehe.
thx for the help slartibartfasz and esammer much appreciated |
|
Back to top |
|
|
slartibartfasz Veteran
Joined: 29 Oct 2002 Posts: 1462 Location: Vienna, Austria
|
Posted: Sat May 03, 2003 10:36 pm Post subject: |
|
|
np - happens to the best of us
anyway - i developed a habit of setting the apache loglevel to debug and keep a 'tail -f error_log' running when working with cgi - speeds up debugging a lot... _________________ To an engineer the glass is neither half full, nor half empty - it is just twice as big as it needs to be. |
|
Back to top |
|
|
|