I want to create a secure connection between PHP and MYSQL database.

In order to do this, I need to store the DB infos in a separated file, with -r-------- permission (readonly for owner). But doing like this, PHP seems impossible to open the file, making impossible the connection.

What do i have to do? Do i have to run PHPMYADMIN as root?


This is the result of the "ls -l" command. Thank you for help.

enter image description here

  • Can you provide more information about this file? Output from ls -l would be useful. – mrc02_kr Jul 20 '20 at 13:23
  • Just did it. Thank you @mrc02_kr – mattia monari Jul 20 '20 at 13:28
  • Can you also add info which HTTP you are using (apache, nginx) and which user is used to start http server. – mrc02_kr Jul 20 '20 at 13:32
  • Im using Apache. Logged in with my personal user wich i created during Ubuntu Server 18.04 LTS installation. – mattia monari Jul 20 '20 at 13:39
  • Please, don't post screenshots of console output; instead, copy-and-paste it into the question using proper formatting. – AdminBee Jul 20 '20 at 16:03

You web server must be able to read file which contains DB credentials. Since it's not a good practice to start services as root user, you should change ownership of db.ini file:

chown <user>:root db.ini
chmod 0400 db.ini

Instead of use username of user which is used to start Apache. Different Linux distributions use different users to start Apache (apache, http, www-data).

You can find this out by displaying status of Apache service:

systemctl status apache2

or for RHEL/CentOS/Fedora:

systemctl status httpd

Main PID filed shows PID and username you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.