Database unavailable. Please check the database configuration. After clicking Login, it also shows: Login is temporarily unavailable. Please contact the site administrator.
Other Information
Hello, my site is hosted on InfinityFree and the production database/schema have already been created. The app expects private_config.php in the account directory beside htdocs, but the web File Manager only lets me upload files into htdocs. Creating or editing a file in the account root failed with “Could not read file.”
Could you please tell me the supported secure way to create/edit/upload private_config.php outside htdocs? I do not want to put database or email passwords in the public web directory. The config file needs the MySQL password and other private settings, so I will enter those myself once I have a safe method. No credentials are included in this request.
Welcome to the InfinityFree community forum! Good to have you here.
Most people answering here are volunteers. They’re often the fastest source of help. Admin (the only staff member) checks in about once a day for issues on our end.
Volunteers can’t see your account or website. Share what you actually see, like error messages and what happens when you try something. That’s more useful than your theory of what’s wrong.
AI tools often get InfinityFree wrong. If a volunteer’s advice differs from what an AI told you, please try the volunteer’s suggestion first.
Solving an issue is a joint effort. Try the suggestions you get and report back what happened.
Beep boop, I’m a bot! I dug through the forum to get you started. I sometimes get things wrong though, so do with this what you will until a human has a look.
You can’t put private_config.php outside htdocs on InfinityFree. The web root is always the htdocs folder, and files created or uploaded anywhere else on your account are deleted automatically. That’s probably why File Manager gave you “Could not read file.” This is the article that says so:
The usual approach is to keep private files inside htdocs and block web access to them. The Laravel guide does this with its .env file. It uploads everything into htdocs, then uses a rewrite rule in htdocs/.htaccess so requests for private files return a 404 instead of the file. The guide is written for Laravel, but the idea is the same for your config file:
Your app may also need changing. If it only looks for private_config.php beside htdocs, you’ll have to point it at the copy inside htdocs. Which app or framework is this? That would show whether it has a setting for the config path.
For the “Database unavailable” error, remember that your MySQL host isn’t localhost. Use the hostname shown next to your database in the members area, and fill in the database name and username exactly as listed there.
Using a PHP file with confidential settings in it is completely safe. A PHP file that only defines some variables or constants will just return a blank page when accessed directly. WordPress, Joomla, MyBB and many other systems have done this forever and that hasn’t led to mass data breaches of the world’s most popular CMS.
If you want to be really, really sure, here are some additional security measures you can take:
Add .htaccess rules to your website that blocks access to the configuration files.
Define a constant at the start of your application’s index.php, and check whether that constant is set at the top of your configuration file. If it’s not set, exit early. I would have given you an example of this, but every CMS I checked doesn’t bother. So I suggest you don’t either.
But only do it if you need it for your peace of mind. Your website is no less safe without it.
Actually WordPress (kind of) does. The core files don’t do it, but bundled themes and plugins does check for the presence of ABSPATH. Actually this is a requirement to get your code listed in the directory.