Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is saving MySQL username/password in the php.ini file secure? [duplicate]

I would like to know if it is secure to save the username, password, server etc. in the php.ini file so when I connect to the MySQL server I don't have to always put the parameters?

Also, can this information (saved in the php.ini) be viewed or retrieve by any kind of methods (like phpinfo() or something like that)?

like image 261
Tech4Wilco Avatar asked Oct 24 '11 13:10

Tech4Wilco


People also ask

Is it safe to store password in php file?

My recommendation: Don't store passwords in source code. Instead, store them in a configuration file (outside of the web root), and make sure the configuration file is not publicly accessible.

Where does MySQL store passwords for user accounts?

MySQL stores credentials in the user table in the mysql system database. Operations that assign or modify passwords are permitted only to users with the CREATE USER privilege, or, alternatively, privileges for the mysql database ( INSERT privilege to create new accounts, UPDATE privilege to modify existing accounts).

How do I password protect MySQL?

There's no way to require an additional password for a user once he logged in. Control access via the normal MySQL login. The user name used for that can be configured to have only access to the objects you want. The used user name decides what is allowed and what is not.


3 Answers

As long as you make sure the ini file is outside the DOCUMENT_ROOT and not world-readable, it's no less secure than any other method.

like image 91
Alex Howansky Avatar answered Sep 22 '22 21:09

Alex Howansky


It isn't secure, because you can read ini files with php method: parse_ini_file

like image 43
Guilherme David da Costa Avatar answered Sep 20 '22 21:09

Guilherme David da Costa


You don't have to put that info in the parameters every time. You can define the connection in a separate file (dbconnection.php) and include that in the files that need a database connection.

like image 32
Luchian Grigore Avatar answered Sep 21 '22 21:09

Luchian Grigore