SlideShare a Scribd company logo
PHP development
with Docker
Introduction to PHP development using Docker containers
March 23rd, 2016 - Yosh de Vos
Setting up the
development stack
Why Docker?
• Play with new technology
• Performance issues with
Vagrant on Windows
• Runs native on Linux
• Why not?
The setup
Software
• Docker Engine
• Docker Machine
• Docker Compose
Stacks
• Apache
• Nginx
The Apache stack
Apache + PHP:
custom build image with Apache, mod_php and
SSH access
Mysql:
official Mysql or Mariadb image listening on port
3306 using volumes from data container
Memcached:
official image with memory limitation listening on
port 11211
Mysql
Apache-PHP
Memcached
Mysql Data
The Nginx stack
Nginx:
official Docker image listening on port 80
and using fastcgi for PHP-FPM
Mysql:
official Mysql or Mariadb image listening on port
3306 using volumes from data container
Memcached:
official image with memory limitation listening on
port 11211
PHP-FPM:
custom build image with PHP-FPM and SSH access
Mysql
Nginx
PHP-FPM
Memcached
Mysql Data
The PHP image
Custom build image based on phusion/baseimage:
• Ubuntu 14.04 LTS
• Easy to use init system
• Syslog and logrotate configured correctly
• Crond
• Ondrej Sury PPA repository
Running services:
• Postfix
• Syslogd
• Crond
• PHP-FPM or Apache
Different images for:
• PHP 5.5, 5.6 or 7.0
• PHP-FPM or Apache with mod_php
• With or without development tools
The PHP development image
A layer on top of the PHP image to add functionality
for development environment like:
• SSH server
• Xdebug
• Custom entrypoint.sh to create user on first boot
• Various development tools
Development tools:
• Phing
• Phpcs
• Phpmd
• Phpunit
• Bower
• Grunt
• Gulp
• Npm
Container access
• Using SSH to access the container using agent
forwarding
• The same username and userid as the host OS is
available inside the container to preserve
ownership and permissions
• Optimized Bash prompt and installed all required
tools for development
• All sudo rights available when needed
Entrypoint.sh
A small script set as entrypoint that creates a new
user on first boot of the container using environment
variables.
This makes sure that the user on the host OS is
available inside the container with the same
username and userid.
Linked volume
The /var/www volume is shared with the host
OS.
● Directly linked from the host OS
● No need for continuously syncing during
development
● State between container lifecycles remain
• /var/www/
• .ssh/
• sites/
• my-application/
• web/
• .bash_history
• .bashrc
• .gitconfig
Container linking
Using container linking to enable DNS aliases
inside containers.
In this way the DNS alias can used inside your
app configuration.
● The mysql and memcached containers are
linked to the PHP container and are available
as hostname “mysql” and “memcached”.
● The PHP container is linked to Nginx and is
available as hostname “php”.
# parameters.yml
parameters:
database_host: mysql
memcached_host: memcached
# nginx.conf
server {
location ~ .php(/|$) {
fastcgi_pass php:9000;
}
}
Virtualhost configuration
Configuration for Nginx/Apache is
stored outside the container so it easy
to add virtualhosts for each application.
The default virtualhost resolves all
domain names to document root:
./www/sites/<domain>/web
# apache.conf
<Virtualhost *:80>
ServerName sites.dev
DirectoryIndex index.html index.php app.php
VirtualDocumentRoot /var/www/sites/%1/web
</Virtualhost>
# nginx.conf
server {
server_name ~^(?<domain>.+).dev$;
root /var/www/sites/$domain/web;
}
DNS aliases
Solutions:
• Use static ip address
• Use dnsmasq for wildcard
subdomains like *.dev
• Add each hostname to
/etc/hosts
# /etc/dnsmasq.conf
address=/dev/192.168.99.100
# /etc/hosts
192.168.99.100 application.dev
docker-compose.yml
nginx
mysql_data
http -> 80, https -> 443
ssh -> 2022
mysql -> 3306
Docker
Machine
php-fpm
<application>.dev mysql
memcached
The setup
Resources
PHP docker images
https://github.com/yoshz/docker-php
https://hub.docker.com/u/yoshz/
Bunch of dockerfiles to can build different types of
PHP containers.
- PHP 5.5, 5.6 or 7.0
- Apache + mod_php or Nginx + php-fpm
- Separate images with development tools
integrated
PHP Development Stack
https://github.com/yoshz/phpdevstack
Bunch of scripts and docker-compose files to quickly
start your own development stack with PHP.
Thank you
@yoshzz
github.com/yoshz
hub.docker.com/u/yoshz

