I setup a Laravel app on a VPS. It's for demonstration purposes only.
I would ssh login to the VPS using PuTTY and type:
php artisan serve --host x.x.x.x
Everything works fine. However, when I close the PuTTY connection, the server shuts down.
Is it possible to let the artisan server run in the background just like Apache?
You can run any shell command in the background by adding &
to the end. If you want it to continue to run after you've disconnected, then run it with nohup
nohup php artisan serve &
To kill it later, you'll be given a process ID, but don't be fooled because this kicks off other processes that will persist even when killed. To get the actual server PID, you can find it by filtering ps
output with grep
ps -ef | grep "$PWD/server.php"
Should give you some output like this:
jeff 23978 23977 0 16:50 pts/4 00:00:00 /usr/bin/php7.0 -S 127.0.0.1:8000 /path/to/laravel-project/server.php
jeff 24059 18581 0 16:51 pts/4 00:00:00 grep --color=auto /path/to/laravel-project/server.php
The first number after your username is the PID you want to kill.
kill 23978
Don't do this for a production site, but a quick demo might be ok.
Probably the quickest way to do this, at least on a temporary level, is to use screen - You can run it in a screen session and then Ctrl-a then d in Putty/shell to minimize it. It will continue running after your session closes.
You can resume and kill or restart later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With