Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2 Ubuntu mysql_connect function causing 500 Internal Server Error

I am trying the following script:

<?php
 mysql_connect("inspectlettest.ce0ohcvwmist.us-east-1.rds.amazonaws.com", "username", "password") or die(mysql_error());
 echo "Connected to MySQL<br />";
?>

The web server is strangely returning a 500 Internal Server Error.

I can connect to the mysql server via terminal from the instance just fine.

Any ideas?

like image 393
tim Avatar asked Jun 02 '11 21:06

tim


1 Answers

When you get an internal server error when executing a php script, your first step should be to get more information about this error. On Ubuntu, you can check following apache log file:

/var/log/apache2/error.log

It is possible that it will say something like that:

[...] PHP Fatal error:  Call to undefined function mysql_connect() in [...]

If you see it, it is possible that some required packages are not installed on your system. If I remember correctly, you need at least mysql-client and php-mysql packages. Restarting the apache server may also be necessary:

$ sudo apt-get install mysql-client
$ sudo apt-get install php-mysql
$ sudo /etc/init.d/apache2 restart

If your error message is different, please add it to the question, it will make helping you easier.

like image 75
Dariusz Walczak Avatar answered Oct 04 '22 23:10

Dariusz Walczak