2

I have Apache2 and PHP5 installed. My DocumentRoot is /var/www/. All .php and .html files are served form / and its child directories well. However when I request, say, .png images I get Forbidden notice.

I'd like to dispatch a specific /static/ directory for static content.

How should I edit Apache's configuration files to be able to view static content from /static/ ?

Alex
  • 2,357
  • 5
  • 32
  • 41

3 Answers3

3

i'm not sure if i understand the problem but you can:

if you want to serve static files not from /var/www/static use:

Alias /static/ /somewhere/somewhere/dir/

if your static directory is already in /var/www/static and you get forbidden error - make sure that those files are readable for user under which apache runs:

chown www-data:www-data -R /var/www/static

should fix readability issue. depending on distribution username might differs. check it by running ps faux|grep apache

pQd
  • 29,981
  • 6
  • 66
  • 109
  • Yes pQd, thanks, that was it, I put the jpegs in the directory, but forgot to chmod them. – Alex Jul 26 '09 at 12:08
0

Apache allows to specify php.ini settings on per-directory basis, so you should be able to disable php for user dirs with something like this in your httpd.conf file:

<Directory /home/*/public_html>
php_admin_flag engine off
</Directory>

Also you can set these in ".htaccess"

kolypto
  • 11,058
  • 12
  • 54
  • 66
0

In order for content of a directory on the filesystem to be 'webservable', you gotta have a Directory directive that encapsulates it, and the files have to be accessible by the user that your webserver executes as. Most default installs have one Directory set up and all of the content falls under it (ie. /var/www/).

This is not mandatory, you can have content served from underneath other directories, as long as you have another Directory section defined for it. You can take multiple directories like that and make it seem like one happy tree with an Alias directive.

You can also prohibit serving certain parts of an otherwise 'webservable' tree, for exmample to prevent include files containing DB connect strings, passwords, usernames, etc.

Same rules apply to scripts, just with ScriptAlias directive.

Marcin
  • 2,391
  • 1
  • 17
  • 14