6

I'm new in Laravel, I made virtual host http://example.com and installed Laravel in folder of this domain but when I try to access this domain I get this enter image description here

2
  • Show your VirtualHost configuration, and make sure the vhosts module is enabled in your httpd.conf Commented Jan 27, 2014 at 16:34
  • <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/example" ServerName example.com ServerAlias www.example.com ErrorLog "logs/www.example.com.domain-error.log" </VirtualHost> Commented Jan 27, 2014 at 16:41

3 Answers 3

14

This is your VirtualHost setup

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/example" ## <-- pointed to wrong folder
    ServerName example.com
    ServerAlias www.example.com 
    ErrorLog "logs/www.example.com.domain-error.log"
</VirtualHost>

You didn't point it to the public folder. It should be (These are minimum requirements)

<VirtualHost *.80>
    DocumentRoot "C:/xampp/htdocs/example/public"
    ServerName example.com
</VirtualHost>

You should point it to the public folder because index.php is inside public folder.

I use this kind of setup

<VirtualHost laravel4.dev>
    DocumentRoot "D:/xampp/htdocs/laravel4/public"
    ServerName laravel4.dev
</VirtualHost>

Corresponding setup in windows/system32/drivers/etc/host file is

127.0.0.2           ci.dev
127.0.0.3           laravel4.dev ## <-- This is for current vHost
127.0.0.4           symcom.dev

So, I can navigate to my site on local host using http://laravel4.dev (dev for development)

Sign up to request clarification or add additional context in comments.

3 Comments

Wish I would have found this post when I was Googling this exact same issue... I put it together finally and it worked, but this would have saved me some grief!
@AVProgrammer, Wish you all the best and better luck next time and thanks for the thumbs up :-)
I did the same thing too. I thought pointing the vhost to the laravel installation folder /example/ should be enough thinking Laravel routing will take care of moving all / urls to the public folder automatically. Guess I was wrong after reading this.
5

That's exactly what you should be seeing. When you click the 'public' folder do you see a 'You have arrived.', with the laravel logo? If so, then you've correctly installed laravel.

The 'public' folder, is the main folder in which the actual public has access to your website when you put it on a server. You'll want to do one of two things here:

The simple (but insecure) way:

Add a .htaccess file to the root of your web folder containing this text:

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

This will make all requests go to www.example.com/public, but only show www.example.com in the URL.

The harder (but correct) way:

This completely depends on which provider you will be hosting your website on, but on Godaddy and others, you have the option of selecting the root folder of your website. In this case you'd select the 'public' folder to be the root. I cannot give you a tutorial on that because this option ranges on availability on every hosting provider.

EDIT: I should add just in case. When you add content to your site, such as CSS/images/files and everything the public will have access to, make sure you put them in the public folder.

Comments

2

You VirtualHost configuration needs to point DirectoryRoot further into public/ directory, so it can use its .htaccess and index.php inside that directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.