I'm using MAMP just for my development environment and haven't really understood the folder structure of /var/www/project-name/ on a web server. I'm wondering whether you're meant to point the web server to the htdocs folder or it's supposed to point to the root of the project folder?

The reason I ask is because libraries are meant to exist outside of the htdocs folder for security purposes, but how are they pointed to from the web application itself? Surely the web application can't access folders outside of the htdocs folder if the web server is pointing to the htdocs folder for the web application?


A simple solution is to have a folder structure like so:

    + webroot/
    + libraries/

Point your apache2 DocumentRoot to the webroot directory. Keep all the libraries that you don't want accessible from the web in the libraries directory. In your php code, use the include directive to access the libraries code.

The trick is to understand that php can include any file on your system it has read access to. A person browsing your website can only access files inside your webroot directory.

  • 10
Reply Report

If you have multiple vhosts on the same server, it's pretty common to have each site in a directory under /var/www, and each of these have a htdocs folder, which is mounted as the web root. You can then have logs and application-specific libraries in a folder above the web root. Eg.:

  • 4
Reply Report

PHP can access any file in the filesystem for which the apache server user has the correct permissions. On a linux box running apache without virtual hosts, /var/www is a common place to use for your htdocs directory.

  • 1
Reply Report

It is a googd idea to map your local websites in directories in the same way as your domains work.

Often you have multiple websites on a single web hosting account, so setup virtual hosts to mirror the setup.

If your shared hosting is:


Create 3 vitual hosts on your local PC but keep an identical file structure.

Also, use conditions in your config files to setup the site deifferently depending on the server file structure, to ensure the same config file works on both setups. This means you keep your one-step build process.

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions