localhost/test

http://localhost/test

The localhost/test path is used for test pages, debug scripts, and development testing. Create a test directory to safely experiment without affecting production code.

→ Open localhost/test

Create Test Directory

# Windows XAMPP cd C:\xampp\htdocs mkdir test # Linux cd /var/www/html sudo mkdir test sudo chown -R www-data:www-data test # Mac MAMP cd /Applications/MAMP/htdocs mkdir test

Common Test Files

PHP Info Test

Create test/phpinfo.php:

<?php // Display PHP configuration phpinfo(); ?>

Access: localhost/test/phpinfo.php

Database Connection Test

Create test/dbtest.php:

<?php // MySQL connection test $host = 'localhost'; $user = 'root'; $pass = ''; $db = 'test'; $conn = mysqli_connect($host, $user, $pass, $db); if ($conn) { echo "Database connected successfully!"; echo "
Server: " . mysqli_get_server_info($conn); mysqli_close($conn); } else { echo "Connection failed: " . mysqli_connect_error(); } ?>

PDO Connection Test

<?php try { $pdo = new PDO( "mysql:host=localhost;dbname=test", "root", "" ); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "PDO connection successful!"; // Test query $stmt = $pdo->query("SELECT VERSION()"); $version = $stmt->fetch(); echo "
MySQL Version: " . $version[0]; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?>

Server Variables Test

Create test/server.php:

<?php echo "

Server Information

"; echo "Server Software: " . $_SERVER['SERVER_SOFTWARE'] . "
"; echo "Server Name: " . $_SERVER['SERVER_NAME'] . "
"; echo "Server Port: " . $_SERVER['SERVER_PORT'] . "
"; echo "Document Root: " . $_SERVER['DOCUMENT_ROOT'] . "
"; echo "PHP Version: " . phpversion() . "
"; echo "OS: " . PHP_OS . "
"; echo "

PHP Modules

"; print_r(get_loaded_extensions()); ?>

HTML Test Page

Create test/index.html:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Test Page</title> <style> body { font-family: Arial, sans-serif; padding: 20px; } .success { color: green; } .error { color: red; } </style> </head> <body> <h1>Test Page Working</h1> <p class="success">If you see this, your server is running correctly.</p> <h2>Quick Tests</h2> <ul> <li><a href="phpinfo.php">PHP Info</a></li> <li><a href="dbtest.php">Database Test</a></li> <li><a href="server.php">Server Info</a></li> </ul> </body> </html>

JavaScript Test

Create test/script.html:

<!DOCTYPE html> <html> <head> <title>JavaScript Test</title> </head> <body> <h1>JavaScript Test</h1> <button onclick="testFunction()">Click to Test</button> <div id="output">

File Upload Test

Create test/upload.php:

File Upload Test

<?php if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['testfile'])) { $file = $_FILES['testfile']; echo "

File Information:

"; echo "Name: " . $file['name'] . "
"; echo "Type: " . $file['type'] . "
"; echo "Size: " . $file['size'] . " bytes
"; echo "Temp: " . $file['tmp_name'] . "
"; echo "Error: " . $file['error'] . "
"; if ($file['error'] === 0) { echo "

Upload successful!

"; } else { echo "

Upload failed!

"; } } ?>

Session Test

Create test/session.php:

<?php session_start(); // Set session variable if (!isset($_SESSION['visits'])) { $_SESSION['visits'] = 0; } $_SESSION['visits']++; echo "

Session Test

"; echo "Session ID: " . session_id() . "
"; echo "Page visits: " . $_SESSION['visits'] . "
"; echo "
Refresh to increment"; // Display all session variables echo "

Session Variables:

"; echo "
";
print_r($_SESSION);
echo "
"; ?>

API Test

Create test/api.php:

<?php header('Content-Type: application/json'); // Simple API endpoint for testing $response = [ 'status' => 'success', 'message' => 'API is working', 'timestamp' => time(), 'server' => $_SERVER['SERVER_NAME'], 'method' => $_SERVER['REQUEST_METHOD'] ]; echo json_encode($response, JSON_PRETTY_PRINT); ?>

Test with: curl http://localhost/test/api.php

Email Test

Create test/email.php:

<?php // Test if mail() function works $to = "test@example.com"; $subject = "Test Email"; $message = "This is a test email from localhost."; $headers = "From: noreply@localhost"; $result = mail($to, $subject, $message, $headers); if ($result) { echo "Email function is available and executed."; echo "
Note: Email may not actually send without SMTP configuration."; } else { echo "Email function failed or is not configured."; } // Check mail configuration echo "

Mail Configuration:

"; echo "SMTP: " . ini_get('SMTP') . "
"; echo "smtp_port: " . ini_get('smtp_port') . "
"; echo "sendmail_path: " . ini_get('sendmail_path') . "
"; ?>

Test Directory Structure

htdocs/test/ ├── index.html # Main test page ├── phpinfo.php # PHP configuration ├── dbtest.php # Database test ├── server.php # Server info ├── script.html # JavaScript test ├── upload.php # File upload test ├── session.php # Session test ├── api.php # API endpoint test ├── email.php # Email test └── README.txt # Test documentation

Security Considerations

  • Delete on Production - Never deploy test files to production servers
  • Restrict Access - Use .htaccess to password protect test directory
  • No Sensitive Data - Don't use real credentials in test files
  • Remove phpinfo() - Exposes server configuration details

Protect Test Directory

Create test/.htaccess:

AuthType Basic AuthName "Test Area" AuthUserFile /path/to/.htpasswd Require valid-user # Or deny all access # Deny from all
Best Practice: Use descriptive file names for tests. Instead of test.php, use db-connection-test.php or api-endpoint-test.php for clarity.

Common Test URLs

  • localhost/test/ - Main test directory
  • localhost/test/phpinfo.php - PHP configuration
  • localhost/test/dbtest.php - Database connection
  • localhost/test/api.php - API endpoint

Frequently Asked Questions

Why use localhost/test?

It provides an isolated location for debugging and testing without affecting your main application or production files.

Is localhost/test secure?

By default, it's accessible to anyone on localhost. For network access, use password protection or IP restrictions via .htaccess.

Should I commit test files to version control?

Generally no. Add /test/ to .gitignore to avoid committing test files, especially those with phpinfo() or database credentials.

Related Resources