Setup Docker for LAMP!

1 minute read

Author: Doe Hoon LEE

This shows the steps to setup LAMP environment with DockerPermalink

What is LAMP?Permalink

LAMP stands for Linux Apache MySQL PHPPermalink

You can simply git clone https://github.com/DOEHOONLEE/dockerLAMP.git or try typing in the following steps!Permalink

1. Project StructurePermalink

Project Structure

  1. Create directories php and www

  2. Create a Docker file Dockerfile in php directory

  3. Create a file docker-compose.yml in the root directory

  4. Create index.php in www directory

  5. Create .env in root directory [this can be skipped if you do not want to use environment variables]

2. In Dockerfile inside php directory, we will writePermalink

PHP Dockerfile

3. index.php within the www directory looks like thisPermalink

indexPHP

4. Now, the most interesting one: docker-compose.ymlPermalink

Docker Compose

You can use different names for DATABASE, user, password, or even ports if you want to. Also, again, you do not have to use environment variables like in the picture.

(See step 9 for environment variables)

5. We are now all set! Let’s test it out!Permalink

Compose Build

type in docker-compose up --build and test if it works!

6. Check if all containers are running smoothly!Permalink

type in docker ps

dockerPS

7. Go to localhostPermalink

localhost

You should see Connected to MySQL successfully!

8. Test if phpmyadmin is workingPermalink

Go to localhost:8080

phpmyadmin

9. In case you want to use environment variablesPermalink

env

10. To stop the service,Permalink

type in docker-compose stop

Docker Compose Stop

Leave a comment