Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

James Cowie:
All hail Xdebug and lets let var dump die
Jan 12, 2017 @ 12:58:23

In a recent post to his site James Cowie sings the praises of Xdebug for debugging and says that "var_dump must die" as a method for debugging in your application development flow.

How many times have you been working in Magento or any other php application and hit an error, exception or something not quite right? For me a lot. I’ve been that developer that debugs by fire and throws echo var_dumps and dies around like a western gunslinger. It’s easy, provides quick feedback cycles but lets be honest its lazy, in efficient, rarely provides all of the data you need to solve the problem on the first try and its not something you want to boast about by the coffee machine.

[...] So whats the “better” way of debugging a application? Well welcome Xdebug + PHPStorm. Imagine inside of the IDE we can set a breakpoint, a fancy die and reload our web page. Magically the IDE has stopped execution and we can see the state of the application at that exact path. We can see the variables and we can step through the code and see exactly what class and method is called next and so on and so forth.

While his instructions are specific to PHPStorm, most major IDEs will have a similar setup process with their own tweaks. In his case, though, he has one more layer of complexity - the PHP is executing inside a Docker container. He walks you through the process he followed to get the flow from container to local IDE set up. He wraps up the post with an example of debugging a script and what the results look like inside of PHPStorm (including a screencast).

tagged: xdebug vardump phpstorm docker container tutorial

Link: http://jamescowie.me/blog/2016/12/all-hail-xdebug-and-lets-let-var-dump-die/

Mattias Noback:
Containerizing a static website with Docker, part III
Jan 09, 2017 @ 11:48:46

Matthias Noback has posted the third part of his "containerizing a static website with Docker" service, continuing on from his previous two posts to look at deploying the environment he's created.

In the previous posts we looked at creating a build container, and after that we created a blog container, serving our generated static website.

It's quite surprising to me how simple the current setup is — admittedly, it's a simple application too. It takes about 50 lines of configuration to get everything up and running.

The idea of the blog container, which has nginx as its main process, is to deploy it to a production server whenever we feel like it, in just "one click". There should be no need to configure a server to host our website, and it should not be necessary to build the application on the server too. This is in fact the promise, and the true power of Docker.

He then gets into the two remaining steps in the process resulting in the deployment of the simple application: pushing to Docker Hub and deploying out to a DigitalOcean server. He includes all of the commands and configuration you'll need to get the process set up and work with the remote machine.

tagged: docker series container part3 deploy dockerhub digitalocean

Link: https://php-and-symfony.matthiasnoback.nl/2017/01/containerizing-a-static-website-with-docker-part-iii/

Matthias Noback:
Containerizing a static website with Docker (Part 1 & 2)
Jan 06, 2017 @ 09:07:39

Matthias Noback has started a series to his site showing you how to use Docker along with a static site, like one generated with Sculpin to create a complete environment. So far he's posted part one and part two.

Recently a former colleague of mine, Lucas van Lierop, showed me his new website, which he created using Spress. Lucas took two bold moves: he started freelancing, and he open-sourced his website code. This to me was very inspiring. I've been getting up to speed with Docker recently and am planning to do a lot more with it over the coming months, and being able to take a look at the source code of up-to-date projects that use Docker is certainly invaluable.

Taking lots of inspiration from Lucas's codebase, and after several hours of fiddling with configuration files, I can now guide you through the steps it took to containerize my blog (which is the site you're visiting now) and deploy a single container to a production server.

In part one he talks about how his blog is currently set up - based on a "large set of Markdown files" - and using Sculpin to generate the resulting site. He walks through the configuration of the Sculpin installation and how to configure and build the initial container, the "build" container.

In part two he continues the process but creates a "blog" container this time. This container runs the web server itself (nginx) configured as required by the Sculpin formatting.

tagged: container docker static website tutorial series part1 part2

Link: http://php-and-symfony.matthiasnoback.nl/categories/Docker/

Gonzalo Ayuso:
Playing with Docker, Silex, Python, Node and WebSockets
Jan 03, 2017 @ 09:47:19

