LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache cant see document root (https://www.linuxquestions.org/questions/linux-newbie-8/apache-cant-see-document-root-861581/)

crowx 02-09-2011 05:32 AM

Apache cant see document root
 
I have set up apache on Centos 5.5 and am struggling with vhosts set up.

With the config I have set apache will correctly serve sites with a document root of

/var/www/html

/home/myuser/public_html

but not

/home/myuser/projects

> ls -al
shows public_html and projects as having identical permissions (755)

Code:

drwxr-xr-x 6 myuser myuser 4096 Feb  8 10:05 .
drwxr-xr-x 3 root    root    4096 Feb  7 15:37 ..
drwxr-xr-x 4 myuser myuser 4096 Feb  7 17:21 projects
drwxr-xr-x 4 myuser myuser 4096 Feb  9 10:21 public_html

and for the purposes of testing both directories contain an index.html file with the same 755 permission.

When I restart the httpd service I get:
Code:

[root@localhost conf]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: Warning: DocumentRoot [/home/myuser/projects] does not exist
                                                          [  OK  ]

My vhosts file contains:

Code:

<VirtualHost *:80>
  ServerName test.localdev
  DocumentRoot /home/myuser/projects

  <Directory "/home/myuser/projects">
    options Indexes Includes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

I only have one vhosts file at the moment so for my test I change the DocumentRoot and Directory between projects and public_html, restarting httpd between each change.

Apache error log shows:
Code:

[Wed Feb 09 11:22:24 2011] [error] [client 172.16.55.1] (13)Permission denied: access to / denied
[Wed Feb 09 11:22:24 2011] [error] [client 172.16.55.1] (13)Permission denied: access to /favicon.ico denied

and I get a 403 in the web browser.

I am confused as to what is going on... Everything works if I set doc root and dir as /home/myuser/public_html, but not /home/myuser/projects

appilu 02-09-2011 05:42 AM

hi,
As a trial jst give project folder full permission and try.then configure required permission.

crowx 02-09-2011 05:48 AM

I have just set projects and the projects/index.html file to 777, but Apache is still reporting the same problem and I'm still getting a 403 in the browser. (I did restart the httpd service.)

linuxlover.chaitanya 02-09-2011 05:55 AM

Your Virtualhost tag does not seem to end anywhere. Just a typo or something?

crowx 02-09-2011 05:58 AM

Quote:

Originally Posted by linuxlover.chaitanya (Post 4252906)
Your Virtualhost tag does not seem to end anywhere. Just a typo or something?

Yeah, sorry. It was on the next page when I copied the text so I missed it.
It is there, and I have added it to the op.

appilu 02-09-2011 06:03 AM

hi,
403 seems something related to permission for webuser
can u do one thing.jst backup the projects directory then take a copy of public_html ,rename it to projects and give a try.
if its ok copy contents from backuped project folder.
jst a suggestion.

linuxlover.chaitanya 02-09-2011 06:06 AM

You can for time being turn off the SELinux and see if it works. Just check.

crowx 02-09-2011 06:17 AM

Quote:

Originally Posted by linuxlover.chaitanya (Post 4252916)
You can for time being turn off the SELinux and see if it works. Just check.

Great, that worked! Thanks.

I did

Code:

[root@localhost myuser]# echo 0 >/selinux/enforce
[root@localhost myuser]# cat /selinux/enforce
0

And now it works. So, whats going on there? I dont know what SELinux is - just quickly googled to find out how to turn it off. Is it safe to leave it off?

crowx 02-09-2011 06:43 AM

Quote:

Originally Posted by appilu (Post 4252912)
hi,
403 seems something related to permission for webuser
can u do one thing.jst backup the projects directory then take a copy of public_html ,rename it to projects and give a try.
if its ok copy contents from backuped project folder.
jst a suggestion.

Ok, odd.

So I re-enabled SELinux
Backed up projects to projects.bac
Moved public_html to projects
- and now that one works. Apache restarts fine and serves the page.
So I copied projects back to public_html
- and now public_html doesnt work. It gives the same errors that projects used to.

?!!

linuxlover.chaitanya 02-09-2011 07:19 AM

You will need to configure SELinux to allow apache to read from your home directory. If your system is not a production apache server, you can safely turn SELinux off. You can go to SELinux configuration tool from GUI and configure it to allow apache to read the directories if you want it running. Your take. I keep it off on non production machines.

crowx 02-09-2011 08:25 AM

Quote:

Originally Posted by linuxlover.chaitanya (Post 4252984)
You will need to configure SELinux to allow apache to read from your home directory. If your system is not a production apache server, you can safely turn SELinux off. You can go to SELinux configuration tool from GUI and configure it to allow apache to read the directories if you want it running. Your take. I keep it off on non production machines.

Brilliant. Thanks for your help. httpd_enable_homedirs was set to 1 which was fine, but of course my project directory did not have the right context for Apache to serve files from it.

The solution was to do
Code:

chmod 711 /home/myuser
chmod 755 /home/myuser/public_html
chmod 755 /home/myuser/projects
setsebool -P httpd_enable_homedirs 1
chcon -R -t httpd_sys_content_t /home/myuser/public_html
chcon -R -t httpd_sys_content_t /home/myuser/projects
service httpd restart

I found this here, after I searched for help on configuring SELinux as a result of the above posts.

Thanks again guys.

linuxlover.chaitanya 02-09-2011 11:21 PM

Great you got it working.


All times are GMT -5. The time now is 10:37 PM.