Automate Marketing Initiatives with Salesforce Marketing Cloud Learn More

How to remove machine dependency for LAMP development using Docker?

Being a developer, sooner or later you have to undergo such machine dependency problems while deployment of code on the server. There are scenarios where you have to work with a team of developers and maybe they use different versions of PHP and MySQL, or if you are working for LAMP environment then WAMP, XAMPP, LAMPP, MAMP installation can be a big pain for developers.

Now, let’s assume you are done with all installation but what will happen if the server environment does not match with your local development environment? I know this is the most undesirable situation for any developer. But, do you know you can get rid of all these hitches and save your development time? There are a number of solutions available in the market. But, here I want to share my personal experience with Docker.

My experience with Docker has been quite good, I have been using Docker for 3 years now. Docker, which initially released 5 years back has filled the gap and offered a consistent development environment to the developers. Before using docker, as a full stack developer, while working on LAMP environment, I always had to switch my PHP, Apache, MySQL settings and versions, when I switched to multiple projects. It was a big pain to repeat the set every time and it ultimately affected my productivity. But, Docker has made things easier and faster.

Let me explain you with an example:

If I want to set up my development environment for PHP 7.2, Mysql mysql:5.7.22 and Nginx server.

I have multiple solutions to setup this environment:

  • First, I can install XAMPP/WAMP/LAMPP, but this environment does not contain Nginx service.
  • Second, I can install everything separately in the local machine, but there are many problems with this process too.
Problem 1.

If your development machine is Windows and deployment server is Ubuntu or vice-versa.

Problem 2.

Development software compatibility installation is a critical time consuming process for the developer.

Problem 3.

Even if you solve both of these problems, you will have to change settings according to your project’s requirements and it will take a long time to execute those changes.

That’s where Docker comes to the rescue, it not only simplifies all these problems but simply removes all machine dependency problems.

How to install Docker?

Using Docker does not require any professional courses or training. If you have a basic understanding of development environment setup, you can easily do it . You just have to install Docker in your machine or on the server and simply let it manage everything right from the development to the deployment. With Docker, you can create any number of virtual machines and keep those into a single container.

You can find a complete Docker installation guide here with this link from where you can select your OS and install. Docker uses the concept of container and images. Now let’s understand what is Docker’s container and images.

Docker Images, Layers and Containers

Docker images are basically the files with the set of instructions, consisting of multiple layers that can be used to incorporate tools, system library and other files required for executable code. When we run an image, it becomes one or multiple instances for the container. The Docker image includes all dependencies of the executable code so that the containers can run independently from one environment to another in a similar OS without any changes. You can have multiple containers for a single image.

  • If you want to see the list of all running Docker containers you have to execute the command
    docker ps-a
  • If you want to see all running images you have to execute the command
    docker images –a

You must have basic knowledge of command execution as Windows operating system uses power shell to execute the commands and Ubuntu and Mac OS use the terminal to execute the commands.

How to set up XAMPP machine using Docker?

Before setting up XAMPP machine, make sure you already have Docker installed in your machine.

Now first create a directory anywhere in your system.

Directory structure (I have created this directory according to my requirements, you can create according to your requirement):

  • mysql (directory)
  • nginx (directory)
  • php (directory)
  • docker-compose.yml file)
  • Dockerfile (file and it does not contain file extension)

What is docker-compose.yml ?

Compose is a tool for defining and running multiple-container Docker applications. With Compose, you can use a YML file to configure your application’s services. Define the services that make up your app in docker-compose.yml, so they can be run together in an isolated environment.

What is Dockerfile?

A Dockerfile is a text document that contains all the commands a user can call on the command line to assemble an image.

Using docker build, users can create an automated build that executes several command-line instructions in succession. Following are the commands that you can use in a Dockerfile.

  • Mysql directory: Put your customized MySQL conf file if you have customized anything.
  • nginx directory: Put your customized nginx conf file if you have customized anything.
  • PHP directory: Put your custom php.ini file if you have customized anything.

