tjones
tjones

Reputation: 367

In what directory do i put my mysql config.php files when setting up a website/app?

Hi I'm new to putting up websites. I have a document root: home/user/public_html/www.example.com/public where all of my static file should go to be publiclly viewable. But many of these files include config.php. These config.php files have user names and passwords so it just doesn't seem right to put them in the public folder.

  1. Where should these files go?

  2. If I move the configs to a different directory (I have tried) then the static files can't find the config files anymore. Would I point to the new location?

Upvotes: 1

Views: 3949

Answers (2)

Ajit
Ajit

Reputation: 336

Yup you need change the location of config.php with respect to the static files. If I understood correctly, by default they both are in same directory, so you must have
include 'config.php';
if you want to move them into a new folder, suppose name of the folder is hidden, then you have to change it to :
include 'hidden/config.php';

Finally if you decided to move up one directory, you have to use
include '../config.php';

You can read in detail about relative paths here: Absolute vs relative links

Upvotes: 1

PorridgeBear
PorridgeBear

Reputation: 1183

Well, WordPress, one of the more popular and largest platforms out there just puts a wp-config.php file into the document root, so if it's good enough for them you could say it's good enough for you :)

You can of course store the config.php file 1 level up from your actual document root. PHP can still access it if given the correct path.

E.g. http://codex.wordpress.org/Hardening_WordPress#Securing_wp-config.php

Each file that includes config.php needs to reference it with the correct path. If you just store the config.php in the root you can change all the includes to use

include_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');

This will work no matter the location of the including file.

Upvotes: 1

Related Questions