Fixing “Client denied by server configuration” Error in Apache Virtual Host Setup on Ubuntu


2 views

Many developers encounter this frustrating scenario: You've set up a virtual host in Apache on Ubuntu, configured what appears to be correct directory permissions, yet still get the "Client denied by server configuration" error in your logs. Let's examine a real-world case where the DocumentRoot was set to /home/remix/ with proper directives, but access was still denied.

Before diving deep, verify these basics:


# Check if the directory exists and has correct permissions
ls -ld /home/remix/

# Verify Apache can access the directory (www-data user typically)
sudo -u www-data ls -l /home/remix/

If these commands fail, you need to fix filesystem permissions first.

On modern Ubuntu systems, AppArmor might be blocking access. Check its status:


sudo aa-status

If AppArmor is active, you'll need to either:


# Option 1: Disable AppArmor for Apache (not recommended for production)
sudo ln -s /etc/apparmor.d/usr.sbin.apache2 /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.apache2

# Option 2: Modify the AppArmor profile (better for security)
sudo nano /etc/apparmor.d/usr.sbin.apache2

The original configuration uses older syntax (Order allow,deny). For Apache 2.4+, use:



    ServerAdmin webmaster@localhost
    DocumentRoot "/home/remix/"
    ServerName testproject
    ServerAlias testproject
    
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    

For home directories, consider these permission settings:


# Set correct ownership
sudo chown -R $USER:www-data /home/remix/

# Set secure permissions
find /home/remix/ -type d -exec chmod 750 {} \;
find /home/remix/ -type f -exec chmod 640 {} \;

# Special case for WordPress or similar CMS
find /home/remix/ -type d -exec chmod 755 {} \;
find /home/remix/ -type f -exec chmod 644 {} \;

If permissions prove too complex, consider symlinking to Apache's default directory:


sudo ln -s /home/remix /var/www/testproject

Then update your vhost configuration accordingly.

Enable verbose logging temporarily:


# In your vhost configuration
LogLevel debug

# Or for specific modules
LogLevel authz_core:trace8

This often reveals the exact reason for the denial.

Before giving up, verify:

  1. Apache user (www-data) has execute permission on all parent directories
  2. No conflicting .htaccess files exist
  3. No IP-based restrictions in other configuration files
  4. Virtual host is actually being loaded (check with apachectl -S)

When your Apache server throws a "Client denied by server configuration" error despite having what appears to be correct directory permissions in your virtual host configuration, the frustration is real. Let's dissect this common issue that many developers face when setting up local development environments.

The error message AH01630: client denied by server configuration typically indicates that Apache's authorization system is blocking access to the requested resource, regardless of your Allow from all directive. This often stems from multiple layers of permission checks in Apache's modular architecture.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "/home/remix/"
    ServerName testproject
    ServerAlias testproject
    <Directory "/home/remix/">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted  # Modern replacement for Order/Allow
        # Order allow,deny    # Legacy syntax
        # Allow from all      # Legacy syntax
    </Directory>
</VirtualHost>

If you're running Apache 2.4+, the older Order allow,deny syntax is deprecated. The modern equivalent is:

Require all granted

Beyond Apache configuration, ensure the directory has proper filesystem permissions:

ls -ld /home/remix/
# Should show at least drwxr-xr-x
chmod 755 /home/remix/
chown -R $USER:$USER /home/remix/

On systems with SELinux enabled (common in CentOS/RHEL), you might need:

semanage fcontext -a -t httpd_sys_content_t "/home/remix(/.*)?"
restorecon -Rv /home/remix

Always verify your configuration before restarting Apache:

apachectl configtest

Here's a complete virtual host configuration that should work for most modern Apache setups:

<VirtualHost *:80>
    ServerName testproject
    DocumentRoot "/home/remix"
    
    <Directory "/home/remix">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/testproject_error.log
    CustomLog ${APACHE_LOG_DIR}/testproject_access.log combined
</VirtualHost>

Enable verbose logging temporarily in your Apache configuration:

LogLevel debug

Then check the error log for detailed information:

tail -f /var/log/apache2/error.log