Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make "php -S" to work on local network?

Tags:

php

server

lan

In OS X Mavericks (and newer), start a PHP server from the command line:

cd to/your/directory
php -S localhost:8888

It works, but the server only available on that computer only. Is there a way to test it on other devices within the same LAN?

like image 263
Stickers Avatar asked Nov 19 '15 15:11

Stickers


People also ask

How do I run a PHP site locally?

Type the command php -S localhost:8000 to run your site on port 8000. Note: If you get an error that 'php' is not recognized, you likely will need to add it to your path manually. To do that, locate php.exe (for me it is in the directory C:\xampp\php\ ).

What is local server in PHP?

A local server is a server that is running in a local or a mounted folder and whose document root is NOT the parent of the project root. To configure access to the server in this set-up, you need to specify the following: The server configuration root folder and the URL address to access it.


2 Answers

EDIT:

You will want to launch the server with the command

php -S 0.0.0.0:8888

This will allow you to access the server remotely (see docs http://php.net/manual/en/features.commandline.webserver.php)

After this is done there are 2 ways to view the site on your local network

http://192.168.1.2:8888 where 192.168.1.2 is the IP address of your computer which you can find in your System Preferences under Network.

http://myMac.local:8888 where myMac is your local computer name which you can find in your System Preferences under Sharing.

REMEMBER: Both of these options may require your firewall to allow incoming traffic to port 8888 (or whatever port your script is listening on), if you have that running.

like image 73
cmorrissey Avatar answered Sep 17 '22 13:09

cmorrissey


Start with:

php -S 0.0.0.0:8888

otherwise you bind the server to localhost;

like image 25
wolfx Avatar answered Sep 17 '22 13:09

wolfx