Dockerizing PHP 7 with Zend Server

      24 Comments on Dockerizing PHP 7 with Zend Server

PHP 7 is out, and to help you join the revolution we’ve updated our official PHP/Zend Server container on Docker to allow you to set up the latest PHP 7 stack (GA) using the Zend Server PHP 7 technology preview in just a few minutes.

This tech preview gives you the safest and most comprehensive PHP 7 stack out there with the largest amount of tested extensions, and of course you’ll also get access to all the rest of Zend Server’s development, deployment and monitoring tools (more about the tech preview here).

Launching the container

Your first step is to install Docker.

Once you’ve got Docker correctly installed and running, all you have to do is execute the docker ‘run’ command with the official PHP/Zend Server container name:

Docker will then begin to download and initialize the pre-installed Zend Server instance, and will begin the installation process. 

Once initialized, the container will output all the information required to launch Zend Server, including an automatically generated admin password for accessing the Zend Server UI which you can of course change later on.

All you have to do now is open your browser, enter the machine’s IP together with the port the Zend Server UI listens on (10081) and use the provided password to access the Zend Server UI:

zend_Server_ui

Launching a different PHP/Zend Server

You can set up any of the following PHP/Zend Server versions by changing the version variable in the ‘run’ command:

  • 8.5-php5.5
  • 8.5-php5.6
  • 7.0-php5.4

So for example, if you want to set up Zend Server 8.5 with PHP 5.6, use:

Pulling applications

Application files can be automatically pulled from a Git repository using the GIT_URL environment variable in the ‘run’ command. The files are copied to the container’s ‘/var/www/html’ folder and defined in Zend Server as the default app.

By the way, an example ‘index.html’ file is included by default in the container.

Other environment variables

There are a number of additional variables you can sue in the run command using the ‘e’ switch.

  • To specify a pre-defined admin password for accessing the Zend Server UI, use:
    ZS_ADMIN_PASSWORD
  • To specify a pre-purchased license use the following env vars:
    • ZEND_LICENSE_KEY
    • ZEND_LICENSE_ORDER

For creating a cluster, you need to use all of the following variables:

  • MYSQL_HOSTNAME – IP or hostname of a MySQL database
  • MYSQL_PORT – MySQL listening port
  • MYSQL_USERNAME – Database username
  • MYSQL_PASSWORD – Database password
  • MYSQL_DBNAME – Name of the database Zend Server will use for the cluster (created automatically if it does not exist).

Usage example:

So in just a few minutes you’ve got your PHP 7 environment up and running. What next? Start adding some files and code and use Z-Ray to identify any issues.  The image packs an Ubuntu instance with Apache, so add your files to the root directory at: /var/www/html.

More details on the container here.

Enjoy!