Akshay Mohite
Akshay Mohite

Reputation: 79

Run laravel 5 app without php artisan serve

I have created small blog application in laravel 5.2 .the app works whenever i run it using php artisan serve. But without running artisan serve , when i access it from public folder for e.g. localhost/blog/public/addBlog it gives error page not found.

My routes.php has following lines Route::get('addBlog','BlogsController');

It works fine with php artisan serve with visiting http://localhost:8000/addBlog

Upvotes: 0

Views: 2805

Answers (3)

Renish Gotecha
Renish Gotecha

Reputation: 2522

Use following command

sudo a2enmod rewrite

I had tried in to the ubuntu but i am not sure that will run in another os or not

Upvotes: 0

twigg
twigg

Reputation: 3993

Laravel expects the folder to be in the root of the application so set-up a virtual host and update your hosts file to match.

Upvotes: 0

Frnak
Frnak

Reputation: 6802

The solution is pretty simple. Laravel expects your public folder to be the root of the webserver / url / domain.

Using the serve command works since localhost:8000 is the root then.

Using the longer url doesn't work since your root is localhost/blog not localhost.

A fairly simple solution is to create a virtualhost, to explain how you can do this we would need to know what is running on your localhost (xampp? wamp?)

Nevertheless, the solution would be a virtualhost pointing to localhost/blog/public

Update example for wamp virtual hosts

C:\Windows\System32\drivers\etc\hosts => open as admin and add

127.0.0.1 blog.dev

C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
  ServerName blog.dev
  DocumentRoot "C:\wamp\www\blog\public"
  ServerAlias blog.dev
</VirtualHost>

It's basically the same for xampp, but the path to the vhosts conf is different

Don't forget to restart wamp/xampp after doing the changes. Then simply open http://blog.dev via browser and enjoy

Upvotes: 3

Related Questions