Monday, March 26, 2018

Authorization configuration has changed between Apache 2.2 and 2.4

If you are developing Symfony, Zend, Laravel, or any web framework requiring .htaccess,
and you upgrade Apache from 2.2 to 2.4, or your dev Vagrant vm is updated to a newer OS, your web site may start showing the ambiguous error message
“Forbidden You don't have permission to access / on this server”

There are a multitude of possible causes for this error, but assuming you web site was working, and you just upgraded Apache, check the Apache virtual host configuration as the Authorization configuration has changed between Apache 2.2 and 2.4

Ubuntu
> sudo vi /etc/apache2/sites-enabled/[your vhost site].conf

Centos
> sudo vi /etc/httpd/conf.d/[your vhost site].conf


Prior Configuration

<VirtualHost *:80>
    ServerName tutorial.localhost
    DocumentRoot /path/to/tutorial/web
    SetEnv APP_ENV "dev"
 
    <Directory /path/to/tutorial/web>
        AllowOverride All
        Order allow,deny    #<-- 2.2 config
        Allow from all        #<-- 2.2 config
    </Directory>
</VirtualHost>

Updated Configuration

<VirtualHost *:80>
    ServerName tutorial.localhost
    DocumentRoot /path/to/tutorial/web
    SetEnv APP_ENV "dev"
    <Directory /path/to/tutorial/web>
        AllowOverride All
        Require all granted   #<-- 2.4 New configuration
    </Directory>
</VirtualHost>

Ah the simple things

restart apache

Ubuntu
> sudo systemctl restart apache2

Centos
> sudo service httpd restart

References:
http://httpd.apache.org/docs/2.4/upgrading.html#run-time
https://stackoverflow.com/a/24665604/3893727


Related info:
You can also make sure apache has permission to your web root
> ls -l /path/to/tutorial/web

Ubuntu
www-data should have access

Centos
apache should have access

Or find whatever process name Apache is running as
> ps -aef | grep apache
or
> ps -aef | grep httpd

If your web root is a personal directory, you can add your user to the Apache group

Ubuntu
> sudo usermod -a -G www-data vagrant

Centos
> sudo usermod -a -G apache vagrant


End of document. Thanks for reading.

No comments:

Post a Comment