Apache VirtualHost Error: DocumentRoot Path Exists But Throws “Does Not Exist” Warning


2 views

Recently while configuring a VirtualHost on CentOS 6.0, I encountered a puzzling Apache warning: "DocumentRoot [/var/www/whatever] does not exist" - despite the directory clearly being present. Here's how I troubleshooted and resolved this issue.

My VirtualHost configuration in /etc/httpd/conf.d/whatever.conf looked correct:


    DocumentRoot "/var/www/whatever"
    ServerName whatever.ourdomain
    
        allow from all
        Options +Indexes
    

Basic checks confirmed the directory existed:

$ ls -ld /var/www/whatever
drwxr-xr-x 2 apache apache 4096 Feb 15 10:30 /var/www/whatever

$ pwd
/var/www/whatever

On CentOS/RHEL systems, SELinux often causes such "phantom" permission issues. Checking the context:

$ ls -Z /var/www/
drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 whatever

The correct context for Apache content should be httpd_sys_content_t. If missing, restore it with:

$ sudo chcon -R -t httpd_sys_content_t /var/www/whatever

Another possibility is the filesystem mount options. Check with:

$ mount | grep /var
/dev/mapper/VolGroup-lv_var on /var type ext4 (rw,noexec,nosuid)

The noexec flag might cause issues. Temporarily remount or update /etc/fstab.

Sometimes the issue lies in how Apache processes paths:

$ httpd -S
VirtualHost configuration:
*:80                   whatever.ourdomain (/etc/httpd/conf.d/whatever.conf:1)

Verify if Apache sees the configuration correctly. Also check for duplicate DocumentRoot directives.

Create a test script to verify how Apache sees the path:

In my case, the solution was threefold:

  1. Correct SELinux context: chcon -R -t httpd_sys_content_t /var/www/whatever
  2. Verify parent directory permissions: chmod 755 /var /var/www
  3. Restart Apache with full path: sudo /sbin/service httpd restart

Remember that Apache error messages sometimes oversimplify the actual problem. When dealing with "non-existent" directories that clearly exist, always check:

  • SELinux contexts
  • Filesystem mount options
  • Parent directory permissions
  • Symbolic link resolutions
  • Apache's path interpretation

This is one of those frustrating Apache scenarios where everything appears correct on the surface, but the web server stubbornly insists the DocumentRoot directory doesn't exist. Let me walk through the complete diagnostic process I used to solve this exact issue.

Here's the VirtualHost configuration in question:



    DocumentRoot "/var/www/whatever"
    ServerName whatever.ourdomain
    
        allow from all
        Options +Indexes
    

First, let's verify all the obvious things:


# Check directory existence
ls -ld /var/www/whatever

# Verify permissions
namei -l /var/www/whatever

# Confirm SELinux context
ls -Z /var/www/

On CentOS/RHEL systems, SELinux is often the silent culprit. Even with correct permissions, the security context might be wrong:


# Check current context
ls -dZ /var/www/whatever

# Correct context for web content
chcon -R -t httpd_sys_content_t /var/www/whatever

# Alternative: restore default context
restorecon -Rv /var/www/

Another subtle issue could be filesystem mounting. If /var/www is on a separate partition:


# Check mount options
mount | grep /var/www

# Verify noexec or nodev flags aren't set

The key insight here is that Apache might see a different filesystem than your shell session. We can verify this:


# Run as Apache user
sudo -u apache ls -ld /var/www/whatever

# Or using strace
strace -f -e trace=file /usr/sbin/httpd -t 2>&1 | grep whatever

If all else fails, try restructuring your VirtualHost:



    ServerName whatever.ourdomain
    ServerAlias www.whatever.ourdomain
    
    DocumentRoot /var/www/whatever
    
        Require all granted
        Options Indexes FollowSymLinks
        AllowOverride All
        
        # Additional security headers
        Header always set X-Content-Type-Options "nosniff"
        Header always set X-Frame-Options "SAMEORIGIN"
    
    
    ErrorLog /var/log/httpd/whatever_error.log
    CustomLog /var/log/httpd/whatever_access.log combined

When standard logs don't show enough detail, enable trace logging:


LogLevel trace8

Then check error logs after restarting Apache. Look for filesystem-related error messages that might reveal the underlying issue.