Serv from local IP (inet addr) with PHP


Use PHPs built-in server to serve from local IP - or inet addr. In order to use or test from other devices on the same local network.

#!/usr/bin/env php

// This will get your IP, e.g.
$inet = trim(shell_exec('hostname -I'));

// If first arg is set ignore inet addr
// Then you could use e.g. localhost
if (isset($argv[1])) {
    $inet = $argv[1];

// Default port. If second arg is set then use this as the port
$port = 8080;
if (isset($argv[2])) {
    $port = $argv[2];

echo "Serving on $inet:$port";
echo PHP_EOL;
echo $command = "php -S $inet:$port";
echo PHP_EOL; 

This page has been viewed 1892 times. First hit: 16-Apr-2019 10:24:46
Share email, Google+, Twitter, Facebook.
comments powered by Disqus