Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently attempting to create a system for users to login/register an account for an iPhone app that I'm developing. I have it working on a local server, but my attempts to move it to a real server have not been successful.

I'm running an EC2 instance and made sure to keep open ports 22, 80, and 3306 (sources are all I've installed Apache, MySQL, and PHP/phpMyAdmin. I'm using the AFNetworking framework to handle all the connections.

What I'm doing is:

API.m // this is where I make a connection with the EC2 instance and below are the settings for the connection
#define kAPIHost @""
#define kAPIPath @"photoapp/"

I get a successful connection with my instance, which is great. I can post the code if you like, but I won't for now as it seems to me it isn't necessary. The php files which I stuck in photoapp folder I defined above attempt to connect to the mysql db with:

$link = mysqli_connect("","root","password");
mysqli_select_db($link, "photoappdb");

What happens is when I try to register a user, the username and password do not show up in the database when I go over and check in phpMyAdmin. Again, this all works when I run MAMP and change everything to localhost, so to me it seems like it would have something to do with how I'm attempting to connect to the instance or something with the instance itself.


I deleted some parts of the initial question as I'm getting closer to the source of this. I believe I know what's going on, but I don't know how to get around it

If I set the initial API connection with kAPIHhost @"", I get a successful connection, but the php files don't run. If I set the initial API connection without the 3306 port like kAPIHhost @"" the connection fails, but the php files run and I get lots of mysql connection errors.

I attempted to connect directly to the php files via the browser like: and I get a php output in the log file, but if I go to with the MySQL port, my browser attempts to download the php file...

So there seems to be some awkward handling of php files. I believe when I try to connect to the correct ip kAPIHhost @"" I succeed, but then the server will attempt to download the php files to the iphone rather than running them. Can anyone explain this behavior? Thank you!

share|improve this question
Did you make a typo when you wrote that you opened port 3066? Because then it makes sense, since you are connecting to mysql on port 3306 – Frederik Nielsen Aug 11 '13 at 23:51
Some friendly mysql security tips: 1) For your app, create a user in mysql just for that app that only has the access rights needed for that app/database combination instead of using the root user. 2) I highly recommend that you do not open up port 3306 to the world ( Instead, lock it down using EC2 security groups to only the hosts that need mysql access. 3) Many internet rootkits routinely target phpMyAdmin. When you go into production, I would avoid that tool like the plague. – platforms Aug 12 '13 at 0:35
@FrederikNielsen : I'm sorry that was a typo. I've edited the post, but yes, I opened 3306 on the EC2 instance. – BlueGuy Aug 12 '13 at 2:13
@platforms : 1) I'll be sure to do that 2 & 3) I'm still pretty new at the server end of things. I'll jot this down and remind myself to change these issues in the future. At least for now, it's making it easier to develop. I imagine I'll be rebuilding the instance/mysql build a few times as my needs change and become more knowledgable. Thanks for the suggestions. – BlueGuy Aug 12 '13 at 2:16
up vote 0 down vote accepted

You appear to be supplying the port incorrectly (as part of the hostname).

mysqli_connect PHP function

For the PHP function mysqli_connect, the params look like this:


Notice the 5th param is port (which usually defaults to 3306).

Your Code

Here is what it should look like:

$link = mysqli_connect("","root","password");
mysqli_select_db($link, "photoappdb");


$link = mysqli_connect("","root","password", "photoappdb","3306");
share|improve this answer
You're right, the port wasn't sent properly. Thank you so much! I spent so much time on this. – BlueGuy Aug 14 '13 at 8:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.