LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   localhost on apache2 (https://www.linuxquestions.org/questions/debian-26/localhost-on-apache2-507196/)

radiodee1 12-03-2006 04:47 PM

localhost on apache2
 
I'm a noob and I'm using a new install of Debian 3.1 kernel 2.6.8. I installed apache2 and set up a localhost site. I edited '/etc/hosts' to include a fake domain name, and edited '/etc/apache2/sites-available/default' to look like this (in part)

Code:

NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
#      ServerName www.davenet.com
        ServerAdmin webmaster@localhost

        #DocumentRoot /var/www/
        DocumentRoot /var/www

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

        <Directory /var/www>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                # RedirectMatch ^/$ /apache2-default/
        </Directory>

        #... more stuff here
</VirtualHost>

Well, I can see my '/var/www/index.html' page (at document root) but that page cannot access any resources that are in a directory... a directory in document root too, like a pics directory at '/var/www/pics/'. I did this before on a w32 version of apache 2, but it worked a little differently. Can anybody tell me how to get this to work?

(I read about how apache had a bug where you had to take the trailing slash off of the 'DocumentRoot' line, or certian things wouldn't work. I thought initially that was my problem, but alas, following that line of thinking produced no solution for me.):confused:

Dutch Master 12-03-2006 06:14 PM

When you visit a webpage on space allocated for user X on an Apache server you basically have the permissions that user has on that server. Okay, it's a shortcut, but it helps to understand the permissions issue. When that user doesn't have permission to access a particular directory on the server, neither do you! The solution is quite simple: make sure both directories are owned by the same user ;) Or, in case that troubles you: make a group with both users and change ownership of the directory to that group.

radiodee1 12-04-2006 06:54 AM

Dutch Master, thanks for the reply! I'm not sure I totally understand what you're saying. You mean I should make sure that either I start a group for my directories that are under document root, or I change their ownership, to make sure that the user who requests the web page has permission on those directories...

OK. I should have written before, I have permission on all those directories... '/var/www/' and the test directory '/var/www/pics/'. I tried to change the permission on '/var/www/' itself to my user (from root).

I still can't see files that reside in '/var/www/pics' when I look at '/var/www/index.html'. Bummer. ('/var/www/index.html' has some pictures on it that reside in '/var/www/pics'). Anybody have any more ideas???

EDIT: it seems in a way you were right. I got it to work by changing the permissions. Files in the '/var/www/pics' directory had to be changed from r permission to rw permission. 'chmod 666 *' in the pics directory seemed to do the trick. Thanks.

snowtigger 12-04-2006 07:12 AM

In the apache config there is a bit that sets what user and/or group apache runs. say for example it runs as user=apache and group=apache.

Make ensure apache can read the directories that you want to view from a web browser.

an example of ownership and permissions

### apache user can read/write/execute, apache can group read/execute, all others can not. However people viewing it from a web browser can see it cause apache is the user that accesses it.
/var/www drwxr-x--- apache apache

### apache user/group and any other can not read/write/execute this directory. only root can do stuff, so no one with a web browser can see it cause apache can not read the contents of the directory
/var/www/pics drwxr-x--- root root

Be careful when setting write permissions to directory that are viewable from the web, it can be possible that someone will put nasty stuff there.

:)

vharishankar 12-04-2006 08:31 AM

The best thing I've found is to put the public_html folder inside the user's home directory and configure apache to look for its www root under ~/public_html.

radiodee1 12-04-2006 05:26 PM

Thanks for the replies!! I tried out some different things. setting the 'other' permission to 'read' is what made my pics in my '/var/www/pics' folder work. 'chmod 604 sample.bmp' works and 'chmod 773 sample.bmp' doesn't. That sort of supports the special 'apache' group idea. I'm transferring these over from a mounted windows partition, so the files all end up with root as the owner and 400 the permissions.

Where do you find the info on what group and user apache works as?

snowtigger 12-05-2006 06:19 PM

From the apache docs which can be found at http://httpd.apache.org/docs/2.0/

user to run as

group to run as

:)

radiodee1 12-06-2006 05:49 PM

Thanks. I went to the links above. I also found the lines for 'User' and 'Group' in the apache2.conf file. Thanks again.


All times are GMT -5. The time now is 02:51 PM.