From f20aae3732f15478d2293e04cdf5d428dd497436 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Thu, 26 May 2016 12:26:21 -0500 Subject: [PATCH] Initial commit --- Dockerfile | 45 +++++++++ README.md | 91 +++++++++++++++++ config/apache2.conf | 224 ++++++++++++++++++++++++++++++++++++++++++ config/my.cnf | 128 ++++++++++++++++++++++++ docker-compose.yml | 8 ++ public_html/index.php | 155 +++++++++++++++++++++++++++++ 6 files changed, 651 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 config/apache2.conf create mode 100644 config/my.cnf create mode 100644 docker-compose.yml create mode 100644 public_html/index.php diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..144876c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM debian:jessie + +# Install necessary programs +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get update && apt-get install -y apache2 libapache2-mod-php5 \ +mysql-server php5 php5-mysql php5-mcrypt php5-curl php5-gd phpmyadmin vim \ +wget curl git + +# Configure apache +COPY ./config/apache2.conf /etc/apache2/apache2.conf +RUN a2enmod rewrite + +# Configure MySQL +COPY ./config/my.cnf /etc/mysql/my.cnf +EXPOSE 3306 + +# Install composer +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ + php -r "if (hash_file('SHA384', 'composer-setup.php') === '92102166af5abdb03f49ce52a40591073a7b859a86e8ff13338cf7db58a19f7844fbc0bb79b2773bf30791e935dbd938') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \ + php composer-setup.php --install-dir=/usr/bin --filename=composer && \ + php -r "unlink('composer-setup.php');" + +# Install magerun +RUN wget https://files.magerun.net/n98-magerun.phar && \ + mv n98-magerun.phar /usr/bin/ && \ + echo 'alias magerun="php -f /usr/bin/n98-magerun.phar --"' >> /root/.bashrc + +# Install Accolade Magerun Tools +RUN mkdir -p /usr/local/share/n98-magerun/modules && \ +git clone https://github.com/Accolades/MagerunTools.git /usr/local/share/n98-magerun/modules/MagerunTools + +# Install Magento Mess Detector +RUN git clone https://github.com/AOEpeople/mpmd.git /usr/local/share/n98-magerun/modules/mpmd + +# Install modman +RUN wget -q --no-check-certificate -O - https://raw.github.com/colinmollenhour/modman/master/modman-installer | bash && \ +mv ~/bin/modman /usr/local/bin/modman + +# Start the web server +ENV APACHE_LOCK_DIR=/var/lock/apache2 +ENV APACHE_PID_FILE=/var/run/apache2/apache2.pid +ENV APACHE_RUN_USER=www-data +ENV APACHE_RUN_GROUP=www-data +ENV APACHE_LOG_DIR=/var/log/apache2 +ENTRYPOINT service mysql start; apache2 -DFOREGROUND diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cee545 --- /dev/null +++ b/README.md @@ -0,0 +1,91 @@ +Accolade's Docker LAMP Stack for Magento +======================================== + +To get started, first [download and install Docker](https://docs.docker.com/engine/installation/). + +For Windows Devs +----------------- + +Once you have that out of the way, you'll first need to delete the default machine, and replace it with one that has a bit more RAM. You shouldn't allocate more than half of your total RAM to the machine. Since I have 8GB of RAM, I'll allocate 4GB to Docker, so I still have a bit for my host machine: + +Remove the existing machine: + +`docker-machine rm default` + +Replace it with a new one: + +`docker-machine create -d virtualbox --virtualbox-memory "4096" default` + +You can replace `default` with whatever you like. It's not very important. + +With your new machine set up, cd into the directory where these files are located. Docker will start you at your home by default, so for me it's just `cd Documents/docker-lemp` + +*Reminder to Windows devs:* This is a bash shell, so capitalization counts. + +All Devs + +From the docker-lamp directory, you can run + +`docker-compose up -d` + +This will take some time because Docker will have to fetch and configure the image for the LAMP stack. + +Windows Devs +------------ + +Once the installation is complete, run + +`docker-machine ip default` + +to get the IP address of your Docker machine. Drop that into the address bar of your favorite browser and you should see a screen very much like this one! + +Linux Devs +---------- + +On Linux, you can usually get away with just going to localhost (127.0.0.1) + +All Devs +--------- + +You can also use that same IP address to set up MySQL Workbench with it, if you prefer, or you can use PHPMyAdmin, by visiting your machine's IP address at /phpmyadmin. In my case, this would be http://192.168.99.100/phpmyadmin. + +The default root password is empty. + +Once you have your Docker machine running, you can place your files in the public_html folder. The other folders contain configuration files, so it's not recommended to add files to them or modify them in any way. + +To get shell access to your machine, there are a couple of things you have to take into consideration. The most important being that the process are each run in their own containers, so you cannot access multiple processes from the same shell. This means that you will need to open a different shell process for each running process you wish to connect to. To see a list of all of your running containers, use the following command: + +`docker ps` + +this will give you an output that looks something like this: + +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +50d61f2b31cb dockerlemp_nginx "nginx -g 'daemon off" About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp dockerlemp_nginx_1 +190bc213fe3a dockerlemp_php "php-fpm" About an hour ago Up About an hour 9000/tcp dockerlemp_php_1 +fe0d4632c300 phpmyadmin/phpmyadmin "/run.sh" About an hour ago Up About an hour 0.0.0.0:8080->80/tcp dockerlemp_phpmyadmin_1 +509ab5917034 dockerlemp_mysql "docker-entrypoint.sh" About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp dockerlemp_mysql_1 +``` + +By using either the container id or its name, you can connect to them with the following command: + +`docker exec -it CONTAINER_NAME/ID /bin/bash` + +Replace CONTAINER_NAME/ID with the name or id of the container you'd like to connect to, and you will be dropped into a bash environment where you can run commands like importing a large database into MySQL or running composer or magerun (both of which are already installed and ready to use.) + +So, to run a composer installation, you would need to first run + +`docker exec -it dockerlemp_php_1 /bin/bash` + +to gain access to the shell, and then you could cd into the correct directory and run your composer install command. + +As stated earlier, you will not have access to the mysql process from this shell. To gain that, you'll have to press `Ctrl + D` to exit the current shell, and then run + +`docker exec -it dockerlemp_mysql_1 /bin/bash` + +to enter a shell with access to the mysql process. + +DISCLAIMER: + +This Docker machine should under NO circumstances, be used in a production environment. This is solely intended for local development, and has numerous security concerns that would need to be addressed prior to being a feasible production candidate. You have been warned. diff --git a/config/apache2.conf b/config/apache2.conf new file mode 100644 index 0000000..29c2629 --- /dev/null +++ b/config/apache2.conf @@ -0,0 +1,224 @@ +# This is the main Apache server configuration file. It contains the +# configuration directives that give the server its instructions. +# See http://httpd.apache.org/docs/2.4/ for detailed information about +# the directives and /usr/share/doc/apache2/README.Debian about Debian specific +# hints. +# +# +# Summary of how the Apache 2 configuration works in Debian: +# The Apache 2 web server configuration in Debian is quite different to +# upstream's suggested way to configure the web server. This is because Debian's +# default Apache2 installation attempts to make adding and removing modules, +# virtual hosts, and extra configuration directives as flexible as possible, in +# order to make automating the changes and administering the server as easy as +# possible. + +# It is split into several files forming the configuration hierarchy outlined +# below, all located in the /etc/apache2/ directory: +# +# /etc/apache2/ +# |-- apache2.conf +# | `-- ports.conf +# |-- mods-enabled +# | |-- *.load +# | `-- *.conf +# |-- conf-enabled +# | `-- *.conf +# `-- sites-enabled +# `-- *.conf +# +# +# * apache2.conf is the main configuration file (this file). It puts the pieces +# together by including all remaining configuration files when starting up the +# web server. +# +# * ports.conf is always included from the main configuration file. It is +# supposed to determine listening ports for incoming connections which can be +# customized anytime. +# +# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ +# directories contain particular configuration snippets which manage modules, +# global configuration fragments, or virtual host configurations, +# respectively. +# +# They are activated by symlinking available configuration files from their +# respective *-available/ counterparts. These should be managed by using our +# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See +# their respective man pages for detailed information. +# +# * The binary is called apache2. Due to the use of environment variables, in +# the default configuration, apache2 needs to be started/stopped with +# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not +# work with the default configuration. + + +# Global configuration +# + +# +# ServerRoot: The top of the directory tree under which the server's +# configuration, error, and log files are kept. +# +# NOTE! If you intend to place this on an NFS (or otherwise network) +# mounted filesystem then please read the Mutex documentation (available +# at ); +# you will save yourself a lot of trouble. +# +# Do NOT add a slash at the end of the directory path. +# +#ServerRoot "/etc/apache2" + +# +# The accept serialization lock file MUST BE STORED ON A LOCAL DISK. +# +Mutex file:${APACHE_LOCK_DIR} default + +# +# PidFile: The file in which the server should record its process +# identification number when it starts. +# This needs to be set in /etc/apache2/envvars +# +PidFile ${APACHE_PID_FILE} + +# +# Timeout: The number of seconds before receives and sends time out. +# +Timeout 300 + +# +# KeepAlive: Whether or not to allow persistent connections (more than +# one request per connection). Set to "Off" to deactivate. +# +KeepAlive On + +# +# MaxKeepAliveRequests: The maximum number of requests to allow +# during a persistent connection. Set to 0 to allow an unlimited amount. +# We recommend you leave this number high, for maximum performance. +# +MaxKeepAliveRequests 100 + +# +# KeepAliveTimeout: Number of seconds to wait for the next request from the +# same client on the same connection. +# +KeepAliveTimeout 5 + + +# These need to be set in /etc/apache2/envvars +User ${APACHE_RUN_USER} +Group ${APACHE_RUN_GROUP} + +# +# HostnameLookups: Log the names of clients or just their IP addresses +# e.g., www.apache.org (on) or 204.62.129.132 (off). +# The default is off because it'd be overall better for the net if people +# had to knowingly turn this feature on, since enabling it means that +# each client request will result in AT LEAST one lookup request to the +# nameserver. +# +HostnameLookups Off + +# ErrorLog: The location of the error log file. +# If you do not specify an ErrorLog directive within a +# container, error messages relating to that virtual host will be +# logged here. If you *do* define an error logfile for a +# container, that host's errors will be logged there and not here. +# +ErrorLog ${APACHE_LOG_DIR}/error.log + +# +# LogLevel: Control the severity of messages logged to the error_log. +# Available values: trace8, ..., trace1, debug, info, notice, warn, +# error, crit, alert, emerg. +# It is also possible to configure the log level for particular modules, e.g. +# "LogLevel info ssl:warn" +# +LogLevel warn + +# Include module configuration: +IncludeOptional mods-enabled/*.load +IncludeOptional mods-enabled/*.conf + +# Include list of ports to listen on +Include ports.conf + + +# Sets the default security model of the Apache2 HTTPD server. It does +# not allow access to the root filesystem outside of /usr/share and /var/www. +# The former is used by web applications packaged in Debian, +# the latter may be used for local directories served by the web server. If +# your system is serving content from a sub-directory in /srv you must allow +# access here, or in any related virtual host. + + Options FollowSymLinks + AllowOverride None + Require all denied + + + + AllowOverride None + Require all granted + + + + Options Indexes FollowSymLinks + AllowOverride all + Require all granted + + +# +# Options Indexes FollowSymLinks +# AllowOverride None +# Require all granted +# + + + + +# AccessFileName: The name of the file to look for in each directory +# for additional configuration directives. See also the AllowOverride +# directive. +# +AccessFileName .htaccess + +# +# The following lines prevent .htaccess and .htpasswd files from being +# viewed by Web clients. +# + + Require all denied + + + +# +# The following directives define some format nicknames for use with +# a CustomLog directive. +# +# These deviate from the Common Log Format definitions in that they use %O +# (the actual bytes sent including headers) instead of %b (the size of the +# requested file), because the latter makes it impossible to detect partial +# requests. +# +# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended. +# Use mod_remoteip instead. +# +LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined +LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined +LogFormat "%h %l %u %t \"%r\" %>s %O" common +LogFormat "%{Referer}i -> %U" referer +LogFormat "%{User-agent}i" agent + +# Include of directories ignores editors' and dpkg's backup files, +# see README.Debian for details. + +# Include generic snippets of statements +IncludeOptional conf-enabled/*.conf + +# Include the virtual host configurations: +IncludeOptional sites-enabled/*.conf + +# Include PHPMyAdmin +Include /etc/phpmyadmin/apache.conf + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/config/my.cnf b/config/my.cnf new file mode 100644 index 0000000..7d4d5c5 --- /dev/null +++ b/config/my.cnf @@ -0,0 +1,128 @@ +# +# The MySQL database server configuration file. +# +# You can copy this to one of: +# - "/etc/mysql/my.cnf" to set global options, +# - "~/.my.cnf" to set user-specific options. +# +# One can use all long options that the program supports. +# Run program with --help to get a list of available options and with +# --print-defaults to see which it would actually understand and use. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +# This will be passed to all mysql clients +# It has been reported that passwords should be enclosed with ticks/quotes +# escpecially if they contain "#" chars... +# Remember to edit /etc/mysql/debian.cnf when changing the socket location. +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + +# Here is entries for some specific programs +# The following values assume you have at least 32M ram + +# This was formally known as [safe_mysqld]. Both versions are currently parsed. +[mysqld_safe] +socket = /var/run/mysqld/mysqld.sock +nice = 0 + +[mysqld] +# +# * Basic Settings +# +user = mysql +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +port = 3306 +basedir = /usr +datadir = /var/lib/mysql +tmpdir = /tmp +lc-messages-dir = /usr/share/mysql +skip-external-locking +# +# Instead of skip-networking the default is now to listen only on +# localhost which is more compatible and is not less secure. +bind-address = 127.0.0.1 +# +# * Fine Tuning +# +key_buffer = 16M +max_allowed_packet = 1G +thread_stack = 192K +thread_cache_size = 8 +# This replaces the startup script and checks MyISAM tables if needed +# the first time they are touched +myisam-recover = BACKUP +#max_connections = 100 +#table_cache = 64 +#thread_concurrency = 10 +# +# * Query Cache Configuration +# +query_cache_limit = 1M +query_cache_size = 16M +# +# * Logging and Replication +# +# Both location gets rotated by the cronjob. +# Be aware that this log type is a performance killer. +# As of 5.1 you can enable the log at runtime! +#general_log_file = /var/log/mysql/mysql.log +#general_log = 1 +# +# Error log - should be very few entries. +# +log_error = /var/log/mysql/error.log +# +# Here you can see queries with especially long duration +#slow_query_log_file = /var/log/mysql/mysql-slow.log +#slow_query_log = 1 +#long_query_time = 2 +#log_queries_not_using_indexes +# +# The following can be used as easy to replay backup logs or for replication. +# note: if you are setting up a replication slave, see README.Debian about +# other settings you may need to change. +#server-id = 1 +#log_bin = /var/log/mysql/mysql-bin.log +expire_logs_days = 10 +max_binlog_size = 100M +#binlog_do_db = include_database_name +#binlog_ignore_db = include_database_name +# +# * InnoDB +# +# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. +# Read the manual for more InnoDB related options. There are many! +# +# * Security Features +# +# Read the manual, too, if you want chroot! +# chroot = /var/lib/mysql/ +# +# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". +# +# ssl-ca=/etc/mysql/cacert.pem +# ssl-cert=/etc/mysql/server-cert.pem +# ssl-key=/etc/mysql/server-key.pem + + + +[mysqldump] +quick +quote-names +max_allowed_packet = 1G + +[mysql] +#no-auto-rehash # faster start of mysql but no tab completition + +[isamchk] +key_buffer = 16M + +# +# * IMPORTANT: Additional settings that can override those from this file! +# The files must end with '.cnf', otherwise they'll be ignored. +# +!includedir /etc/mysql/conf.d/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..72777f4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +app: + build: . + ports: + - 80:80 + - 3306:3306 + volumes: + - /var/lib/mysql + - ./public_html:/var/www/html diff --git a/public_html/index.php b/public_html/index.php new file mode 100644 index 0000000..88c461a --- /dev/null +++ b/public_html/index.php @@ -0,0 +1,155 @@ + + + + + Accolade Docker - LAMP Stack + + + +
+

