Do I need to open the MySQL port for my LAMP app to work?

I am getting the following error after I first deployed my app: Database connection failed: Connection timed out (2002)

Thank you in advance!


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Yes, it is running on the same box.

defined(‘DB_SERVER’) ? null : define(“DB_SERVER”, “<my_ip_address>”); defined(‘DB_USER’) ? null : define(“DB_USER”, “<db_username>”); defined(‘DB_PASS’) ? null : define(“DB_PASS”, “<db_password>”); defined(‘DB_NAME’) ? null : define(“DB_NAME”, “<db_name”);

private $connection;

function __construct() { $this->open_connection(); }

public function open_connection() { $this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME); if(mysqli_connect_errno()) { die(“Database connection failed: " . mysqli_connect_error() . " (” . mysqli_connect_errno() . “)” ); } }


if your mysqld is running on the same box as the rest of the stack then you should definitely be using a UNIX socket to connect to mysql.

What does your mysql connection stanza look like in the code?