More Related Content

PPTX
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
PDF
Developing and Deploying PHP with Docker
PPTX
Dockerizing a Symfony2 application
PDF
Dockerize your Symfony application - Symfony Live NYC 2014
PPTX
Deploying Symfony2 app with Ansible
PDF
Continuous Integration: SaaS vs Jenkins in Cloud
ODP
Docker for Developers - php[tek] 2017
PPT
Learn basic ansible using docker
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Developing and Deploying PHP with Docker
Dockerizing a Symfony2 application
Dockerize your Symfony application - Symfony Live NYC 2014
Deploying Symfony2 app with Ansible
Continuous Integration: SaaS vs Jenkins in Cloud
Docker for Developers - php[tek] 2017
Learn basic ansible using docker

What's hot (20)

PDF
Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Dock...
PDF
Using docker to develop NAS applications
PPTX
Native Containers on Windows 10 & Windows Server 2016 using Docker
PPTX
Docker 1.11 Presentation
PDF
Docker + Microservices in Production
PDF
How to deploy PHP projects with docker
PPTX
The How and Why of Windows containers
PDF
Docker All The Things - ASP.NET 4.x and Windows Server Containers
PPTX
Deploying Windows Containers on Windows Server 2016
PPTX
Docker orchestration
PDF
Docker up and running
PPTX
Exploring Docker Security
PDF
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
PPTX
Docker for Developers - Sunshine PHP
PPTX
Real World Experience of Running Docker in Development and Production
PPTX
From Docker to Production - SunshinePHP 2017
PDF
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
PDF
Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...
PPTX
Docker Networking Tip - Macvlan driver
PPT
Build service with_docker_in_90mins
Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Dock...
Using docker to develop NAS applications
Native Containers on Windows 10 & Windows Server 2016 using Docker
Docker 1.11 Presentation
Docker + Microservices in Production
How to deploy PHP projects with docker
The How and Why of Windows containers
Docker All The Things - ASP.NET 4.x and Windows Server Containers
Deploying Windows Containers on Windows Server 2016
Docker orchestration
Docker up and running
Exploring Docker Security
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker for Developers - Sunshine PHP
Real World Experience of Running Docker in Development and Production
From Docker to Production - SunshinePHP 2017
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...
Docker Networking Tip - Macvlan driver
Build service with_docker_in_90mins
Ad

Viewers also liked (20)

PPTX
Docker - Demo on PHP Application deployment
PDF
Running php on nginx
PDF
From LAMP to LNNP
PDF
Word press on conoha このべん #3
PDF
mod_php vs. FastCGI 原理与比较
PDF
Nginx + PHP
PPTX
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
PPTX
High performance PHP: Scaling and getting the most out of your infrastructure
PPTX
Techtalk2015 MOD_PHP vs PHP-FPM
PPTX
PHP7実環境ベンチ2016春
PDF
PHP Files: An Introduction
PPTX
第2回勉強会資料 柏木
PDF
mod_php vs FastCGI vs FPM vs CLI
PDF
Nginx pres
PDF
PHP-FPMとuWSGI——mod_php以外の選択肢を探る
PDF
Ultrafast WordPress Virtual Word camp2015
PDF
realpathキャッシュと OPcacheの面倒すぎる関係
PPTX
Php development with Docker
PDF
Docker & PHP - Practical use case
PPT
NTR Lab - bespoke software development in Russia
Docker - Demo on PHP Application deployment
Running php on nginx
From LAMP to LNNP
Word press on conoha このべん #3
mod_php vs. FastCGI 原理与比较
Nginx + PHP
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
High performance PHP: Scaling and getting the most out of your infrastructure
Techtalk2015 MOD_PHP vs PHP-FPM
PHP7実環境ベンチ2016春
PHP Files: An Introduction
第2回勉強会資料 柏木
mod_php vs FastCGI vs FPM vs CLI
Nginx pres
PHP-FPMとuWSGI——mod_php以外の選択肢を探る
Ultrafast WordPress Virtual Word camp2015
realpathキャッシュと OPcacheの面倒すぎる関係
Php development with Docker
Docker & PHP - Practical use case
NTR Lab - bespoke software development in Russia
Ad