Accolade's Docker LAMP Stack for Magento

+

To get started, first download and install Docker.

+ +

For Windows Devs

+ +

Once you have that out of the way, you'll first need to delete the default machine, and replace it with one that has a bit more RAM. You shouldn't allocate more than half of your total RAM to the machine. Since I have 8GB of RAM, I'll allocate 4GB to Docker, so I still have a bit for my host machine:

+ +

Remove the existing machine:

+ +
docker-machine rm default
+ +

Replace it with a new one:

+ +
docker-machine create -d virtualbox --virtualbox-memory "4096" default
+ +

You can replace

+
default
+

with whatever you like. It's not very important.

+ +

With your new machine set up, cd into the directory where these files are located. Docker will start you at your home by default, so for me it's just

+ +
cd Documents/docker-lemp
+ +

Reminder to Windows devs: This is a bash shell, so capitalization counts.

+ +

All Devs

+ +

From the docker-lamp directory, you can run

+ +
docker-compose up -d
+ +

This will take some time because Docker will have to fetch and configure the image for the LAMP stack.

+ +

Windows Devs

+ +

Once the installation is complete, run

+ +
docker-machine ip default
+ +

to get the IP address of your Docker machine. Drop that into the address bar of your favorite browser and you should see a screen very much like this one!

+ +

