8

I'm learning laravel, and at the beginning I had run the command

php artisan serve

and keep my terminal window open so I can keep the server running, but later I wanted to just work with my app just like working on a normal php application so I created a virtual host directed to my laravel application "public" folder.

here is the problem:

I still have to run the "php artisan serve" and open my virtual server url

http://brk.localhost:8000

and then close the terminal, all that before I can normally open this link without defining the port number 8000. and If I left my computer and get back to continue work, I found that I can't access it unless I do the whole process again. and If I made a modification to any of the application views I get the same problem.

what am I missing?

3 Answers 3

13

Just add the and symbol '&' to the end of the command. This will keep it running in the background.

5
  • 1
    php artisan serve& worked like a charm !! Thanks. How to close it now ? Closing the terminal only ? Jul 19, 2017 at 21:19
  • After running that, do I need press Ctrl+c? @PlayHardGoPro Dec 26, 2017 at 8:35
  • @KiranReddy Ya ! Ctrl+C did the trick. not sure if the command Exit will work aswell. Jan 2, 2018 at 11:13
  • Your answer is a bit misleding , when I put at the end of the actual command like :php artisan serve& --host=xxx.xx.xx.xx --port=7879 it launched local ip 127.0.0.0 then I put it at the end of parameters like php artisan serve --host=xxx.xx.xx.xx --port=7879& it indeed started work ok then returned to this post again and upvoting.
    – CodeToLife
    Jan 23, 2021 at 21:26
  • What is the significance of the ampersand??
    – Jay.Smyth
    Oct 14, 2021 at 9:12
1

There are 3 main ways that you can access your Laravel app while you are developing it.

1) Using artisan serve

This method is probably the easiest method but it does mean that you have to remember to do this every time you start working on your project, which you have said that you do not want to do.

2) Using Laravel Homestead

This method requires a little more configuration but the documentation is very good. You won't have to remember to keep the terminal window open when you use it, but you'll still have to remember to keep the virtual machine running.

3) Set up LAMP / MAMP / WAMP or even LEMP

Setting up a local Apache or Nginx daemon on your own machine will require the most amount of configuration but it will mean that your web server automatically starts with your OS so whatever you put in your web directory will always be accessible through the web browser. You will not need to run and terminal commands or run a virtual machine.

Please note, however, that by using a local Apache/Nginx daemon you will be sacrificing a lot of flexibly and you will not have the luxury of deleting it all and starting again in a few minutes if you mess up the config.

Still, a lot of people still prefer to run their own Apache/Nginx daemon locally for development. I am one of them.

15
  • I have all the application included in LAMP installed. Apache server, PHP, Mysql and all on my Ubuntu system.still have the same issue.
    – medo ampir
    Feb 27, 2016 at 10:12
  • Yes, but you said that you were running your project using artisan serve. If you have LAMP installed and setup properly then you do not need to use artisan serve. You can simply access localhost. If that doesn't work, it means you have LAMP set up incorrectly.
    – Joseph
    Feb 27, 2016 at 12:27
  • may be but how can I check? everything is working fine except laravel application, it is full of complications... and now while I'm trying to figure out the solution to my problem above I hit another issue that wasn't happening before. I can access the home view "/" but I can't access any other view. it says "The requested URL /login was not found on this server.". the framework should help not make it worse :D
    – medo ampir
    Feb 27, 2016 at 14:18
  • You said LAMP, right? So that means you are using Linux. What's in your /var/www directory? Your Laravel project needs to be in there and will be accessible at localhost/public but this can be configured.
    – Joseph
    Feb 27, 2016 at 14:23
  • here it is "/var/www/html/brokers" is the project directory. and I have a virtual host "brk.localhost" directed to "/var/www/html/brokers/public"
    – medo ampir
    Feb 27, 2016 at 14:26
0

I encountered a similar situation where, if I were to save any modification to project files, I had to run "php artisan serve" and quit it before apache2 can serve the site.

I fixed it by modifying the file system permissions for my project.

I found this , which fixed the permission issue.

This solved the situation where I had to run php artisan serve, over and over again.

Primary cause of this is running package managers as sudo. Every file is created with bad permissions.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.