Web Server with a single command

With a single command is possible to start, on Linux, a temporary webserver, publishing some folder contents in a port of your choice. To kill it, just the good and old Ctrl+C. Very useful in a lot of cases

Using Python (no PHP, but does not require any additional package)

python -m SimpleHTTPServer [port number]

Using terminal, access a folder, execute the command above, and type in browser:

    • http://127.0.0.1:<port> (local access)
    • http://seu-ip-na-rede:<port> (remote access)

If ommited, the default port number is 8000.

This command also works on Windows, if you use Cygwin.

More information abouut the SimpleHTTPServer:  http://docs.python.org/2/library/simplehttpserver.html

With PHP support (requires php 4.5 or higher)

php -S <ip>:<port> (in this case, the port is mandatory)

Using terminal, access a folder, execute the command above, and type in browser:

    • http://<ip>:<porta>

To allow local access, yout must run this command with the address 127.0.0.1

To allow remote acess, run it with your network IP.

If PHP is not installed and your distro supports apt-get, do this:

sudo apt-get install php5

More information about the PHP Built-in web server: http://php.net/manual/en/features.commandline.webserver.php