LinuxQuestions.org
Help answer threads with 0 replies.
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 04-17-2011, 12:19 PM   #1
avinc
LQ Newbie
 
Registered: Apr 2011
Posts: 10

Rep: Reputation: 0
Post Why the php mysql_connect() only can connect localhost MySQL?


Halo. I am very confused. Please help me

Background:
I used 4 host to establish a high-availability web server system.
2 Load Balancer + 2 Web Server(installed MySQL Server 5.5). 2 MySQL Server used Multi-Master Replication.
Used "Amoeba" as MySQL Proxy which direct the write statement to a specific MySQL Server.

I can login Amoeba and MySQL Server using MySQL client.
I tried query something in XAMMP on Windows XP. It work!

Installed related software:
MySQL-server-5.5.11-1.rhel5
MySQL-shared-compat-5.5.11-1.rhel5
php53-mysql-5.3.3-1.el5_6.1
MySQL-client-5.5.11-1.rhel5
php53-gd-5.3.3-1.el5_6.1
php53-cli-5.3.3-1.el5_6.1
php53-5.3.3-1.el5_6.1
php53-mysql-5.3.3-1.el5_6.1
php53-common-5.3.3-1.el5_6.1
php53-pdo-5.3.3-1.el5_6.1

What I tried:
yum install php php-mysql
yum install php53 php53-mysql
Compiled php 5.3.6 soruce + MySQL 5.5 Server, Client, Shared, Shared-Compact

Above software installed on different host. And the phpinfo showing MySQL

I doubt something wrong in my php.ini. Used default php configuration.

Thank you for your time.

Last edited by avinc; 04-18-2011 at 11:40 AM.
 
Old 04-18-2011, 08:11 AM   #2
koosha
LQ Newbie
 
Registered: Jun 2009
Distribution: Debian GNU/Linux
Posts: 29

Rep: Reputation: 0
Check out the log file of MySQL and your web server located in /var/log. That should give you useful information. Using the following function in PHP is a good idea to find out what the error is about:
Code:
echo mysql_error();
Write it after the mysql_connect function in your code.

Last edited by koosha; 04-18-2011 at 08:13 AM.
 
Old 04-18-2011, 11:03 AM   #3
avinc
LQ Newbie
 
Registered: Apr 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Thank you for your reply. I had tried your suggestion. "Can't connect to MySQL server ...".

My situation: "I could connect to MySQL from the PHP via Apache and MySQL via the MySQL console, and could not connect via the PHP"

But, PHP only can connect to MySQL using mysql_connect("localhost", "root", "password");

Last edited by avinc; 04-18-2011 at 11:08 AM.
 
Old 04-18-2011, 11:40 AM   #4
avinc
LQ Newbie
 
Registered: Apr 2011
Posts: 10

Original Poster
Rep: Reputation: 0
I found the problem

Quote:
Its selinux not allowing apache to make remote connections
Solution:
setsebool -P httpd_can_network_connect=1
 
Old 04-18-2011, 04:42 PM   #5
koosha
LQ Newbie
 
Registered: Jun 2009
Distribution: Debian GNU/Linux
Posts: 29

Rep: Reputation: 0
Yeah. It's SELinux that many times causes problems but is hidden from the user's perspective, especially in Red Hat systems that is enabled by default.
 
Old 04-18-2011, 08:25 PM   #6
avinc
LQ Newbie
 
Registered: Apr 2011
Posts: 10

Original Poster
Rep: Reputation: 0
koosha, Thank you for your help
 
  


Reply


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
PHP not supporting mysql_connect() sunils1973 Linux - Server 5 04-17-2008 12:22 PM
mysql_connect crashes php DavidHB Slackware 4 04-18-2007 09:06 AM
php mysql_connect error compu73rg33k Linux - Software 11 04-02-2005 06:37 AM
mysql_connect problem w/apache+php CodeCrush Linux - Software 0 05-24-2004 09:35 AM
Redhat PHP 4.2 Problem, no mysql_connect() nehalem Linux - Software 1 11-20-2003 01:12 AM

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

All times are GMT -5. The time now is 03:23 PM.

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