Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 07-09-2008, 07:33 PM   #1
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).

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)

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

Rep: Reputation: 15
$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');
Old 07-10-2008, 01:38 AM   #3
Registered: Mar 2004
Location: Edmonton, AB, Canada
Distribution: Fedora
Posts: 37

Original Poster
Rep: Reputation: 15
Originally Posted by Swagata Paul View Post
$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.


apache2, xen

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 01:47 PM.

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