How to Fix Apache 404 Not Found on Ubuntu 22.04
The Root Cause
Apache 404 Not Found on Ubuntu 22.04 primarily indicates that the web server cannot locate the requested file or resource within its configured DocumentRoot. This typically stems from an incorrect DocumentRoot path specified in the virtual host configuration, or the absence of the requested file (e.g., index.html) in the designated directory.
Quick Fix (CLI)
# 1. Create a basic index file if it's missing (assuming default /var/www/html)
sudo echo "<h1>WebToolsWiz: Apache is Working!</h1>" | sudo tee /var/www/html/index.html
# 2. Ensure the default Apache site is enabled
sudo a2ensite 000-default.conf
# 3. Reload Apache to apply changes
sudo systemctl reload apache2
Configuration Check
Edit the default virtual host configuration file: /etc/apache2/sites-available/000-default.conf
Verify the DocumentRoot directive points to the correct directory where your web files are located. Also, ensure the corresponding <Directory> block grants appropriate access.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html # <-- Verify this path is correct for your files
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html> # <-- Ensure this matches DocumentRoot and has 'Require all granted'
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
If you changed DocumentRoot, save the file, then restart Apache: sudo systemctl restart apache2.
Verification
# Check Apache configuration for syntax errors
sudo apache2ctl configtest
# Verify content by accessing localhost (or your server IP)
curl http://localhost/