0

I have set up my first Larevel application on WampServer on my local machine under the directory 'laravel', When I type localhost/laravel it takes me to the file structure as shown below. I can only get to the homepage of the application when I type in localhost/laravel/public.

enter image description here

Here is my routes.php file:

Route::get('/', function () {
    return view('welcome');
});

Route::auth();

Route::get('/home', 'HomeController@index');

How do I configure my application to make the welcome page the root? Am I missing something here? Surely there is an easier way to do this than having to edit the .htaccess?

user3574492
  • 6,225
  • 9
  • 52
  • 105
  • .htaccess is the way to go – Rolf Pedro Ernst Aug 04 '16 at 20:40
  • Config you wamp to laravel/public directory. My httpd-vhosts.conf: ` ServerName sockets.dev ServerAlias www.sockets.dev DocumentRoot E:/Projects/LaravelSockets/laravel/public/ Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted Order allow,deny Allow from all ErrorLog "logs\errors.log" LogLevel warn ServerSignature Off ` – mcklayin Aug 04 '16 at 20:41
  • @mcklayin what if I'm not using vhosts? When I eventually move this app onto a production server I won't have access to the Apache configs so this is not a feasible option. – user3574492 Aug 04 '16 at 20:42
  • you want need to config it on a production server as thats done for you when setting up a domain name and that. As this is a local version you will need to set up a vhost etc for the system to work. You can try localhost/laravel/public and it should display but that will be it, it wont work form there etc without a vhost file etc as mentioned above. – Simon Davies Aug 04 '16 at 20:45

2 Answers2

1

Try this:

/.htaccess

RewriteEngine on
RewriteRule (.*)$ /laravel/public$1 [R=301,L]
Alfredo EM
  • 2,029
  • 1
  • 14
  • 16
  • This worked, very quick and easy. I don't like the idea of setting up a vhost because when migrating to different environments it could be problematic. However with a .htaccess file it will pretty much work wherever I move my application to. Thanks! – user3574492 Aug 04 '16 at 20:58
  • Another option is to use https://laragon.org/ this modern LAMP Server automatically configures virtual host for your projects. If you create a project in the path www/laravel one virtualhost be created and you can access the url laravel.dev (this is configurable). Take the time to try this tool – Alfredo EM Aug 04 '16 at 21:01
  • This looks good but at this moment I am sort of forced to stay with the simplest solution without a vhost because when I host my application on a production server, it won't be configurable – user3574492 Aug 04 '16 at 21:05
  • But one question? I don't want my URL to have public in it, how do I change this? – user3574492 Aug 04 '16 at 21:12
  • Check this http://stackoverflow.com/a/28735930/5885326 it's amazing how easy it is!!! – Alfredo EM Aug 04 '16 at 21:13
0

Somewhere in the apache config files you have a

<DocumentRoot "/path/to/laravel">

You should change this to

<DocumentRoot "/path/to/laravel/public">

For security reasons only a few files are 'put online', but public/index.php will still do everything you want.

After you have done this, make sure your .htaccess file is correct. If you don't your routes will not work properly.

Options +FollowSymLinks
RewriteEngine On

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

As shown here in the laravel 5.1 doc's. Not sure why they left it out in 5.2...