Gonzalo Ayuso has a new post to his site sharing some of the results of his work combining Docker, Silex, Python, Node and WebSockets, discovering how to create a complete platform with these tools.

I’m learning Docker. In this post I want to share a little experiment that I have done. I know the code looks like over-engineering but it’s just an excuse to build something with docker and containers. Let me explain it a little bit.

The idea is build a Time clock in the browser. [...] Yes I know. We can do it only with js, css and html but we want to hack a little bit more. The idea is to create: a Silex/PHP frontend, a WebSocket server with socket.io/node [and a] Python script to obtain the current time.

He then starts in on the code, first creating the WebSocket server in Node then the Python script that makes an internal request to get the time and return it. Then the Silex route is created to serve up the template for the page and the code it uses to connect back to the websocket. The post ends with the Docker configuration he used to create the Docker environment all of this lives in.

tagged: docker silex python node websockets tutorial environment

Link: https://gonzalo123.com/2017/01/02/playing-with-docker-silex-python-node-and-websockets/

Master Zend Framework:
How to Build a Docker Test Environment
Sep 28, 2016 @ 11:20:40

The Master Zend Framework site continues their series covering the creation of a Docker-based testing environment in this second part highlighting the addition of testing support.

In the first part in this series on developing web applications using Docker, we saw how to create a local development environment using Docker; one ideally suited to creating Zend Expressive (or any other kind of PHP-based web application). But, what we didn’t cover was how to handle testing in a Docker-based environment.

[...] How do you run tests when working with Docker containers? After a bit of searching, I found that it’s not that difficult. But you have to use the right combination of commands.

Since unit tests can be run locally if need be (they shouldn't need any resources from the service if they're true unit tests) he focuses on acceptance testing. For his examples he uses the Codeception testing tool. He walks you through the setup of some simple tests based on the "home" page functionality of the Zend Expressive skeleton application. With that in place, he shows the updates that will need to be made to execute the tests from outside the instance via a "docker exec" call. The post finishes with a look at adding two other tools to the mix as well: Make and Phing.

tagged: docker test environment series part2 testing acceptance codeception make phing

Link: http://www.masterzendframework.com/how-to-build-a-docker-test-environment/

Master Zend Framework:
How To Build a Local Development Environment Using Docker
Sep 02, 2016 @ 11:57:05

The Master Zend Framework site has posted a tutorial helping you create a Docker-based development environment complete with PHP, MySQL and Apache working happily together.

Why in this modern day and age is setting up a development environment still such a complicated process? [...] Why is it still so hard to get one setup that works, that does what you need, and that matches the deployment environment’s of testing, staging, production and so on?

[...] By now our development environments have grown quite sophisticated. But the overhead of both building and maintaining them has increased significantly also. Wouldn’t it be easy if we could set them up, but with only a small investment of time and effort? I think you know where I might be heading with this. You can. Yes, that’s right, you can. Ever heard of Docker?

He then starts in on introducing Docker (for those not already familiar) and how it differs from a VirtualBox/Vagrant setup that's already become quite popular. He talks about "containers" and the role they play as well as an overview of the environment he's going to show you how to create. He then helps you get Docker installed, explains how the containers will work together and provides the Docker YAML configuration for each of them. The docker-compose command is then used to bring the environment up, downloading the containers as needed. The final result of his setup is a set of containers running together to serve up a Zend Framework Skeleton Application.

tagged: docker local development environment tutorial introduction mysql apache zendframework skeleton

Link: http://www.masterzendframework.com/docker-development-environment/

Zend Developer Zone:
Testing your project with PHP 7.1
Aug 23, 2016 @ 12:20:12

On the Zend Developer Zone author Cal Evans has written up a post showing you how to test your application with PHP 7.1, the upcoming minor release version for the PHP 7.x series.

Both PHP 7.0 and the upcoming PHP 7.1 release are fairly benign releases. They do not break backwards compatibility except in a few edge cases. If you’ve not yet moved to PHP 7.0, check out our posts tagged php7 for details on what might trip you up there.

