Docker PHP built-in server web app container and Nginx-proxy

I have been migrating some projects to my Digital Ocean server with Docker installed. One of these migration projects uses PHP in its back-end and had Lighttpd serving the content. Recently I've ventured into the NodeJS world, but I started that PHP project before. Now I use Express for serving my Javascript apps. So I wanted to find an minimalistic replacement for Lighttpd to bundle with my PHP app container.

PHP built-in server

PHP has an built-in http server. Usage is very simple, from your app root run: php -S localhost:8080
This suits my needs perfectly. Notice that the PHP manual warns that the server shouldn't be used on a public network, only for development. I like gray lines.

Dockerfile:

FROM php:7.1-cli

COPY . /usr/src/app  
WORKDIR /usr/src/app

EXPOSE 8080

CMD php -S 0.0.0.0:8080  

Nginx-proxy

I run the container like this: docker run -d -e VIRTUAL_HOST=change_to_your_domain.com --name app_name image_name

The -e environmental variable is for my Nginx-proxy container that handles incoming requests and points them to the correct content. This way I can host multiple domains with one ip on DigitalOcean.

Find out more about Nginx-proxy:
https://hub.docker.com/r/jwilder/nginx-proxy/

Sandro

So many projects to make! I Enjoy building electronics, especially radios. I also like web development, playing with hardware like the Raspberry Pi and spending time outdoors. Love combining it all!

Finland
comments powered by Disqus