Similar to PHP development with Docker (20)

PDF
How Reconnix Is Using Docker
ODP
Why Docker? Dayton PHP, April 2017
PDF
DevOPS training - Day 1/2
ODP
Docker for PHP Developers - Madison PHP 2017
PPT
2 Linux Container and Docker
PDF
Advanced Docker Developer Workflows on MacOS X and Windows
PDF
OSCON: Advanced Docker developer workflows on Mac OS and Windows
PDF
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
PPTX
A Survey of Container Security in 2016: A Security Update on Container Platforms
PPT
Develop with linux containers and docker
PDF
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
PPT
Linux containers and docker
PPTX
Docker Mentorweek beginner workshop notes
PPTX
Docker for PHP Developers - ZendCon 2016
ODP
Docker for PHP Developers - php[world] 2017
PPTX
WordPress Development Environments
PDF
Docker Containers - everything about docker Containers
PPTX
Docker New York Meetup May 2015 - The Docker Orchestration Ecosystem on Azure
PPTX
Docker Seattle Meetup April 2015 - The Docker Orchestration Ecosystem on Azure
PPTX
Docker DANS workshop
 
How Reconnix Is Using Docker
Why Docker? Dayton PHP, April 2017
DevOPS training - Day 1/2
Docker for PHP Developers - Madison PHP 2017
2 Linux Container and Docker
Advanced Docker Developer Workflows on MacOS X and Windows
OSCON: Advanced Docker developer workflows on Mac OS and Windows
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
A Survey of Container Security in 2016: A Security Update on Container Platforms
Develop with linux containers and docker
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
Linux containers and docker
Docker Mentorweek beginner workshop notes
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - php[world] 2017
WordPress Development Environments
Docker Containers - everything about docker Containers
Docker New York Meetup May 2015 - The Docker Orchestration Ecosystem on Azure
Docker Seattle Meetup April 2015 - The Docker Orchestration Ecosystem on Azure
Docker DANS workshop
 

Recently uploaded (20)

PPTX
2025-08-03 Joseph 01 (shared slides).pptx
PPTX
What is Clause, definition and structure
PPTX
Emphasizing It's Not The End 08 06 2025.pptx
PDF
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
Introduction to Effective Communication.pptx
PPTX
IBA DISTRICT PIR PRESENTATION.POWERPOINT
PPTX
ppt flame guard FLAME GUARD PRESENTATION.pptx
PPTX
Postmodernism notes for literature students
PPTX
business communication final draftt.pptx
PPTX
Caption Text about Social Media Post in Internet
PPTX
Understanding-Communication-Berlos-S-M-C-R-Model.pptx
PPTX
Assam' Vibrant Bihu Festival Bihu presentation.pptx
PPTX
Called To More (Final I Think) 08 03 2025.pptx
PDF
Enhancing Bambara Groundnut Production Through Improved Agronomic Practices
PPTX
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
PPTX
Learning-Plan-5-Policies-and-Practices.pptx
PPTX
worship songs, in any order, compilation
PPTX
DARKWEB Deepweb what to do or not ?.pptx
PDF
Swiggy’s Playbook: UX, Logistics & Monetization
2025-08-03 Joseph 01 (shared slides).pptx
What is Clause, definition and structure
Emphasizing It's Not The End 08 06 2025.pptx
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
Instagram's Product Secrets Unveiled with this PPT
Introduction to Effective Communication.pptx
IBA DISTRICT PIR PRESENTATION.POWERPOINT
ppt flame guard FLAME GUARD PRESENTATION.pptx
Postmodernism notes for literature students
business communication final draftt.pptx
Caption Text about Social Media Post in Internet
Understanding-Communication-Berlos-S-M-C-R-Model.pptx
Assam' Vibrant Bihu Festival Bihu presentation.pptx
Called To More (Final I Think) 08 03 2025.pptx
Enhancing Bambara Groundnut Production Through Improved Agronomic Practices
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
Learning-Plan-5-Policies-and-Practices.pptx
worship songs, in any order, compilation
DARKWEB Deepweb what to do or not ?.pptx
Swiggy’s Playbook: UX, Logistics & Monetization

