Jump to content

Newbie - where to store MYSQL connection name/password


enveetee

Recommended Posts

Hi there

 

I am just finalising my first ever PHP/MYSQL project and I am worried about where to safely keep my connection credentials for the SQL DB.

 

Currently, I am storing them in ../php/config.php and this works fine, but I am worried as to the security of this

 

Can anyone advise please

 

Thanks

Link to comment
Share on other sites

I prefer to store it outside the documentroot of your website.

 

So in case your documentroot is /var/www/html then i should maybe store it in /var/www/config/config.php.

 

Another possibility is to store it in a subdirectory of the documentroot and protect it by an .htaccess file with the content Deny from All 

 

If you are using apache 2.4 then it should be Require all denied

Link to comment
Share on other sites

Assuming that your current location is 'outside' of the web-accessible tree, then that will be safe from attacks using http. Won't help if your site password is compromised and someone uses ftp to browse your site.

 

Course - there are better experts at this facet - let's see what they say.

Link to comment
Share on other sites

Well, I can tell you not to store it at /var/www/html/mySecretPasswords.ini (assuming a Redhat install).  I wouldn't even do so if protected by .htaccess or something similar in httpd.conf as it is just a desultory in waiting.

 

I've toyed with the idea of encrypting the file, but since PHP will need to decrypt it, I guess this doesn't make sense.

Link to comment
Share on other sites

Exactly, it does not make any sense. Do not think too difficult!

 

Even if you store the mysql username and password in a normal accessible .php file then normal http users will not be able to read the code in the .php file. So the options mentioned above is allready a little extra security. And as ginerjm mentioned above it is much more important to use strong password protection for other protocols like SSH and FTP because that are main entrances! 

 

(Think about locking all the windows from the house but forget to close your frontdoor :P)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.