How do I connect from php to mySQL using SSL?

How do I make a connection from a php script to a mysql database using SLL to encrypt the transferred data?
novocentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mgrennanCommented:
This is a simple example.

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

See http://us.php.net/function.mysql-connect
0
Ray PaseurCommented:
Where are the PHP and MySQL hosts (what URLs)?
0
novocentAuthor Commented:
mgrennan, I want to connect via SSL to secure the transfer of data between the php server and the mysql server. The mysql server is on a remote host.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

mgrennanCommented:
So this must be a remote connections.  Setting up SSL with MySQL is a completed process involving creating and installing certificates.

Maybe your best best is to tunnel over ssh.  A command line:

ssh -L 3306:mysqlhsot:3306 -l user -N mysqlhost

Your application would then connect to localhost port 3306 and would be ssl connected to port 3306 on the remote server.
0
mgrennanCommented:
Here is the information on connect PHP with a certificate.

http://th.php.net/manual/en/mysqli.ssl-set.php

Here is the information on setting up MySQL certificates.

http://dev.mysql.com/doc/refman/5.0/en/secure-create-certs.html\
0
novocentAuthor Commented:
mgrennan, I will look into that info. I started to make and installed certificates earlier today, but never completed the process. I came across another idea and it seemed to work. I was hoping to confirm the solution: I used this connection:
$conn = mysql_connect("XXX.XXX.XXX.XXXX", "username", "password",true, MYSQL_CLIENT_SSL);
on the remote mysql database I used:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'remoteIP' IDENTIFIED BY 'password' REQUIRE SSL;
It made a connection which I think is SSL, I know of no way to confirm that. I do know that trying to use only $conn = mysql_connect("XXX.XXX.XXX.XXXX", "username", "password") fails. It seemed so simple that I was doubting the SSL connection. And doubting whether the information transferred from the mysql database to the remote php was actually encrypted.  Any thoughts?



0
mgrennanCommented:
Sounds like you have it work.  MYSQL_CLIENT_SSL is a good function.

Use WireShark to confirm the connection is encrypted.

http://www.wireshark.org/

Wireshark is a great tool and you should learn how to use it.  The trick to using it in this case is to use a filter to see only the connections between your guest and server.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.