Make sure the path of above-mentioned files are currently written in docker-compose.yml

You can navigate here and find the sample files for docker-compose.yml and Dockerfile

How to PHP application using Docker in Laravel?

Let’s explore how we can use Docker container with php 7.2. , MySql 5.* and NGINX server. Change nginx file for laravel public folder. The path for Laravel: root /var/www/public;

Other: root /var/www;

/var/www -> This is a Path of the working directory

Before moving to the next step please make sure you have installed Docker in your machine

Command to check Docker Version-docker –v

Please follow the below mentioned steps and commands to use docker

  • First, you have to clone the project in your specific drive or directory
  • Now Install docker and docker compose in your machine
  • Open power shell
  • Navigate to your project directory, refer step 1.
  • docker-compose up -d
Essential Docker Commands

1. Start all required containers:docker-compose up -d

-d: Run the container in the background

2. Stop all container:docker-compose down

3. Run commands in a specific container:docker-compose exec app nano .env

docker-compose exec – This is a command to execute commands

app – This the name of the container in which we want to run the command

4. Accessing MySql:docker-compose exec db bash

After entering db bash hit mysql -u root -p for MySQL root password and default database refer docker-compose.yml file

Hope this article will help you to have the basic understanding and usability of the Docker and provide you with a solution for machine dependency problem while development to save your time and increase your productivity.

Omkar Kurmi


Share On


Omkar Kurmi

Omkar Kurmi

Top Stories

Zabbix Vs Nagios
Zabbix vs Nagios Core – All Key Features & Functionalities Compared
Choosing an efficient IT infrastructure monitoring system for your business can be overwhelming, as you need to take many features, factors, and functionalities into consideration. Technical and business requirements need to be assessed, in addition to examining any anomalies in the deployment or support processes. The level of competence of
Implementing a Raspberry Pi and Arduino UNO Based Current/Voltage Measurement System
In this article, we show you how to measure the AC Current and AC Voltage using the ACS712 current sensor and ZMPT101B voltage sensor. In addition to the Wattmeter, this circuit also acts as a Voltmeter and Ammeter which are used to measure voltage and current, respectively. If the connection
Zabbix 6.2
Zabbix 6.2 - More Powerful, Featureful, & Secure
The focus of infrastructure monitoring software company Zabbix has always been on innovation. Over the past 6 versions, the software company has made some necessary big and minor changes in its front end and back end to enhance usability and overall user experience.   Just like the previous versions, Zabbix
Zabbix 6.0 LTS
Zabbix 6.0 LTS – All the Latest Features & Functionalities 
Zabbix is a robust network, virtual machine, cloud service, and server monitoring software built on an open-source environment. The monitoring tool which already has numerous benefits has launched a number of new features and functionalities with its latest version Zabbix 6.0 LTS. The latest version of the network monitoring tool
Salesforce Marketing Cloud
Automate Marketing Initiatives with Salesforce Marketing Cloud 
In today’s era of digitalization, it is imperative to leverage the power of automation in marketing to boost revenue and enhance overall customer satisfaction. In a survey published by Statista, digital marketing automation was found to be the second most effective digital marketing technique (after content marketing) [1]. In fact,
Things You Should Know About Odoo
Things you Need to Know About Odoo ERP System 
Are you considering Odoo as your next ERP system? If yes, this might have raised a few common questions in your mind. Why go for the Odoo ERP system? What benefits does Odoo ERP Offer? Is there a better ERP other than Odoo? Is Odoo customizable? To answer all these


        Keep an eye on your inbox for the PDF, it's on its way!

        If you don't see it in your inbox, don't forget to give your junk folder a quick peek. Just in case. 

            You have successfully subscribed to the newsletter

            There was an error while trying to send your request. Please try again.

            Zehntech will use the information you provide on this form to be in touch with you and to provide updates and marketing.