简体   繁体   中英

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 eg 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

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

Laravel希望该文件夹位于应用程序的根目录中,因此请设置虚拟主机并更新主机文件以使其匹配。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM