Where to put PHP files, root directory or public_html directory?

4k views Asked by At

I saw alot of frameworks like Laravel, Zend, Symfony .... and I noticed that they put php files in the root directory, but when I saw WordPress and vBulletin and alot of famous scripts, and I noticed that they put the php files in the public directory.

I wanna know what is the best place to put my PHP files. Root directory or public_html directory? Which is better? and Why! And what is the difference between them?

1

There are 1 answers

0
Brad On BEST ANSWER

Assuming by "root directory" you mean somewhere outside of the web server's document root, and that "public_html" is the web server's document root...

It's best practice to only have scripts that must be directly accessible within your web server's doc root. If something happens where PHP gets disabled, you don't want the whole world downloading copies of your source code. Scripts can include files from wherever they can access on disk, so it's possible to only put a loader in the web server's doc root and keep the whole application out of there. This is common and best practice.

Wordpress likely doesn't do this by default because most folks installing Wordpress don't really know what they're doing. It's easier for them to just extract a tarball to one place and not have to worry about it. The ones that do know what they are doing can customize installation paths if desired.