Skip to content
PHP Logo

What are some common methods for setting up password protection in PhpMyAdmin?

To set up password protection in PhpMyAdmin, you can create a .htpasswd file with encrypted passwords and configure the .htaccess file to require authentication before accessing PhpMyAdmin.

php
<?php
$htpasswd_file = '/path/to/.htpasswd';
$htaccess_file = '/path/to/.htaccess';

$username = 'admin';
$password = 'password';

// Encrypt the password
$encrypted_password = password_hash($password, PASSWORD_DEFAULT);

// Add username and encrypted password to .htpasswd file
file_put_contents($htpasswd_file, "$username:$encrypted_password");

// Configure .htaccess file to require authentication
$htaccess_content = "AuthType Basic\n";
$htaccess_content .= "AuthName 'Restricted Area'\n";
$htaccess_content .= "AuthUserFile $htpasswd_file\n";
$htaccess_content .= "Require valid-user\n";
file_put_contents($htaccess_file, $htaccess_content);
?>