Search code examples
apache2lamp

How do I set up LAMP without the forbidden message when viewing my site?


I use a Linux Mint 16 + newest LAMP + Laravel.

I'm getting this error when I try viewing my website either via "localhost" or "127.0.0.1".

Forbidden

You don't have permission to access / on this server.
------------------------------------------------------
Apache/2.4.6 (Ubuntu) Server at 127.0.0.1 Port 80

My setting are as follows:

on /etc/hostname

NameServer ynwlocalwebserver

on /etc/hosts

127.0.0.1       localhost
127.0.1.1       ynwlocalwebserver

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

I only have one site-enable named "ynwlocalwebserver.conf" it's current contents for the meantime are:

NameVirtualHost *:80

<VirtualHost *:80>

  ServerName ynwlocalwebserver
  DocumentRoot /home/ynwmint/ynw/public
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  <Directory /home/ynwmint/ynw/public>
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

</VirtualHost>

<VirtualHost *:80>

  ServerName localhost
  DocumentRoot /home/ynwmint/ynw/public
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  <Directory /home/ynwmint/ynw/public>
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The folder ynw in "/home/ynwmint/ynw/public" is the Laravel project.

I put the chmod of the public folder to 777 (for the meantime) and chown it under www-data:www-data

What am I doing wrong, or what else do I need to check?

Thanks.


Solution

  • Apache 2.4 has some minor changes with regards to config.

    This:

    ServerName ynwlocalwebserver
    DocumentRoot /home/ynwmint/ynw/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    <Directory /home/ynwmint/ynw/public>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    

    Should be changed to this:

    <VirtualHost *:80>
    
        ServerName ynwlocalwebserver
        DocumentRoot /home/ynwmint/ynw/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        <Directory /home/ynwmint/ynw/public>
            Options +Indexes +FollowSymlinks + MultiViews
            AllowOverride All
            Require all granted
        </Directory>
    
    </VirtualHost>
    

    Also for added security you may want to this directory rule:

    <Directory />
        Options FollowSymlinks
        AllowOverride None
    </Directory>
    

    Source: http://httpd.apache.org/docs/2.4/upgrading.html