Creating a Docker LAMP (Linux, Apache, PHP & MySQL) Stack

Christopher Quiles
4 min readJan 14, 2021

--

This lab will be creating a LAMP stack using Docker and solving some of the errors that will happen along the way.

What is the LAMP Stack? The widely popular LAMP stack is a set of open source software used for web application development. For a web application to work smoothly, it has to include an operating system, a web server, a database, and a programming language.

Docker-LAMP is a set of docker images along with a LAMP stack (Apache, MySQL and PHP) all in one handy package.

LAMP can help you reduce development time. Because LAMP is an open source stack that has been available for more than a decade, there is today a substantial LAMP ecosystem. You can build on what other people have done in the past and make it your own.

  1. The lab will create the following containers:
  • Apache + PHP Container
  • MySQL Container
  • PhpMyAdmin Container

2. Requirements:

For this lab we’ll be using an Ubuntu 20.04 LTS server

3. Managing Root User

# 1. Create the docker group.
$ sudo groupadd docker

# 2. Add your user to the docker group.
$ sudo usermod -aG docker $USER

# 3. Log out and log back in so that your group membership is re-evaluated.

# 4. Verify that you can run docker commands without sudo.
$ docker run hello-world

4. Git Clone & Change Directory:

Run the following command to clone git repository

git clone https://github.com/quiwest/Docker-LAMP.git

Change Directory

cd Docker-LAMP

5. Create Folder to mount with Apache and MySQL container

Before, we provision our LAMP container environment. First, We need to complete some prerequisites. We will setup Two Directories, One for DocumentRoot and Second for MySQL database directory.

sh setupdir.sh

Copy phpinfo.php INSIDE the DocumentRoot directory.

cp phpinfo.php DocumentRoot

6. Setup Container for LAMP Stack

To provision LAMP stack run following command.

docker-compose up

Validate Created Container.

docker container ls

You will see three up and running containers.

7. Verify Container and Services:

In order to verify Apache container, check your Docker host IP address and access IP Address in the browser.

*NOTE* You may need to install and start Apache for image to appear.
https://www.cyberciti.biz/faq/star-stop-restart-apache2-webserver/

http://IP-ADDRESS

*NOTE* If you’re apache2 is off, failing to start, or is having a configuration error you’ll receive a page like the the one below.

Try to restart Apache first

sudo service apache2 restart

or it might be an error so run the following commands

http://IP-ADDRESS/phpinfo.php

http://IP-ADDRESS:8080

We have successfully setup LAMP stack on Docker host.

Hopefully this helped somebody out there! Please stay connected.

https://www.linkedin.com/in/quiwest/

quileswest@gmail.com

--

--