How to add /home/user/public_html as virtual host in apache - centos

12,076

Depends a bit on the error message in your log files, a missing IndexDocument i.e. no index.html in the documentroot could be one obvious cause for that error.

The other common cause would be because you have SELinux enabled. Check that with getenforce.

And of course file system privileges on the path to the documentroot i.e. on /home/user and /home/user/domains/<etc>

Share:
12,076

Related videos on Youtube

Hamidreza
Author by

Hamidreza

Updated on September 18, 2022

Comments

  • Hamidreza
    Hamidreza over 1 year

    In Directadmin (I used it before) when we create a reseller, a new user with a home directory was created and user could add domains in a home directory like /home/user/domains/example.com/public_html

    How i can add /home/user/public_html as virtual host to apache web server? I want to config apache like direct admin to use home directory.

    Im new on Centos 6.5 and i'm trying to config a web server. My OS is clear (no any configs, just DNS) and SElinux is disabled in /etc/sysconfig/selinux. I have one ip for my VPS.

    Now my config for httpd is below.

    <VirtualHost domain-1.com:80>
        DocumentRoot /home/user/domains/domain-1.com/public_html
        ServerName domain-1.com
    </VirtualHost>
    

    When i add this config, i get forbbiden error in http://domain-1.com and http://server-ip

    UPDATE I added the following code to apache conf.d but the error is alive.

    <IfModule mod_userdir.c>
        UserDir enabled user
        UserDir public_html
    </IfModule>
    <Directory /home/*/public_html>
            Options Indexes Includes FollowSymLinks
            Require all granted
            AllowOverride All
            Allow from all
            Order deny,allow
    </Directory>
    
    • user9517
      user9517 about 10 years
      This will almost certainly be SELinux httpd_enable_homedirs
    • Hamidreza
      Hamidreza about 10 years
      @Iain I see that page, my permission for public_html is (drwxr-xr-x 751), why i cant change it using chmod 755 public_html as root access?
    • user9517
      user9517 about 10 years
      the perms you show above are 755 so you won't see them changing ...
    • user9517
      user9517 about 10 years
      I think you should stop what you're doing and go read some documentation on Unix permissions and how they interact with the filesystem and processes.
  • Hamidreza
    Hamidreza about 10 years
    I change selinux to disable by setenforce 0 and changing /etc/sysconfig/selinux to disable. but error happen again.
  • Hamidreza
    Hamidreza about 10 years
    getenforce = disabled.
  • Hamidreza
    Hamidreza about 10 years
    before adding VirtualHost, http://server-ip worked fine. but after it both of them given forbidden error.
  • HBruijn
    HBruijn about 10 years
    And nothing useful in the apache error log?
  • Hamidreza
    Hamidreza about 10 years
    just this error: (13)Permission denied: access to / denied
  • HBruijn
    HBruijn about 10 years
    That is the error code for a file system permissions problem (One can check with perror 13). Quite useful. Check if the apache user can access the DocumentRoot with ls -ld /home/user /home/user/domains/ /home/user/domains/domain-1.com /home/user/domains/domain-1.com/index*
  • Hamidreza
    Hamidreza about 10 years
    I tyred to login as apache user with su apache but it is not possible, how i can do this?
  • HBruijn
    HBruijn about 10 years
    The apache user typically has no valid shell, which is why you can't use su apache, what you can do is (as root) sudo -u apache ls -ld /home/user /home/user/domains/ etc. But just checking owners groups and permissions of the directories and files doesn't have to be done as apache, root or even user would work just as well.
  • Hamidreza
    Hamidreza about 10 years
    There is a problem with /home/user/domains permission. I change it by chmod 777 /home/user/domains to solved the problem. Thanks ;)