LAMP Docker Tutorial

Today we bring you a small pill of knowledge with the hand of Docker for website development in PHP.


What web developer has not had to configure a lamp setup with MySQL, PHP/Apache etc ? There are many solutions and today I want to present to you a small Tutorial to have your own LAMP Stack so you can develop easily any php website with a simple Docker-compose file.

LAMP Docker Tutorial

There are many solutions to do this. Since us - web developers are normally inside so many projects, we need to be able to switch between setups so we are going to mount everything from a docker-compose.yml file that we can just copy and run Docker easily.


First things first, I'm asuming that you have but if you haven't, install Docker in your computer. Up to windows Windows 10 Home you have to use the docker-toolbox, where as Windows 10 pro users get to use the latest version of Docker containers.


Check that your installation is correct by executing

docker --version

Now, create an new folder where you will be working and create a new file, paste the following code and save it as docker-compose.yml. Don't worry we will explain what's going on in a minute

version: '2'
services:
  mariadb:
    image: 'mariadb:latest'
    environment:
      - MYSQL_USER=local_user
      - MYSQL_DATABASE=local_database
      - MYSQL_ROOT_PASSWORD=password
    # volumes:
      # Mounting the content of the database inside of a subfolder named mariadb_data
      # - './mariadb_data:/var/lib/mysql'
    ports:
      - '3306:3306'
    expose:
      - 3306
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
  apache:
    image: php:7.3-apache
    volumes:
      # Mounting the website inside of a subfolder named app
      - ./app/:/var/www/html
    expose:
      - 80
    ports:
      - 80:80

Let's analyze what Docker is doing here. We are going to create three services. One of the services will be the mysql database. The next service will be a mysql explorer like phpMyadmin called Adminer. This will allow us to explore the mysql database if we don't happen to have any sql explorer installed.


The last service will be the Apache php service with version 7.3 . If you need another specific version for PHP, simply change the numbers.


Let's go back to the docker terminal (I suggest you use the Docker Quickstart Terminal if you are not familiar with the cli or if you are like me and have it missconfigured in your laptop) and run the command.

docker-compose up

If any errors occur, make sure that the docker machine has access to the folder you are working in. (Share the folder in either Docker Desktop or Docker toolbox for legacy systems).


Now, check the IP of your docker virtual machine (normally it would display in localhost, but in windows legacy systems you'll need to check for the IP Address first. If you want it fast simply check it in Kitematic.

Now access your ip in your web browser. Remember you can access the port 8080 for the adminer interface for mysql, and you can access the port 3306 to connect to the mysql server.

Exploring the docker-compose.yml

The Docker-compose.yml files are pretty self explanatory. Whenever I work with projects or systems I like to set them up user Docker compose or docker stack, and run the images from my docker-compose.yml.


For the time being. we use EXPOSE to expose the docker container ports to any other app or container. This way we can access the database server from any other application. From the docker-compose what we are doing is declaring 3 different services that will act as independent containers.


If we wanted for example, to create a personalized php.ini file for our php server. We would need to create a php.ini file and then, under the volumes section in the apache: service , we should add the following line (remember to keep the indentation).

- ./php.ini:/usr/local/etc/php/php.ini

And in the same folder as we have the docker-compose.yml file we should have a php.ini file with the modifications that we wanted to personalize for our server. Check the specs of the php machine by echoing a phpinfo(); and then create your php.ini accordingly to your installation needs.


If you can't be bothered in editing the whole thing and you only need to modify it, you can always create a backup in your folder by accessing your apache docker container via ssh (or kitematic). Navigating to the file in the /usr/local/etc/php/ folder and then copying the php file to the /var/www/html . A new file will automatically pop up that you can edit and then add the line previously mentioned


Happy Coding!

Our reader's favorite picks

Joomla Docker Tutorial - Create your first joomla docker container

Creating a Joomla Docker container.

Leave review
In this tutorial we are going to learn how to set up a docker container and...
Read More
Lamp Docker Tutorial

LAMP Docker Tutorial

Leave review
Today we bring you a small pill of knowledge with the hand of Docker for we...
Read More
If you want to work remote then don't make these mistakes!

If you want to work remote then don't make these mistakes!

Leave review
Read More
Telegram Creator acuses Whatsapp of having backdoors for syping

Telegram Creator acuses Whatsapp of having backdoors for syping

Leave review
According to Durov, Whatsapp has never been secure and it has been done lik...
Read More
How app development works in developing countries

How app development works in developing countries

Leave review
Read More
This is what your UI should learn from videogames

This is what your UI should learn from videogames

Leave review
The videogame industry moves over one billion dollars on a yearly basis. It...
Read More
Suscribe to our mailing list

What is this about?

Our latest posts.

How to use docker and wordpress

Wordpress and Docker Tutorial

Leave review
Using docker allows us to run all of our project straight in our own machin...
Read More
Using Redis and Node js 101

Node and Redis via Docker

Leave review
In this tutorial we are going to learn how to set up a small redis developm...
Read More
Answering tricky interview JS Questions

Answering tricky interview JS Questions

Leave review
This is a small comprendum of the sort of questions you may find in a Javas...
Read More
Lamp Docker Tutorial

LAMP Docker Tutorial

Leave review
Today we bring you a small pill of knowledge with the hand of Docker for we...
Read More
5G and the value it adds to your Business

5G and the value it adds to your Business

Leave review
We have heard about the infamous 5G network and the dispute between Huawei,...
Read More

Related topics

Our categories.