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.


I use a structure like:


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.


On rented servers the path is generally like /home/username/public_html which is the root of the virtual web host configuration pointed within in Apache.

If the hosting company put a PHP directory there, odds are it's used for user specific configuration parameters such as a php.ini but it's worth checking with them if it's a concern of yours.

Secondly, it depends if the follow PHP code is web accessible or not. If it is, I would probably leave it in /home/username/public_html if not I would create a new directory under /home/username (/home/username/newdirectory). Ideally for security, you could modify the owner of the folder and the permissions but on shared web servers generally you are not given that flexibility.

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.