What are some best practices for developing and testing PHP scripts locally before uploading them to a server?

When developing and testing PHP scripts locally before uploading them to a server, it is important to set up a local development environment using tools like XAMPP or MAMP. This allows you to test your scripts in a controlled environment before deploying them to a live server. Additionally, using version control systems like Git can help track changes and collaborate with team members. Lastly, make sure to thoroughly test your scripts for errors and security vulnerabilities before pushing them to a production server.

<?php
// Sample PHP script for testing locally before uploading to a server

// Connect to a local database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_database";

$conn = new mysqli($servername, $username, $password, $dbname);

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

echo "Connected successfully";

// Close the connection
$conn->close();
?>