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! |
please try and post in the correct forum... this thread will soon be moved to a more suitable location.
|
//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 |
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.
|
Quote:
|
Quote:
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". |
Can't connect to MySQL server on 'servername' (13)
Quote:
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! |
Are you using a "servername" that PHP is able to resolve?
--jeremy |
Quote:
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? |
What connection string are you using to connect?
--jeremy |
Quote:
PHP Code:
|
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. |
thank you very much
it works |
Quote:
|
To establish remote mysql database connection for your PHP website, you must first whitelist the IP of server you will use to connect to the database remotely. You can use following code to configure the remote connection
Code:
<?php Source: remote mysql connection setting |
All times are GMT -5. The time now is 12:30 AM. |