tags:

views:

1291

answers:

5

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: 

You place the libraries in PHP's include_path which is inaccessible to the general user.

orlandu63
So does apache point at /var/www/project/htdocs/ but then say you had index.php, you could say include_path('/var/www/project/mylib/lib.php') ?
Kezzer
+1  A: 

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.

Codingscape
+1  A: 

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.:

/var/www/lolcats.com
/var/www/lolcats.com/htdocs
/var/www/lolcats.com/htdocs/index.php
/var/www/lolcats.com/lib
/var/www/lolcats.com/log
troelskn
+6  A: 

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

/var/www/project-name/
    + 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.

lzhang
That's exactly the answer I was looking for. Thanks very much!
Kezzer
A: 

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:

/var/www/root
 /var/www/root/website1
 /var/www/root/website2
 /var/www/root/website3

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.

Jon Winstanley