LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-09-2008, 07:33 PM   #1
aluchko
Member
 
Registered: Mar 2004
Location: Edmonton, AB, Canada
Distribution: Fedora
Posts: 37

Rep: Reputation: 15
Web applications on xen machine cannot connect to databases [SOLVED]


Turns out I forgot about SELinux (again).

Running
Code:
setsebool -P httpd_can_network_connect_db on
Fixed my problem, on a side note another problem with Squirrelmail not being able to connect to the mailserver was solved by changing
/etc/php.ini: allow_url_include = Off
to On.




(by the way, if anyone knows how I can get the word wrap working on this post please let me know as I have no idea)

I'm having an issue where web applications running on apache, on a xen machine, cannot connect to databases over the network.

The configuration is a server running Fedora Core 6, on this server is a Xen machine running Fedora 9. This xen machine was installed with virt-install.

I don't know a lot of networking so it's whatever the default install did, I believe it connects directly to the router through the server's eth0 device using multicast (they both have their own IP and the router sees both machines as separate).

The essence of the problem is thus, I can write a script, in either php or python which connects to either a mysql or postgresql database on the server. Run from a bash terminal those scripts both run and connect fine, however, put those scripts into web application and neither script can connect to the server.

I've run wireshark on the server and confirmed that no packets are showing up there when the web apps try to make the connection.

In fact I replicated the databases onto the xen machine itself, if I try to connect to the localhost through either 192.168.1.5 or even 127.0.0.1 it again fails, however using 'localhost' instead of '127.0.0.1' works (note as usual everything works through the command line).

I'm pretty sure this isn't a problem with the apache configuration since I have a laptop running F9 and I went as far as copying over the entire /etc/httpd from the xen machine to the laptop and the laptop was still able to run the web apps properly and connect to the databases.

I was wondering if anyone had any idea what was going on or how to fix this?

Thanks,
Aaron

A sample line from the apache error_log
Code:
[Sun Jul 06 16:58:47 2008] [error] [client 192.168.1.2] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on '192.168.1.4' (13) in /var/www/html/test.php on line 2
One of the scripts.
PHP Code:
<?php
$link 
mysql_connect('192.168.1.4','foo''bar');
if (!
$link) {
    die(
'Could not connect: ' mysql_error());
}
echo 
'Connected successfully';
mysql_close($link);
?>
Useful?
Code:
[root@web ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
default         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
[root@web ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:6E:A7:97
          inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:fe6e:a797/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1827194 errors:0 dropped:0 overruns:0 frame:0
          TX packets:208698 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1038882019 (990.7 MiB)  TX bytes:18147937 (17.3 MiB)
          Interrupt:6

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:732 errors:0 dropped:0 overruns:0 frame:0
          TX packets:732 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:104226 (101.7 KiB)  TX bytes:104226 (101.7 KiB)

Last edited by aluchko; 07-13-2008 at 01:41 AM. Reason: found solution
 
Old 07-10-2008, 01:28 AM   #2
Swagata Paul
Member
 
Registered: Jun 2008
Location: Kolkata, India
Posts: 57

Rep: Reputation: 15
$link = mysql_connect('192.168.1.4','foo', 'bar);

I think you have to put an "'" after "bar"......
i.e. the line should be: $link = mysql_connect('192.168.1.4','foo', 'bar');
 
Old 07-10-2008, 01:38 AM   #3
aluchko
Member
 
Registered: Mar 2004
Location: Edmonton, AB, Canada
Distribution: Fedora
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Swagata Paul View Post
$link = mysql_connect('192.168.1.4','foo', 'bar);

I think you have to put an "'" after "bar"......
i.e. the line should be: $link = mysql_connect('192.168.1.4','foo', 'bar');
Must have deleted during copy/paste (will edit post), regardless as I noted the actual php and pythons scripts are good as they run on both the command line and on apache on another box.
 
  


Reply

Tags
apache2, xen



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: SELinux - Highly Secured Web Hosting for Python-based Web Applications LXer Syndicated Linux News 0 05-28-2008 07:30 AM
LXer: Are Open-Source Databases Ready for Production Applications? LXer Syndicated Linux News 0 08-16-2007 01:20 PM
LXer: SA's MySQL guru on databases and the Web LXer Syndicated Linux News 0 07-19-2007 05:31 PM
connect two databases using postgres? w0000422 Programming 3 02-21-2004 02:18 PM
Can i connect to MySQl databases through Telnet? Santorres Linux - Networking 2 01-27-2004 07:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration