What are the best practices for managing firewall settings to allow MySQL connections in PHP development environments?

To allow MySQL connections in PHP development environments, it is essential to manage firewall settings to permit traffic on the MySQL port (usually 3306). This involves configuring the firewall to allow incoming connections on the MySQL port from the IP addresses of the PHP servers. Additionally, it is crucial to ensure that the MySQL server is configured to accept remote connections from the PHP servers.

// Example code to establish a MySQL connection in PHP

$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";