Linux Devs

+ +

On Linux, you can usually get away with just going to localhost (127.0.0.1)

+ +

All Devs

+ +

You can also use that same IP address to set up MySQL Workbench with it, if you prefer, or you can use PHPMyAdmin, by visiting your machine's IP address at /phpmyadmin. In my case, this would be http://192.168.99.100/phpmyadmin.

+ +

The default root password is empty.

+ +

Once you have your Docker machine running, you can place your files in the public_html folder. The other folders contain configuration files, so it's not recommended to add files to them or modify them in any way.

+ +

To get shell access to your machine, there are a couple of things you have to take into consideration. The most important being that the process are each run in their own containers, so you cannot access multiple processes from the same shell. This means that you will need to open a different shell process for each running process you wish to connect to. To see a list of all of your running containers, use the following command:

+ +
docker ps
+ +

this will give you an output that looks something like this:

+ +
$ docker ps
+CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                         NAMES
+50d61f2b31cb        dockerlemp_nginx        "nginx -g 'daemon off"   About an hour ago   Up About an hour    0.0.0.0:80->80/tcp, 443/tcp   dockerlemp_nginx_1
+190bc213fe3a        dockerlemp_php          "php-fpm"                About an hour ago   Up About an hour    9000/tcp                      dockerlemp_php_1
+fe0d4632c300        phpmyadmin/phpmyadmin   "/run.sh"                About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp          dockerlemp_phpmyadmin_1
+509ab5917034        dockerlemp_mysql        "docker-entrypoint.sh"   About an hour ago   Up About an hour    0.0.0.0:3306->3306/tcp        dockerlemp_mysql_1
+            
+ +

By using either the container id or its name, you can connect to them with the following command:

+ +
docker exec -it CONTAINER_NAME/ID /bin/bash
+ +

Replace CONTAINER_NAME/ID with the name or id of the container you'd like to connect to, and you will be dropped into a bash environment where you can run commands like importing a large database into MySQL or running composer or magerun (both of which are already installed and ready to use.)

+ +

So, to run a composer installation, you would need to first run

+ +
docker exec -it dockerlemp_php_1 /bin/bash
+ +

to gain access to the shell, and then you could cd into the correct directory and run your composer install command.

+ +

As stated earlier, you will not have access to the mysql process from this shell. To gain that, you'll have to press

+
Ctrl + D
+

to exit the current shell, and then run

+ +
docker exec -it dockerlemp_mysql_1 /bin/bash
+ +

to enter a shell with access to the mysql process.

+ +

For all questions and concerns, ping @Billy in Flowdock

+ +

DISCLAIMER:

+ +

This Docker machine should under NO circumstances, be used in a production environment. This is solely intended for local development, and has numerous security concerns that would need to be addressed prior to being a feasible production candidate. You have been warned.

+

MySQL Connection Status:

+
+ +