DEV Community

Tony Metzidis
Tony Metzidis

Posted on

PHP Dev Environment One-Liner

Here's the fastest way to get your PHP app running. No MAMP, WAMP, apache or any of that nonsense.

Moreover, it allows you to run multiple projects independently.

I'm assuming you have docker.

tl;dr

This runs the php docker image, mounts the current directory, and spins up a server on port 8086

$ docker run -v $(pwd):/www -it -p8086:8086  php:5.6-alpine sh -c "cd www; php -S 0.0.0.0:8086"

The Full Version

Create your index.php

$ cat > index.php
<html><body><h1><?php print("Hello World!") ?> </h1></body></html>
CTRL-D

Run the Server

$ docker run -v $(pwd):/www -it -p8086:8086  php:5.6-alpine sh -c "cd www; php -S 0.0.0.0:8086"

Test Your Server

$ curl localhost:8086
<html><body><h1>Hello World! </h1></body></html>

Top comments (1)

Collapse
 
tonymet profile image
Tony Metzidis

I hear you. This one liner fills a use case where you need to quickly work on a PHP project for a short period of time, with minimal effort. Another idea would be to quickly prototype or test PHP concepts for beginners while avoiding the investment in tools.

Every tool has a niche.