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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
medo ampir
  • 1,850
  • 7
  • 33
  • 57

3 Answers3

13

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

Basel J. Hamadeh
  • 935
  • 1
  • 7
  • 19
  • 1
    `php artisan serve&` worked like a charm !! Thanks. How to close it now ? Closing the terminal only ? – PlayHardGoPro Jul 19 '17 at 21:19
  • After running that, do I need press `Ctrl+c`? @PlayHardGoPro – Kiran Reddy Dec 26 '17 at 08:35
  • @KiranReddy Ya ! `Ctrl+C` did the trick. not sure if the command `Exit` will work aswell. – PlayHardGoPro Jan 02 '18 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 '21 at 21:26
  • What is the significance of the ampersand?? – Jay.Smyth Oct 14 '21 at 09: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.

Joseph
  • 2,737
  • 1
  • 30
  • 56
  • 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 '16 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 http://localhost. If that doesn't work, it means you have LAMP set up incorrectly. – Joseph Feb 27 '16 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 '16 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 http://localhost/public but this can be configured. – Joseph Feb 27 '16 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 '16 at 14:26
  • Can you temporarily move your Laravel project out of there and put an index.html file with text in it in /var/www/html/public to make sure it's not an Apache issue? – Joseph Feb 27 '16 at 14:29
  • ok, just did that, I move the whole application to the localhost dir, and created an index.html with simple data, and going to localhost/public shows that simple file correctly. and also when I open http://localhost the default page in var/www/html/index.html shows perfectly, and if I changed it to index.php also works fine. – medo ampir Feb 27 '16 at 14:37
  • Sorry, just read your old message again and see you said that "/" is now working properly. So the original question is no longer relevant. I think you should post a new question about the login issue showing your routes and detailing what you've done to set up auth so far. – Joseph Feb 27 '16 at 14:41
  • the "/" is working proberly because I write the "php artisan serve" every few moments, but the same problem is still exists. If I restarted my computer it won't work unless I run the command again. – medo ampir Feb 27 '16 at 14:45
  • But you said that artisan serve is serving on http://brk.localhost:8000. Apache will be serving on http://brk.localhost (no port 8000) unless you've changed it. – Joseph Feb 27 '16 at 14:46
  • let me make this more clear, right now I have all the application files inside my "var/www/html" directory. what is my main page url?. because "http://localhost" return a page with "Index of /" all files. and "http://localhost/public" returns a blank page. – medo ampir Feb 27 '16 at 14:51
  • It depends on what you set for the DocumentRoot in your virtual host. – Joseph Feb 27 '16 at 14:52
  • If your document root is /var/www/html then your URL is brk.localhost/public but if you set your document root to /var/www/html/public then your URL to Laravel home is just brk.localhost (as long as you put Laravel in /var/www/html) – Joseph Feb 27 '16 at 14:56
  • I moved the whole application to the html dir lets work from there and forget about the virtual server. I changed the document root so now localhost directs to the public folder of laravel. and just in case I changed the override to be All. and restarted apache. localhost is blank page. and localhost/public shows "The requested URL /public/ was not found on this server." – medo ampir Feb 27 '16 at 15:03
  • But if you put an index.html file in public and access localhost (no publuc) then it works? In that case, can you enable display errors in php.ini and see what's happening? – Joseph Feb 27 '16 at 16:03
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.

Community
  • 1
  • 1
Manu
  • 48
  • 7