r/PHPhelp • u/Code1Light • Oct 22 '22
Solved PHP server security?
Hello everyone, I pray that you are all doing well.
You might have noticed that the title is a question, that's because I'm not really sure what exactly I'm looking for.
But you might, so here is what I'm specifically asking about.
When we create a database in phpmyadmin, we later go to our coding program and start writing this :
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "whatever the database name is"; $conn = mysqli_connect($servername, $username, $password, $dbname); Now clearly this is not secure. And someone told me once that the username and password should not be like this. But all the tutorials do this, so what's the correct thing to write? Thank you all in advance, have a good day/night 😁 The Lord be with you all and save you all your families and friends 🤍
1
u/dabenu Oct 22 '22 edited Oct 22 '22
There are ways to eliminate plain text secrets, but they involve running a secrets server. That introduces latency you don't want to deal with on every request. So in practice, you basically always end up with a database password in plaintext somewhere. Just make sure you go about it as safely as possible:
store secrets (or rather, all your code save a bootstrap index.php) outside the public directory of your webserver;
limit read access to said files;
turn off display_errors, use a custom exception handler;
Only allow access to your database from the webserer IPs (at least for this user).
I probably forget something.