PHP development with Docker

  • 1. PHP development with Docker Introduction to PHP development using Docker containers March 23rd, 2016 - Yosh de Vos
  • 3. Why Docker? • Play with new technology • Performance issues with Vagrant on Windows • Runs native on Linux • Why not?
  • 4. The setup Software • Docker Engine • Docker Machine • Docker Compose Stacks • Apache • Nginx
  • 5. The Apache stack Apache + PHP: custom build image with Apache, mod_php and SSH access Mysql: official Mysql or Mariadb image listening on port 3306 using volumes from data container Memcached: official image with memory limitation listening on port 11211 Mysql Apache-PHP Memcached Mysql Data
  • 6. The Nginx stack Nginx: official Docker image listening on port 80 and using fastcgi for PHP-FPM Mysql: official Mysql or Mariadb image listening on port 3306 using volumes from data container Memcached: official image with memory limitation listening on port 11211 PHP-FPM: custom build image with PHP-FPM and SSH access Mysql Nginx PHP-FPM Memcached Mysql Data
  • 7. The PHP image Custom build image based on phusion/baseimage: • Ubuntu 14.04 LTS • Easy to use init system • Syslog and logrotate configured correctly • Crond • Ondrej Sury PPA repository Running services: • Postfix • Syslogd • Crond • PHP-FPM or Apache Different images for: • PHP 5.5, 5.6 or 7.0 • PHP-FPM or Apache with mod_php • With or without development tools
  • 8. The PHP development image A layer on top of the PHP image to add functionality for development environment like: • SSH server • Xdebug • Custom entrypoint.sh to create user on first boot • Various development tools Development tools: • Phing • Phpcs • Phpmd • Phpunit • Bower • Grunt • Gulp • Npm
  • 9. Container access • Using SSH to access the container using agent forwarding • The same username and userid as the host OS is available inside the container to preserve ownership and permissions • Optimized Bash prompt and installed all required tools for development • All sudo rights available when needed Entrypoint.sh A small script set as entrypoint that creates a new user on first boot of the container using environment variables. This makes sure that the user on the host OS is available inside the container with the same username and userid.
  • 10. Linked volume The /var/www volume is shared with the host OS. ● Directly linked from the host OS ● No need for continuously syncing during development ● State between container lifecycles remain • /var/www/ • .ssh/ • sites/ • my-application/ • web/ • .bash_history • .bashrc • .gitconfig
  • 11. Container linking Using container linking to enable DNS aliases inside containers. In this way the DNS alias can used inside your app configuration. ● The mysql and memcached containers are linked to the PHP container and are available as hostname “mysql” and “memcached”. ● The PHP container is linked to Nginx and is available as hostname “php”. # parameters.yml parameters: database_host: mysql memcached_host: memcached # nginx.conf server { location ~ .php(/|$) { fastcgi_pass php:9000; } }
  • 12. Virtualhost configuration Configuration for Nginx/Apache is stored outside the container so it easy to add virtualhosts for each application. The default virtualhost resolves all domain names to document root: ./www/sites/<domain>/web # apache.conf <Virtualhost *:80> ServerName sites.dev DirectoryIndex index.html index.php app.php VirtualDocumentRoot /var/www/sites/%1/web </Virtualhost> # nginx.conf server { server_name ~^(?<domain>.+).dev$; root /var/www/sites/$domain/web; }
  • 13. DNS aliases Solutions: • Use static ip address • Use dnsmasq for wildcard subdomains like *.dev • Add each hostname to /etc/hosts # /etc/dnsmasq.conf address=/dev/192.168.99.100 # /etc/hosts 192.168.99.100 application.dev
  • 14. docker-compose.yml nginx mysql_data http -> 80, https -> 443 ssh -> 2022 mysql -> 3306 Docker Machine php-fpm <application>.dev mysql memcached The setup
  • 15. Resources PHP docker images https://github.com/yoshz/docker-php https://hub.docker.com/u/yoshz/ Bunch of dockerfiles to can build different types of PHP containers. - PHP 5.5, 5.6 or 7.0 - Apache + mod_php or Nginx + php-fpm - Separate images with development tools integrated PHP Development Stack https://github.com/yoshz/phpdevstack Bunch of scripts and docker-compose files to quickly start your own development stack with PHP.

Editor's Notes

  • #16: Use this setup to quickly start or build your own.