Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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