0

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

3 Answers 3

3

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

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

Comments

0

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.

Comments

0

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

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.