How to Fix Apache Permission Denied on Ubuntu 22.04
The Root Cause
Apache on Ubuntu 22.04 runs as the www-data user and group by default. “Permission denied” errors typically occur when the www-data user lacks the necessary read, write, or execute permissions for the web root directory, its subdirectories, or the specific files Apache is trying to access or serve.
Quick Fix (CLI)
# Set the web root owner to www-data (recursively)
sudo chown -R www-data:www-data /var/www/html
# Set directory permissions to 755 (read, write, execute for owner; read, execute for group and others)
sudo find /var/www/html -type d -exec chmod 755 {} \;
# Set file permissions to 644 (read, write for owner; read for group and others)
sudo find /var/www/html -type f -exec chmod 644 {} \;
# Restart Apache to apply changes
sudo systemctl restart apache2
Configuration Check
File: /etc/apache2/sites-available/your-site.conf (replace your-site.conf with your actual virtual host configuration file, e.g., 000-default.conf).
Lines to check: Within the <Directory /var/www/html> block (or your specific web root path), ensure the following if you are using .htaccess files for URL rewriting or other directives:
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All # Ensure this is set to All if using .htaccess
Require all granted
</Directory>
Additionally, verify that your ErrorLog and CustomLog paths (found in apache2.conf or your virtual host file) are writable by the www-data user.
Verification
-
Check Apache service status:
sudo systemctl status apache2Ensure the service is
active (running). -
Monitor Apache error logs for new errors:
sudo tail -f /var/log/apache2/error.logAttempt to access your website in a browser and watch for any new permission-related errors.
-
Access your website via a web browser.