Skip to content

alucard001/common-lamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

common-lamp

Common Linux, Apache, MySQL and PHP Environment Setup for Docker

What is it?

This is a common/general purpose docker image and docker-compose to gather as much PHP libraries and Apache as possible.

Why are you doing it?

I would like to make a "replacable" docker image/machine that has less dependency as possible. So that wheneve there is a new project, I can simply download and setup a new image and start building website project right away, without spending another half day or even 1 - 2 hours just to setup and config an environment.

What are inside?

This includes:

  • Linux (Ubuntu 16.04)
  • Apache 2.4 (Use apt-get install apache instead of using official image)
  • PHP 7 (Use apt-get to download PHP instead of using official image)
  • MySQL 5.7.14 (as of this writing, from official MySQL docker image: mysql:latest)

Notes on Apache/PHP

  • I am using Ubuntu 16.04, and the Apache/PHP in Ubuntu official repo. Because it is simpler to install/config/use, than using "official" image.
  • The main obstacle of NOT using official PHP docker image is that, if I want to install additional PHP modules, I need to use their custom commands instead of normal apt-get. To me, using Ubuntu official apt-get command and download repo from them is much easier and safer.
  • Please read my Dockerfile, it is much simpler than before, and give you a general idea on what I did.
  • It is using latest PHP 7 and latest Apache
  • Web file directory in Apache container is /var/www/html
  • Web files are stored OUTSIDE the container. By default (docker-compose.yml), you will have a html directory that saved all your files (Directory structure see below).
  • Docker host (the computer which you run "docker" command) opens port 80.
  • Apache container exposes port 80.
  • Visitor website traffic coming from docker host will be forward to apache container (80:80)
  • The name in YML is called "web", and it links to "db", which is the database (See below).
  • You may also see that I install Redis. And yes, my plan is to use Redis to speed up the loading time. One of my to-do item is to integrate Redis into this project.

Notes on MySQL

  • It is based on official MySQL docker image (https://hub.docker.com/_/mysql/). I am using tag "latest".
  • Web files are stored OUTSIDE the container. By default (docker-compose.yml), data is saved under "mysql_data" (Directory structure see below).
  • Docker host (the computer which you run "docker" command) opens port 3306.
  • MySQL container exposes port 3306.
  • DB connection traffic coming from docker host will be forward to apache container (3306:3306)
  • The name in YML is called "db", and it is linked from "web" (See above).

Directory Structure

Below is the exact file name inside a directory. () is comment.

- common-lamp
---- docker-compose.yml
---- Dockerfile
---- html (will be created when you run "docker-compose up -d")
---- mysql_data (will be created when you run "docker-compose up -d")

Assumptions

  • The purpose of this Git is to create the envirnoment as soon as possible.
  • Why not XAMPP? Well you can. It is your choice. :D But it seems docker provides much more potential (http://www.sitepoint.com/re-introducing-vagrant-right-way-start-php/). This article is talking about Vagrant, but same idea still applies, I think.
  • I put all website files and database files OUTSIDE the container, make the container a replaceable "machine".
  • One website project, one common-lamp, which means one set of common-lamp.
  • One website project means: one web server and one database server. In other words, no cluster.

Known issue/TODO:

  • I realise that the database expose may actually be unnecessary and will have potential security problem.
  • Add custom httpd.conf php.ini and my.cnf config files.
  • Use Redis to speedup loading website. Yes you are right, I am using Wordpress on most of my project at this moment.

My comments:

I know, the common/best practise is to limit the available components as many as possible to prevent potential library conflicts and unnecessary performance punishment. However, the concept here is to setup an contain-everything machine FIRST, and then disable necessary libraries based on your requirements.

Based on the above concept, it is surprising to know that it is difficult to find such thing. So I decided to take the first step to create that.

I am not perfect, and neither is my Git/code/program. Therefore this docker-compose.yml and Dockerfile will be continuously optimized/re-structure so that it can benefit me, and you also.

Any suggestions/recommendations/comments are welcomed!

Happy dockering and developing

Talk soon

Ellery

About

Docker file for common LAMP setting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published