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

Rob Allen:
Using img2lambda to publish your Serverless PHP layer
Feb 25, 2019 @ 17:45:24

Rob Allen has published another post covering the use of serverless technology and PHP to run your applications. In this new post he shows how to use img2lambda to publish your Serverless PHP layer out to an AWS Lambda instance.

[The] img2lambda tool will take the layers of a Docker container and convert them to AWS layers for use in Lambda.

I poked around with Clare’s example and updated my lambda-php project in order to understand how it works. I also rewrote my runtime’s bootstrap to make it clearer.

The clever thing from my point of view is that you can build your PHP runtime layer locally using Docker and then publish the layers to AWS for use in your Lambda functions. This means you can now use the layer in different projects and have them all reference the same PHP runtime.

He digs deeper into the tool, looking at the "magic" happening under the covers using Docker. He provides an example of the Dockerfile it creates and walks through what it does. He then shows how to create the layer in AWS and use a serverless framework and a PHP runtime to execute the "hello world" application. He wraps up the post showing how to test it locally, building from the Dockerfile and using a docker run on the result with simple user input.

tagged: tutorial img2lambda docker package serverless layer aws

Link: https://akrabat.com/using-img2lambda-to-publish-your-serverless-php-layer/

Colin O'Dell:
How To Install PHP 7.3
Dec 13, 2018 @ 19:51:28

Following the recent release of PHP 7.3, Colin O'Dell has put together a guide for those wanting to install it, walking you through the setup for several popular operating systems.

PHP 7.3 has been released, bringing some great new features to the language such as trailing commas in function calls, throwing errors when JSON parsing fails, array_key_first() / array_key_last() functions, and much more!

In the post he includes instructions for:

  • Ubuntu
  • Debian
  • CentOS / RHEL & Fedora
  • Mac OS X
  • Windows

He even includes instructions for two other tool-based installations: phpbrew and Docker.

tagged: install php73 tutorial linux windows osx phpbrew docker

Link: https://www.colinodell.com/blog/201812/how-install-php-73

Laravel News:
Speeding Up PHP with OPcache in Docker
Dec 05, 2018 @ 16:16:51

The Laravel News site has a new tutorial posted showing how to speed up your PHP execution when developing with Docker by making use of the OPCache functionality.

If you’re on Docker for Mac or Docker for Windows, you might see some noticeable slowness and time to the first byte (TTFB) depending on your application’s setup. One of the most important things you can do to improve performance is enabling the OPCache module (regardless of the development environment). There are other things like volume caching (if possible), but OPcache is a win that you want in any environment you’re running PHP applications.

The tutorial starts by sharing a basic Opcache configuration, setting values for timestamp validation, memory consumption, and fast shutdown. These values are static and not very flexible so they change things up by making them able to be set as a part of the Docker build process. The post includes the changes you'll need to make to your Docker configuration to make this setup work in two ways: either copying the file in on build or making use of environment variables to set the configuration options at runtime.

tagged: opcache docker tutorial speed performance configuration

Link: https://laravel-news.com/php-opcache-docker

Matthew Weier O'Phinney:
Building a usable ext-tidy for Alpine-based PHP Docker images
Nov 02, 2018 @ 15:22:29

On his site Matthew Weier O'Phinney has a new post sharing a method he's worked up for creating a Docker image for PHP from an Alpine image that included the "tidy" PHP extension.

I've been working on building PHP Docker images for the purposes of testing, as well as to potentially provide images containing the Swoole extension. [...] This week, I decided to see if I could build Alpine-based images, as they can greatly reduce the final image size. And I ran into a problem.

One of the test-beds I use builds RSS and Atom feeds using zend-feed. When I tried one of these images, I started getting failures. [...] During an initial search, this appeared to be a problem due to libxml2 versions. [...] I realized [after debugging] that the problem was the content — which was being massaged via the tidy extension before being passed to DOMDocument::loadXML(). For some reason, the content generated was not valid XML!

In order to solve this issue (after spending a good deal of time debugging it) he went on a hunt to figure out the previous version. Once he found that it was just a few simple lines in his Dockerfile to include the right version and install it using the apk package manager (example of this is included).

