Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 Virtual Host and mod rewrite setup

I've been trying for a few hours to install Laravel 4 and make the Virtual Hosts and Routing work but so far I've been unlucky. I'm mentioning that I'm doing this on a Windows 7 machine and WAMP.

I'll describe what I've already done:

I've enabled rewrite_module.

Updated httpd-vhosts.conf with the following:

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/laravel/public"
    ServerName laravel.dev
    ServerAlias www.laravel.dev
</VirtualHost>

Next, I've set up the etc/hosts:

127.0.0.1       localhost
127.0.0.1       laravel.dev

Also, the following lines are uncommented both in wamp/../conf/httpd.conf and in wamp/.../conf/original/httpd.conf:

LoadModule vhost_alias_module modules/mod_vhost_alias.so

Include conf/extra/httpd-vhosts.conf

The content of my .htaccess is the following:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Yet, when I go to http://laravel.dev I get an Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request..

If i remove the .htaccess file from the public folder, then I'll see the Laravel "You have arrived" message. If then, i create a route like this (within the app\routes.php):

Route::get('/newroute', function()
{
    return View::make('hello');
});

and then go to http://laravel.dev/newroute I'll end up with a 404 Not Found - The requested URL /newroute was not found on this server.

I am seriously confused and have no idea how I can get past this. I mention (although i think it's clear) that I ran a composer install after cloning the project template, installing the dependencies.

like image 517
Zubzob Avatar asked Nov 06 '13 01:11

Zubzob


2 Answers

If the htaccess file that you posted was in your /public/ folder, then that's why you're getting a 500 internal server error. That htaccess file was made for the folder that the /public/ folder is in. But since your public folder is the document root, you don't need it.

The htaccess file in the /public/ folder should look like this:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

(for WAMP).

like image 159
Jon Lin Avatar answered Nov 01 '22 13:11

Jon Lin


Try turning on AllowOverride All on the directory by changing your VirtualHost to:

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/laravel/public"
    ServerName laravel.dev
    ServerAlias www.laravel.dev
    <Directory "c:/wamp/www/laravel/public">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
like image 26
hayhorse Avatar answered Nov 01 '22 11:11

hayhorse