Forbidden error in apache virtual host setup

user1000232 picture user1000232 · May 4, 2013 · Viewed 12.5k times · Source

Hello I have been looking through internet articles forums to solve my issue and so far it has been to no avail. I am trying to set up an Apache virtual host for my FuelPHP development on localhost but I keep getting slammed with the error 403 message. Here is my current setup.

#/etc/apache2/sites-enabled/000-default
NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/home/supercomputer/Desktop/PHP/fuelProject/public"
    ServerName   localhost.home
    <Directory "/home/supercomputer/Desktop/PHP/fuelProject/public" >
        Options Indexes FollowSymLinks MultiViews Includes ExecCGI
        AllowOverride All
        Order Allow,Deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

I have pointed my Docroot to the public folder inside my fuelProject. Also to make sure Apache had access to the server files, I set the permissions for all of the files recursively to read, write, and execute just to be a 100% safe. Any clues as to what else could be going wrong?

PS: I am running ubuntu raring (13.04)

PSS: And I am trying to visit localhost.home and localhost.home/index.php. I also get the following warnings upon restarting the server

* Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
 ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:59 2013] [warn] NameVirtualHost *:80 has no VirtualHosts

Answer

Aravind.HU picture Aravind.HU · May 5, 2013

Here is the correct way of adding Vhost for fuelphp application or any other php application

<VirtualHost *:80>
    ServerName localhost.home
    DocumentRoot /home/supercomputer/Desktop/PHP/fuelProject/public
    ServerAdmin webmaster@localhost
    <Directory /home/supercomputer/Desktop/PHP/fuelProject/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

And also the below line is not required I dont know why you have added

NameVirtualHost *:80

After doing all above add a host entry to your machine to do that

sudo vi /etc/hosts

add an entry of the virtual host

127.0.0.1  localhost.home

After doing all these things

restart Apache by running

sudo /etc/init.d/apache2 restart 

And just load http://localhost.home in your browser you should be able to see your site up and running .

If you still get forbidden error .you need to give permissions to your whole application folder

follow run these commands to do so

sudo chown -R www-data:www-data /home/supercomputer/Desktop/PHP

sudo chmod -R 775 /home/supercomputer/Desktop/PHP

At last add yourself to www-data group

sudo adduser yourUserName www-data