LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-18-2006, 12:17 PM   #1
habibno05
LQ Newbie
 
Registered: Apr 2005
Location: delawhere?
Distribution: fedora core 3
Posts: 3

Rep: Reputation: 0
connecting php to remote mysql server


I saw there were similar posts but didn't answer my question.
I am running php and mysql on the same server and I have access to the local database just fine. As for connecting to the remote server, I can telnet port 3306 and can also connect to mysql on the remote machine through command line no problems. I restored a copy of my databases from my local mysql to my remote mysql server using command "mysql -u -h -p". So it does not appear to be a permissions issue.

I thought maybe this was a module that was not installed. So I installed php-mysql and mod_auth_mysql with yum on the remote server then restarted mysql service. Still to no avail.

The error I am receiving from mysql_error() is:

Can't connect to MySQL server on 'servername' (13)

Any assistance would be greatly appreciated!
 
Old 10-18-2006, 12:31 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
please try and post in the correct forum... this thread will soon be moved to a more suitable location.
 
Old 10-18-2006, 12:40 PM   #3
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 10,352

Rep: Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616
//moved. Out of curiosity - is there something we could have done better to make clear that this forum was only for Website Suggestions & Feedback?

--jeremy
 
Old 10-18-2006, 12:41 PM   #4
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
You need to allow access by adding the host in the mysql database, by default it's only locally for user accounts unless otherwise specified when you create user accounts.
 
Old 10-19-2006, 12:11 AM   #5
habibno05
LQ Newbie
 
Registered: Apr 2005
Location: delawhere?
Distribution: fedora core 3
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jeremy
//moved. Out of curiosity - is there something we could have done better to make clear that this forum was only for Website Suggestions & Feedback?

--jeremy
My mistake I thought this for user websites not the linuxquestions.org.

Last edited by habibno05; 10-19-2006 at 12:25 AM.
 
Old 10-19-2006, 12:23 AM   #6
habibno05
LQ Newbie
 
Registered: Apr 2005
Location: delawhere?
Distribution: fedora core 3
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by trickykid
You need to allow access by adding the host in the mysql database, by default it's only locally for user accounts unless otherwise specified when you create user accounts.
Hello trickykid,
I had those permissions. That is how I connect to the remote mysql server and performed a restore using "mysql -u username -p -h hostname".
 
Old 09-17-2007, 06:11 PM   #7
smozgur
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 2
Question Can't connect to MySQL server on 'servername' (13)

Quote:
Originally Posted by habibno05 View Post
Hello trickykid,
I had those permissions. That is how I connect to the remote mysql server and performed a restore using "mysql -u username -p -h hostname".
Hi habibno05,

I am having exactly the same problem including same error message from php script while I am perfectly able to connect by using mysql command prompt: Can't connect to MySQL server on 'serverip' (13).

I have other linux and windows (apache) webservers that can connect to the same mysql server with php but only this server.

The only significant difference is PHP is compiled as CGI in the new server where the other ones that can connect are installed as Apache Module.

Have you ever found a solution for this problem?

Thank you!
 
Old 09-17-2007, 08:27 PM   #8
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 10,352

Rep: Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616
Are you using a "servername" that PHP is able to resolve?

--jeremy
 
Old 09-18-2007, 03:15 AM   #9
smozgur
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 2
Quote:
Originally Posted by jeremy View Post
Are you using a "servername" that PHP is able to resolve?

--jeremy
Hi jeremy,

Thanks for your reply!

I am using "server_ip" and this is the same method that I can use in the other servers successfully.

Shouldn't PHP resolve an IP?
 
Old 09-18-2007, 08:05 AM   #10
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 10,352

Rep: Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616Reputation: 2616
What connection string are you using to connect?

--jeremy
 
Old 09-22-2007, 10:56 AM   #11
smozgur
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 2
Quote:
Originally Posted by jeremy View Post
What connection string are you using to connect?

--jeremy
Same method that I am able to connect from other servers via php code:


PHP Code:
$server "serverip";
$dbname "database";
$user "username"//Allowed for the ip
$password "password";
$link mysql_connect($server,$user,$password) or die(mysql_error());
mysql_select_db($dbname); 
Suat
 
Old 09-24-2007, 10:25 PM   #12
smozgur
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 2
Solution

It is explained in the following link:
http://www.ehow.com/how_2090983_conn...r-selinux.html

Shortly;

Reason: SELinux

It restricts Apache remote database connection as default. So our scripts work in command line (# php sqltest.php), and mysql can connect to server but when Apache is involved (calling a php script as web page) then it doesn't work.

Setting:
setsebool -P httpd_can_network_connect=1

I hope it helps someone.

Thanks.
 
1 members found this post helpful.
Old 10-07-2008, 10:25 PM   #13
feri_yanto
LQ Newbie
 
Registered: Aug 2008
Location: Indonesia, Bandung
Distribution: fedora core 5
Posts: 1

Rep: Reputation: 0
thank you very much
it works
 
Old 10-08-2008, 07:49 AM   #14
smozgur
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 2
Quote:
Originally Posted by feri_yanto View Post
thank you very much
it works
Glad to hear it helps!
 
  


Reply

Tags
mysql, php, remote


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
Connecting to a Remote MySQL Server msound Linux - Networking 2 10-18-2006 12:07 PM
connecting PHP to MySQL in a LAMP server rickyglucas_143 Linux - Newbie 2 02-06-2006 04:02 AM
connecting to remote MySQL server acos7 Linux - Software 2 01-30-2004 11:37 PM
newbie Extreme - setting up mysql and php on remote server little girl Linux - Software 3 01-19-2004 12:23 PM
Connecting Mysql Database on remote server akamol Programming 4 10-16-2003 11:46 AM


All times are GMT -5. The time now is 06:26 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration