Shiphp The PHP Developer's Guide to Docker

Latest Blog Posts

Running a SlimPHP Application in Docker Containers

Using Docker to run a simple PHP web application is one thing, but how hard is it to install and run a small framework like SlimPHP in Docker containers? Let’s try it out! 1. Installing SlimPHP with Docker and Composer First we need to install SlimPHP into a new directory. Their documented installation instructions assume that you’ve got Com... Read more

Introduction to Writing Unit Tests in PHP with PHPUnit and Docker

Testing your code is a great way to improve quality and minimize bugs due to regression. PHP has a couple frameworks available for unit testing, but the most popular by far is PHPUnit. Because unit tests are going to be run on a variety of environments, running tests within Docker containers can make tests faster and more portable. This tutori... Read more

Switch Statements in PHP

While the switch statement isn’t as popular as conditional operators like if and elseif in PHP, it can still be useful when evaluating a number of possible outcomes. Using a switch statement is pretty simple, so let’s look at an example: <?php $var = rand(0,2); switch($var) { case 1: echo "The magic number is one."; bre... Read more

Running a PHP Application with Postgres and Docker

MySQL may be the standard choice in relational databases for PHP developers, but Postgres is a great option as well. The setup is very similar, and running Postgres and PHP within Docker containers is just as easy. 1. Create a PHP Script that Connects to Postgres Let’s start by writing a simple PHP script that will connect to a Postgresql da... Read more

Introduction to Interfaces and Abstract Classes

Object oriented languages like PHP have many tools for layering objects. Among PHP’s tools are interfaces and abstract classes which can be used in similar ways. I think many new developers tend to get confused and misuse them, so I’m hoping a little tutorial here will help. What is an Interface? An object interface in PHP is like a class te... Read more