Title: Hiding WordPress database config
Last modified: March 18, 2026

---

# Hiding WordPress database config

 *  [jason_hayes](https://wordpress.org/support/users/jason_hayes/)
 * (@jason_hayes)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/)
 * I need to use the “set environment variable” for sensitive information like the
   database password and salt keys but I’m not sure how– is there any info or a 
   plugin?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18855950)
 * It’s inaccessible and safe.
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18855995)
 * I’m not sure if I understand the question correctly. The database connection 
   details and salts are always stored in the `wp-config.php` file. The contents
   of this file are not publicly accessible and are therefore secure. But what do
   you mean by “is there any info or a plugin?”?
 *  Thread Starter [jason_hayes](https://wordpress.org/support/users/jason_hayes/)
 * (@jason_hayes)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18856023)
 * I guess they want the password for the database stored in a .conf file on the
   server and use this to fetch it
 * // Example: Setting the database name using an environment variable
   define( ‘
   DB_NAME’, getenv(‘DB_NAME’) ?: ‘default_database_name’ );
 * // Example: Setting a custom API key
   define( ‘MY_API_KEY’, getenv(‘MY_API_KEY’));
 *  Thread Starter [jason_hayes](https://wordpress.org/support/users/jason_hayes/)
 * (@jason_hayes)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18856053)
 * **They said to usecthis:**
 * 
   ServerName example.comDocumentRoot /var/www/html
 *     ```wp-block-code
       # Set your variables here
       SetEnv DB_NAME "my_database_name"
       SetEnv DB_USER "my_user"
       SetEnv DB_PASSWORD "my_secure_password"
       SetEnv WP_ENVIRONMENT_TYPE "development"
   
       <Directory /var/www/html>
           AllowOverride All
           Require all granted
       </Directory>
       ```
   
 * and add this to wp-config.php:
 * define( ‘DB_NAME’, getenv(‘DB_NAME’) );
   define( ‘DB_USER’, getenv(‘DB_USER’) );
   define( ‘DB_PASSWORD’, getenv(‘DB_PASSWORD’) );
 * // Optional: Set the environment type (local, development, staging, production)
   
   if ( getenv(‘WP_ENVIRONMENT_TYPE’) ) {define( ‘WP_ENVIRONMENT_TYPE’, getenv(‘
   WP_ENVIRONMENT_TYPE’) );}
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18856060)
 * Who are “they”? What requirements are you going by here?
 *  Thread Starter [jason_hayes](https://wordpress.org/support/users/jason_hayes/)
 * (@jason_hayes)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18856068)
 * I’m building g a wordpress website for someone and they want it secured like 
   that. It seems pretty straight forward. But I thought there mighr be a security
   plugin that does this for me. I don’t think a plugin could get root access though.
   I have root access
    -  This reply was modified 3 months ago by [jason_hayes](https://wordpress.org/support/users/jason_hayes/).
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18856102)
 * Okay, now we have some context for your issue.
 * But no, there’s no plugin for that. As you described above, you have to configure
   it manually. Since what you wrote seems to be a quote, I suspect you’re not entirely
   sure what you need to do?
 * Since I don’t do this often either, I just tested it myself. It’s actually two
   steps:
 * 1) You need to add these entries to your Apache virtual host configuration:
 *     ```wp-block-code
       SetEnv DB_NAME "my_database_name"SetEnv DB_USER "my_user"SetEnv DB_PASSWORD "my_secure_password"SetEnv WP_ENVIRONMENT_TYPE "development"
       ```
   
 * 2) In `wp-config.php`, you need to adjust this (don’t add anything! The constants
   are already there):
 *     ```wp-block-code
       define( 'DB_NAME', getenv('DB_NAME') );define( 'DB_USER', getenv('DB_USER') );define( 'DB_PASSWORD', getenv('DB_PASSWORD') );
       ```
   
 * If, for example, the current entry is:
 *     ```wp-block-code
       define( 'DB_NAME', 'my_database_name' );
       ```
   
 * you need to replace the value with the value of the variable, like this:
 *     ```wp-block-code
       define( 'DB_NAME', getenv('DB_NAME') );
       ```
   
 * This worked perfectly on my test system.
 * If you don’t have virtual host configurations in Apache, you need to enter the
   information in the central configuration file. The name of this file depends 
   on the server structure.
 * If you’re using a tool like cPanel, Plesk, ispconfig, or similar for server administration,
   you may need to enter the information elsewhere in that tool. The support documentation
   or manual for these tools will help you with this.
 * If you’re using an nginx server instead of Apache, a completely different configuration
   would be needed for step 1. The nginx manual should help with this.
 *  Thread Starter [jason_hayes](https://wordpress.org/support/users/jason_hayes/)
 * (@jason_hayes)
 * [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18857346)
 * Awesome. I’ll have to figure out what file to add the information to the “Apache
   virtual host configuration” and I’ll have to look for it. I’m sure there’s documentation
   for WHM/cPanel that will help me find which one to edit. I’m using Cloudlinux9
   with Apache.
 * Thanks!
    -  This reply was modified 3 months ago by [jason_hayes](https://wordpress.org/support/users/jason_hayes/).

Viewing 8 replies - 1 through 8 (of 8 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhiding-wordpress-database-config%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [jason_hayes](https://wordpress.org/support/users/jason_hayes/)
 * Last activity: [3 months ago](https://wordpress.org/support/topic/hiding-wordpress-database-config/#post-18857346)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