Regardless of what version you are moving to, 7.0 or 7.1, you are going to want to test your application before you make the move in production. Sometimes that is difficult though you need a server properly configured, you need someone to manage it, most importantly, you need unit tests. While I can’t help you with that last one – other than point you to @grmpyprogrammer who will publicly abuse you until you write them – I can help you with the “where to test” problem.

Cal shows how to make use of Docker containers to easily test your application in a more self-contained environment and make it simpler to swap out the PHP versions in your platform. He walks you through the steps you'll need to follow to get the environment set up, pull down required components, install and compile PHP and, finally, install Composer globally. Once set up, he shows how to log in, clone your project and execute its test suite. He finishes the post with a few comments about this being a "sandbox", not a CI environment and how it is "future proof" for later versions of PHP too (as it doesn't lock it down to just PHP 7.1.x).

tagged: testing project php71 docker container tutorial

Link: https://devzone.zend.com/7262/testing-project-php-7-1/

Symfony Finland:
Consider Docker for your Symfony projects
Aug 15, 2016 @ 11:24:35

On the Symfony Finland site there's a post that makes a recommendation for your Symfony framework based projects: give Docker a try to make setup and maintenance simpler.

During the first half of 2016 the web development community has talked about Docker quite a bit. The technology has been around since 2013, but during the last few months it has matured and started being adopted for mainstream web development. Docker is a great fit for Symfony projects too.

[...] Docker takes an approach where it wraps a piece of software into something known as a container. These containers are shipped complete with the application code, a runtime, system tools and libraries. Containers are thus guaranteed to always run the same, but can share files and networking with the host and other containers.

They then talk about how this "containerized" setup can be used to your advantage, making it simpler to get a Symfony application up and running with a few commands. The post then gets into an example setup of a Symfony Docker environment complete with Nginx, Varnish and PHP-FPM installed and linked. There's also setup for MySQL and Redis rounding out the data storage side. A quick "docker-composer up" command and, if all goes as expected, the environment is set up and waiting for your application.

tagged: symfony finland docker project tutorial setup configure

Link: https://www.symfony.fi/entry/consider-docker-for-your-symfony-projects

Testing in Docker (Using Different PHP Versions)
Aug 12, 2016 @ 12:23:58

On the ShippingDocker.com site there's a video (and matching tutorial) posted showing you how to use Docker to test with multiple PHP versions with relatively little difficulty. In this case they're not testing the frontend of the application, they're running its unit tests.

[This is a] quick video on running PHP unit tests against different versions of PHP using Docker. [We'll] cover unit testing with PHP.

They start with an example of using the pywatch tool to do the testing without Docker, automatically executing the tests when something changes. This has the limitation of only being able to use your current, local version of PHP. They then shift over to the Docker side of things and show how to run the same pywatch command inside a container of your choosing, tagging it with the PHP version and making it easy to switch between them in the future.

tagged: docker version unittest different example video screencast tutorial

Link: https://shippingdocker.com/blog/docker-testing/

Chris Tankersley:
My Docker Setup
Jul 29, 2016 @ 11:56:11

Docker has quickly become one of the tools that have helped make difficult environment setup and thing of the past. Chris Tankersley, a PHP developer and devops practitioner, has shared some about his own PHP Docker workflow in a new post to his site.

When it comes to Docker, I use Docker Compose to set up and link all of my containers together. It's rare that I have a single container, though many of my Sculpin-based sites live quite comfortably inside of an nginx container, but even those take advantage of volumes.

For his standard three-tier setup he defines a basic docker-compose.yml configuration file with required services (nginx, PHP server, MySQL and Composer), local volume information and the links between them. With that working he uses another script to set up some PHP extensions and Composer as a service (making it a service provides isolation). He also includes the scripts he's written up to help run a few extra commands and execute the Composer and PHP commands much easier. He wraps the post up talking about how all of this fits into his overall workflow and how it relates to the deployment of the application into other environments.

tagged: setup environment workflow setup docker configuration deployment

Link: http://ctankersley.com/2016/07/27/my-php-docker-workflow/