How to Set AllowOverride All in Apache2 on Ubuntu

How to Set AllowOverride All in Apache2 on Ubuntu

If your Magento 2 store is not loading CSS and JavaScript, or your WordPress permalinks return 404 errors after a fresh server setup, the most common cause is Apache2 running with AllowOverride None. This setting tells Apache to ignore all .htaccess files, which means URL rewriting rules, access controls, and other directives your application depends on are silently skipped. This guide covers every method to correctly set AllowOverride All in Apache2 on Ubuntu and verify it is working.

What Does AllowOverride Do in Apache2?

The AllowOverride directive controls whether Apache reads and applies the rules inside .htaccess files for a given directory. When set to None, Apache completely ignores .htaccess files — every request is processed using only the main server configuration. When set to All, Apache allows .htaccess files to override any directive for that directory, including URL rewriting, authentication, caching headers, and access restrictions.

For applications like Magento 2 and WordPress, .htaccess files handle URL rewriting through mod_rewrite. Without AllowOverride All, the rewrite rules in these files are never read, which causes CSS, JavaScript, and images to fail loading — because the clean URLs that point to those assets cannot be resolved. Setting AllowOverride All is typically the first fix when a fresh Magento 2 install shows a blank gray page or missing styles.

Method 1: Edit apache2.conf (Global Setting)

The main Apache2 configuration file on Ubuntu is located at /etc/apache2/apache2.conf. This file contains a <Directory> block for /var/www/ that defaults to AllowOverride None. Changing it here applies the setting globally to all sites hosted under that path.

Open the file with your preferred editor:

sudo nano /etc/apache2/apache2.conf

Locate the block that looks like this:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

Change AllowOverride None to AllowOverride All:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Save the file and restart Apache2:

sudo service apache2 restart

Or using systemctl:

sudo systemctl restart apache2

Method 2: Edit the VirtualHost Configuration File

If your site uses a dedicated VirtualHost configuration file — which is recommended for any production setup — you should set AllowOverride All inside that file rather than in apache2.conf. Virtual host files are stored in /etc/apache2/sites-available/. The default file is 000-default.conf, but you may have a custom file for your domain.

Open your VirtualHost file:

sudo nano /etc/apache2/sites-available/000-default.conf

Inside the <VirtualHost> block, add or modify a <Directory> block pointing to your web root:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save the file and reload Apache2:

sudo systemctl reload apache2

Using the VirtualHost file is the preferred approach because it scopes the setting to a specific site and does not affect other virtual hosts on the same server.

Step 3: Enable mod_rewrite

Setting AllowOverride All allows Apache to read .htaccess files, but URL rewriting also requires the mod_rewrite module to be active. On a fresh Ubuntu server, this module is often not enabled by default. Run the following command to enable it:

sudo a2enmod rewrite

Then restart Apache2 to apply the change:

sudo systemctl restart apache2

You can verify the module is loaded by running:

apache2ctl -M | grep rewrite

If the output shows rewrite_module (shared), the module is active. If you see no output, the module did not load — check for configuration errors with sudo apache2ctl configtest.

If Apache is still not executing PHP after enabling the module, check for related issues such as Apache not executing PHP files correctly, which is a separate configuration problem that commonly appears alongside AllowOverride issues on fresh Ubuntu servers.

Verify the Configuration Works

After restarting Apache2, test that .htaccess files are being read. The quickest method is to add a deliberate syntax error to your .htaccess file and refresh the page. If Apache returns a 500 Internal Server Error, it means Apache is reading the file — which confirms AllowOverride All is active. Remove the test error immediately after confirming.

For Magento 2 stores, reload the storefront and check whether CSS and JavaScript assets are now loading correctly. If styles are still missing, also check whether max execution time or other PHP configuration values need adjustment, as these are separate issues that can cause similar symptoms during Magento page rendering.

Run sudo apache2ctl configtest to verify your Apache configuration has no syntax errors before and after any changes. The command should return Syntax OK at the end of its output.

AllowOverride None vs AllowOverride All: Which Should You Use?

AllowOverride None is faster and more secure. When set to None, Apache does not check for .htaccess files on every request, which reduces filesystem lookups and improves performance. For servers where you control the configuration directly, the Apache documentation recommends moving all directives from .htaccess into the main configuration files and keeping AllowOverride None.

AllowOverride All is necessary when you use applications that manage their own .htaccess rules — Magento 2, WordPress, Drupal, and most PHP frameworks fall into this category. These applications write rewrite rules, security headers, and caching directives directly to .htaccess during installation and updates. Blocking those files from being read breaks core application functionality.

On a dedicated server running a single application like Magento 2, AllowOverride All scoped to the application’s document root is the standard and correct configuration. On shared hosting environments with multiple untrusted users, restricting to specific directive categories like AllowOverride AuthConfig FileInfo is a safer middle ground.

People Also Ask

What is AllowOverride in Apache2?

AllowOverride is an Apache directive placed inside a <Directory> block that controls whether .htaccess files in that directory are allowed to override the main server configuration. Set to None, Apache ignores all .htaccess files completely. Set to All, Apache reads and applies every directive found in .htaccess files within that directory and its subdirectories. It accepts specific categories like AuthConfig, FileInfo, and Options for granular control.

What is AllowOverride None?

AllowOverride None is the default setting in Apache2 on Ubuntu. It disables processing of .htaccess files entirely for the specified directory, improving performance because Apache no longer checks for those files on every request. It is the recommended setting for servers where all configuration is managed through the main Apache config files rather than per-directory overrides.

How do I enable mod_rewrite in Apache on Ubuntu?

Run sudo a2enmod rewrite to enable the module, then restart Apache with sudo systemctl restart apache2. Confirm it is active with apache2ctl -M | grep rewrite. You also need AllowOverride All set for the directory containing your .htaccess file, otherwise mod_rewrite rules will be ignored even when the module is loaded.

How do I stop Apache running on port 80?

Run sudo systemctl stop apache2 to stop the service entirely, or edit /etc/apache2/ports.conf and remove or change the Listen 80 line, then reload with sudo systemctl reload apache2. To check what process is using port 80, run sudo lsof -i :80.

Troubleshooting AllowOverride Issues

If .htaccess rules still appear to be ignored after setting AllowOverride All and enabling mod_rewrite, check these common causes. First, confirm you edited the correct <Directory> block — Apache processes configuration files in order, and a second <Directory> block further down the file or in an included configuration can override your change back to None. Run grep -r "AllowOverride" /etc/apache2/ to find every occurrence across all configuration files.

Second, verify your document root path matches exactly. A block targeting /var/www/ does not automatically cover /var/www/html/mysite/ if another block more specifically targets that path with a different setting. Also confirm Ubuntu software repositories are up to date before installing or upgrading Apache packages, as outdated package sources can result in misconfigured default configuration files being installed.

Finally, always run sudo apache2ctl configtest after every edit. A configuration syntax error will prevent Apache from reloading successfully, and the old configuration — including the original AllowOverride None — will remain active until the error is resolved.

Al Mahbub Khan
Written by Al Mahbub Khan Full-Stack Developer & Adobe Certified Magento Developer

Leave a Reply

Your email address will not be published. Required fields are marked *