tagged: docker tidy xml issue debugging tutorial

Link: https://mwop.net/blog/2018-11-01-alpine-php-ext-tidy.html

Matt Glaman:
Running Drupal's PHPUnit test suites on DDEV
Oct 15, 2018 @ 14:36:29

Matt Glaman has a new post to his site where he walks you through the setup and execution of Drupal's unit tests in the DDEV platform (a Docker-based project that makes it easy to get an environment up quickly).

DDEV is a local development stack built on top of Docker. It gives you all of your environment needs without messy configured on your host machine, without needing to know Docker or configure your own containers. Which is great, and makes life easier. Instead of just using DDEV to develop your site or application locally, why not also run your tests within it?

I have had quite a few people ask me how I configure my setup for testing with Drupal’s PHPUnit test suites. [...] All of these are the same reasons for using a virtual machine or containerized local development stack. So, it is fitting we run our tests within these local stacks as well!

In this article, part one of three, he assumes you already have a DDEV environment up and running with a Drupal application running inside (there's a guide here). With that in place, he shows how to configure PHPUnit via the phpunit.xml file, changing the "SIMPLETEST_*" values for the localhost and local DB connections. He shows how to run the tests by SSHing into the web Docker container and pointing PHPUnit at the configuration file. The end result should look something like this in a terminal.

tagged: tutorial series part1 drupal test unittest ddev docker testsuite

Link: https://glamanate.com/blog/running-drupals-phpunit-test-suites-ddev

Titouan Galopin:
How to build a scalable Symfony application on Kubernetes
Aug 20, 2018 @ 16:23:17

Titouan Galopin has written up a post to his Medium.com site showing a method he's created to set up a scalable Symfony application on Kubernetes, a container management system.

Modern web applications are complex. The expectations of your users regarding your application are constantly increasing: nowadays, an application needs to be fast, convenient, easy to use and beautiful.

Meeting these demands can become another difficulty in the path towards creating a great product. [...] To ease this new difficulty and decrease the time spent on creating and maintaining these expected features, a modern application usually leverages many different components, from content delivery networks (CDN) to full text search services and load balancers.

[...] When you use such infrastructure, being able to interact easily with all its components from within your application is critical. This is where Kubernetes and Symfony are working together to help you achieve incredible results, extremely quickly.

The post starts by introducing some of the basics around Kubernetes for those not familiar with it and the platform they'll be using: Google Cloud Platform. He then talks some about using Symfony in a Kubernetes environment and the role that scalability plays in how you write your code. He makes a few suggestions to make it easier including:

  • Use Flysystem to store your application files in the managed file store
  • Configure Doctrine to use the provided SQL service
  • Use Redis for your cache and your sessions

There's a description for each item in the list, configuration examples where they'd help illustrate, and some links out to other resources for more information.

tagged: symfony tutorial kubernetes scaleable application docker container

Link: https://medium.com/@galopintitouan/how-to-build-a-scalable-symfony-application-on-kubernetes-30f23bf304e

Laravel News:
Creating Multi-Stage Docker Builds for Laravel
Aug 17, 2018 @ 15:24:24

On the Laravel News site they've posted a tutorial showing you how to create multi-stage Docker builds for Laravel applications with a feature included in Docker 17.05.

Starting in Docker version 17.05 multi-stage builds are available to help you optimize Dockerfiles. Using multi-stage builds is a clean way to set up a Docker build pipeline that simplifies the requirements you need on your CI/build server to create a Docker image for your app.

If you’re not familiar with multi-stage builds, no worries! Let me summarize by saying that before multi-stage builds if you wanted to install composer dependencies and frontend dependencies during a docker build of your app, your Docker image would need to have the necessary dependencies such as Node.js installed and Composer PHP.

[...] By using multi-stage builds, you no longer need to install those dependencies or cram them all into your Dockerfile, thus bloating your final image size!

The tutorial then walks you through the multi-stage build approach using a new "demo" Laravel application as the base. In their example they show how to create the application, add it to a Git repository and set up the environment configurations. Next it includes the Dockerfiles required to create the different stages: installing Composer dependencies, installing Node dependencies and copying the application files and artifacts in to place.

tagged: tutorial laravel multistage docker build dependency

Link: https://laravel-news.com/multi-stage-docker-builds-for-laravel

Pascal Landau:
Setting up PhpStorm with Xdebug for local development on Docker
Aug 08, 2018 @ 17:44:30

Following up from his previous post about setting up Docker running PHP-FPM and Nginx on Windows 10, Pascal Landau has published the second part of the series taking things a step further and introducing (and integrating) PhpStorm and Xdebug for local development debugging.

In the second part of this tutorial series on developing PHP on Docker we're taking a good hard look at PhpStorm, Xdebug and how to run and debug scripts from within PhpStorm on Docker.

[...] The setup that I am going to use is for demonstration purposes only! I do not recommend that you use it "as is" as your development setup. [...] There will be a another part of this series that will deal with all of those (and some more common) problems and aims at providing a consistent development environment for all developers in a team (regardless of the OS they are using).

He then walks through the process from setup through actual script debugging:

  • setting up the Docker containers/configuration
  • allowing the PHP container to connect over port 2375
  • running a PHP script on this container
  • building a "workspace" container for Xdebug

For each step he provides the configuration changes needed, commands and screenshots of the settings panels to ensure its easy to follow along.

tagged: docker phpfpm nginx debugging phpstorm xdebug tutorial series part2

Link: https://www.pascallandau.com/blog/setup-phpstorm-with-xdebug-on-docker/

Websec.io:
Securing Credentials for PHP with Docker
Jul 24, 2018 @ 16:31:59

On the Websec.io site a new tutorial has been posted (a sort of continuation from this previous article) showing how to keep secrets safe in a PHP and Docker environment without too much overhead.

In a previous post I covered one method you can use to secure the credentials in your PHP application. In that article I provided an example specific to the use of Apache and its envvars handling to read in values and pass them along to the waiting PHP process as $_ENV variables. This in combination with the psecio/secure_dotenv library allowed you to pass along an encryption key that could be used to decrypt values from the application's .env file.

While this works for a flat Apache and PHP environment, the world has moved beyond that basic setup and has moved to using another popular environment building tool: Docker. [...] So, if we move forward with current technology, we need a way to secure our credentials in a Docker-based environment that makes use of PHP-FPM and Nginx. Fortunately there's a relatively simple way to handle this with just a few configuration changes.

The tutorial starts with an overview of what technologies are involved in the environment (Docker, PHP-FPM, Nginx and Vault) and some of the options for storing secrets with Docker. It then gets into the configuration files needed to create the environment: a Docker Composer configuration, the Nginx server definition, the PHP-FPM settings and the .env file that contains the secrets. Using these pieces and some special configuration directives, the secrets are injected into Docker when the containers are built and storing them in-memory rather that on disk.

tagged: tutorial docker secure credentials environment variable nginx phpfpm

Link: https://websec.io/2018/07/22/Docker-Secure-Credentials.html

Pascal Landau:
Setting up PHP, PHP-FPM and NGINX for local development on Docker (for Windows 10)
Jul 09, 2018 @ 18:19:11

On his site Pascal Landau has posted a complete guide to setting up a Docker-based PHP environment on Windows 10 using Nginx and PHP-FPM.

You probably heard from the new kid around the block called "Docker"? You are a PHP developer and would like to get into that, but you didn't have the time to look into it, yet? Then this tutorial is for you!

[...] This is the first part of a (probably) multi-part series on Docker. The next part will explain how to set up PHP in Docker containers in order to work nicely with PHPStorm when using XDebug.

He starts with a brief overview of why he chose to use Docker and the transition from Vagrant. He then breaks up the tutorial into several different sections, one for each area of the environment:

  • setting up Docker
  • creating the PHP CLI container
  • building the web container (PHP-FPM and Nginx)

He "brings it all together", sharing a docker-compose configuration file that sets up all of the services and configurations in one shot. The tutorial comes complete with screenshots and all command line calls to get your environment up and running quickly.

tagged: nginx docker phpfpm windows10 tutorial setup configure

Link: https://www.pascallandau.com/blog/php-php-fpm-and-nginx-on-docker-in-windows-10/


Trending Topics: