-   Linux - Server (
-   -   Web applications on xen machine cannot connect to databases (

aluchko 07-09-2008 07:33 PM

Web applications on xen machine cannot connect to databases [SOLVED]
Turns out I forgot about SELinux (again).


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 or even it again fails, however using 'localhost' instead of '' 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?


A sample line from the apache error_log

[Sun Jul 06 16:58:47 2008] [error] [client] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on '' (13) in /var/www/html/test.php on line 2
One of the scripts.
PHP Code:

if (!
$link) {
'Could not connect: ' mysql_error());
'Connected successfully';


[root@web ~]# route
Kernel IP routing table
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface    *      U    0      0        0 eth0
default        UG    0      0        0 eth0
[root@web ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:6E:A7:97
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::216:3eff:fe6e:a797/64 Scope:Link
          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)

lo        Link encap:Local Loopback
          inet addr:  Mask:
          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)

Swagata Paul 07-10-2008 01:28 AM

$link = mysql_connect('','foo', 'bar);

I think you have to put an "'" after "bar"......
i.e. the line should be: $link = mysql_connect('','foo', 'bar');

aluchko 07-10-2008 01:38 AM


Originally Posted by Swagata Paul (Post 3209668)
$link = mysql_connect('','foo', 'bar);

I think you have to put an "'" after "bar"......
i.e. the line should be: $link = mysql_connect('','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.

All times are GMT -5. The time now is 04:09 PM.