The best place to put php files above server root directory

directory-structurePHPwebserver

I am running a web application and I want to move a directory containing my php files above the server root directory. Where would be the best place to put them?

On my web server I rent from Namecheap, there is a directory called php in the same directory where public_html is. Is this a good place to put my php files? The php directory has some directories such as data, docs, and ext. Or is this directory merely for configuration files?

FYI, this server is using Apache.

Best Answer

I use a structure like:

/var/www/sites/
/var/www/sites/project.com/
/var/www/sites/project.com/includes/
/var/www/sites/project.com/library/
/var/www/sites/project.com/www/
/var/www/sites/project.com/www/index.php

Where /var/www/sites/project.com/www/ is set as the virtual host's document root, and I use index.php to include files from library/ & includes/

This way I have organized my project to have the bulk of the PHP outside of apache's document root -- as you're looking to do. So that the server doesn't 'blat' the contents of PHP scripts, etc.

However -- if it's managed hosting, you're going to have to play within the box drawn by the host.

I'd say at the same level as public_html/ is a good place to put your directories with PHP files. The public_html/ is about equivalent to /var/www/sites/project.com/www/ in my example directory structure.

As to the nature of the php/ directory, maybe only your host knows. If it's empty, I'd say that they're encouraging you to use it.

Related Question