How Both Docker and PHP Works Simultaneously?
Docker and PHP: Working with Both Simultaneously
PHP/Opensource

Docker and PHP: Working with Both Simultaneously

We all know that PHP is widely used for developing web applications as well as for various eCommerce platforms. Here, we will understand how docker can be used with PHP.

First of all, let’s understand how Docker can be installed on Windows? Creating a machine, get the image from Docker hub and the most important one how PHP script can be run using Dockerfile.

However, before we proceed ahead; you might have some questions as to what Docker actually is? So, let’s take a look at it and understand it before working with the same:

Docker and PHP

What is Docker?

It is an open source project which automatically deploys all applications inside the software containers thus offering an additional layer of abstraction and automation of operating system level virtualization on Linux.

It is one of the tools that can have a good package which includes an application along with its dependencies in a virtual container which can be used on any Linux Server.

Installing Docker on Windows:

  • First of all, download the Docker Toolbox.
  • Now run the .exe file and go on with the suggested steps.
  • At certain point of time; you will have to select among the given docker components that you wish to install. Here, you can also choose the default ones.

Once the installation is successful then you will have three shortcuts on your desktop.

Then, when you will try to install Docker Quick Start terminal then it will try to install default machine. However, at this point of time; you may receive an error regarding virtualization disabled.

In order to enable it; just restart the Docker Quick Start Terminal and then you will be easily able to install the Docker machine and then Docker VirtualBox Manager will open.

This terminal will have a special environment instead of the same Windows Command Prompt.

Developing a new machine with Windows via Command Prompt:

Once you install Docker on Windows then you may wish to create a new Docker machine as per the steps given below:

  1. To create a new Docker machine with Windows Command Prompt then you must set the ssh.exe in the PATH environment variable.

    Command: set PATH=%PATH%; C:\Program Files\Git\bin

  2. Now, the same virtualbox driver can be used to create a new machine known as php-machine.

    Command: docker-machine create --drivervirtualbox php-machine

  3. Now, the Docker will be connected to PHP machine.
  4. Here, you will get new command.

    The existing Docker machines can be listed with this command.
    Command: docker-machine ls

    With this command; the Docker machine can be easily activated and deactivated.

How base docker image can be used to run applications on Apache?

Once the docker machine is created, the Apache version with less configurations can be installed to run PHP. Here, the configuration must be installed in the docker machine known as PHP machine.

Such applications can be installed via images in a Docker. Now, here you might think what is a Docker image?

Docker image: It is a type of document that contains all the instructions any user can call on the command line to develop an image. Docker files are generally written for developing an Apache + PHP docker image. It is advisable to visit Docker Hub before creating one.

Take Away:

Well, again a question “What is Docker Hub?” [The blog of 13th April 2016 is tobe hyperlinked here. The answer to this question will be available in the next part of “Docker with PHP”. Till then, follow these commands and try to install a Docker machine.

For more such amazing news and updates about PHP; stay tuned to Softqube Technologies that offers cost effective PHP Development in India.

Hari Patel

Hari Patel

I am the Managing Director of Softqube Technologies Pvt. Ltd., a modern-day digital transformation, design and development service provider. We provide services to businesses of all verticals across the globe. I believe and live by a mission that I help more entrepreneurs to build, launch and grow profitable businesses.