fsdolphin's avatar

How to use "php artisan serve" in a remote server - DigitalOcean

Hi,

I currently host all of my sites in DigitalOcean and use one domain mainly for testings Laravel, what I do is basically delete an recreate the Laravel project every time I want to test something in Laravel, it works fine but what I would like to do is be able to create a new Laravel project, use php artisan serve and then view it in the browser.

Is it possible use php artisan serve from your remote server (from DigitalOcean)? If yes, how do I view it in the browser?

I have tried http://ipaddress:8000 but it doesn't seem to work.

Thanks

0 likes
30 replies
xsmalbil@icloud.com's avatar

You'll have to do some router settings. Forward a port in the router to your pc's ip and port.

What exactly is the context of your question? You might be overthinking something or missing some information. Cause a server calling home is not something you see very often.

1 like
fsdolphin's avatar

@xsmall

I just want to simplify my testing process, as I mentioned it in my original post I currently use a domain just for testing purposes and I find it overkill (deleting, recreating). What I would like to be able to do instead when testing new features is be able to create a project and view it in the browser without creating any server blocks.

  1. Create new project
    laravel new projectname
  2. Serve
    php artisan surve
  3. View it in the browser (this is the part I'm not sure how to do).
Snapey's avatar

You don't say if php artisan serve returns any errors?

Assuming it starts correctly you should be blocked from doing anything else in that session until you press control-C

Assuming also that you are not running any other web server (apache or nginx)

Port 8000 might be blocked by your iptables, either permit or choose a different port with the --port= property of the artisan serve command. See all options with php artisan help serve

1 like
fsdolphin's avatar

@Snapey

No errors. When I run php artisan serve --host=503.246.895.41 --port=8125 this is what I see...

Laravel development server started on http://503.246.895.41:8125/

But when I go to my browser and type http://503.246.895.41:8125/ I get the This webpage is not available message.

@Snapey, quick question, In theory, should the process described above work? Have you serve your pages this way in a remote server (droplet)?

If course I'm using a fake ip and port here.

3 likes
fsdolphin's avatar

@Snapey - It's working now I just needed to enable the 8000 port in the firewall. Is it a bad a idea to have a port open just for testing, on this case port 8000?

Here is how you do it...

  1. Enter the following line in the terminal.
    php artisan serve --host=754.555.345.34 --port=4563
    EDIT: Deleted the http:// part (read the whole thread to see why)

  2. View it on the browser.
    http://754.555.345.34:4563

Of course replace host and port with your own.

Thanks a lot for your help!

fsdolphin's avatar

@Snapey Any idea how to stop artisan serve on a remote server? ctrl+c doesn't work.

What I'm trying to do is basically stop the page currently being served and serve a different Larval page.

Thanks

Snapey's avatar

sorry, no. ctrl-c should be it!

1 like
fsdolphin's avatar

Does any one out there know how to stop artisan serve on a remote server? It is serving correclty but I would like to serve a different page.

ctrl+c doesn't work as in a local enviroment.

Snapey's avatar

is it running interactively ?

if you have a console prompt you could try $ php app/console server:stop

fsdolphin's avatar

@Snapey
Yes, it is serving the page all the time.

Where am I suppose to run php app/console server:stop, inside my app? I tried running and I get the following message...

 Could not open input file: app/console

I actually stopped Nginx and the page keeps running after Nginx it's being stopped.

Snapey's avatar

PHP is running as an independent process (not under nginx). That line should work at the console?

1 like
Snapey's avatar

try killing the process by using ps to show running processes

Look for the entry mentioning php and server.php note the pid

kill previously noted pid

fsdolphin's avatar

@Snapey
As I said I get message Could not open input file: app/console when I run that on the terminal.

This is what I see when I run ps

PID TTY          TIME CMD    
40685 pts/4    00:00:00 bash    
40685 pts/4    00:00:00 ps    

I changed the pts numbers just in case I'm exposing something that I shouldn't.

Snapey's avatar

what do you see when you are trying to ctrl-c

1 like
fsdolphin's avatar

This is what I see after pressing ctrl-c

user@serverName:/var/www/projectName $ ^C

... but that's not a message, the prompt just changes from

user@serverName:/var/www/projectName $
to
user@serverName:/var/www/projectName $ ^C

Thanks

Snapey's avatar

OK so thats just your bas prompt. Control-c will not work there.

Are you logged in as the same user as when you started the php artisan serve since the process does not show up.

ps -A will give you a huge list of all processes.

1 like
fsdolphin's avatar

@Snapey
First of all thank you for following alone.

Yes, I'm logged as the same user.

I ran ps -A and I got a big list but I don't see anything that says server, I see multiple processes of php5, php and php5-fpm. Should I kill anithing with the php sufix?

Thanks

Snapey's avatar

This is what I see;

9900 ttys001 0:00.27 php artisan serve 9904 ttys001 0:00.08 /usr/bin/php -S localhost:8000 /Volumes/Macintosh HD/webdev/play/server.php

I could kill 9904 and then 9900 will stop on its own

If you are not seeing that, then (daft question), are you sure it's actually running!

1 like
fsdolphin's avatar

@Snapey
It is working now, I really appreciate that you here helping me, thanks a lot.

I was able to stop the server and now everything works, I can now stop it with ctrl-c

  1. To list the process I used sudo lsof -i
    As described in this thread http://stackoverflow.com/questions/27057501/how-to-terminate-old-session-in-iterm2
  2. Killed process listed under PID like so...
    kill PID#

I have a feeling that the main reason it got locked had something to do with the way I served the page, this is how I originally did it.

php artisan serve --host=http://754.555.345.34 --port=8000

and I have a feeling that you don't have to use the port number as long as you make sure port 8000 is open. This is what I'm using that seem to be working...

php artisan serve --host 754.555.345.34

Please note that besides the port number I also got rid of the =http://

Again I don't know if what I'm describing here had something to do with the fact that I couldn't stop it with ctrl-c or not but that's my story.

Again thanks a lot, you are AWESOME!

EDIT: After playing around a little bit more I got to the conclusion that what messes it up is the http:// because I tried php artisan serve --host=754.555.345.34 --port=8000 and it works fine.

Snapey's avatar

I am surprised it works. Those IP addresses don't make any sense (or have you deliberately obfuscated them)

1 like
avambro's avatar

sudo ufw allow 8000

and next

php artisan serve --host=_your_ip_address --port=8000

1 like
geea's avatar

check out php app/Console server:stop or your app/console path ... maybe it is App/Console

geea's avatar

and thats how you do it using force sudo lsof -t -i tcp:8000 | xargs kill -9

canker's avatar

php artisan serve --host=0.0.0.0 --port=80 <-- you must place "0.0.0.0" at your host option and it will work without set any firewall or any extra. I have my droplet in DigitalOcean and using Ubuntu 16.04 x64

2 likes
jvandemerwe's avatar

I had the same problem in Windows that php artisan serve showed a blank page.

When I retried it on another port it was showing me the view as expected.

Now when you start a CMD (as administrator) you can enter:

netstat -a -b |more

It will show you what ports are occupied. In my case port 8000 was already taken by PHPStorm. Just try it in case you see a blank page when not expected.

In that case you could do:

php artisan serve --port=8081

Please or to participate in this conversation.