├── LICENSE ├── README.md ├── backp-docker-compose.yml ├── bin ├── mariadb │ └── Dockerfile ├── nodejs │ └── Dockerfile ├── php7.4-apache │ └── Dockerfile └── php8.3-apache │ └── Dockerfile ├── config ├── apache2 │ └── custom.conf ├── mysql │ └── my.cnf ├── php │ └── php.ini └── vhosts │ └── default.conf ├── docker-compose.yml ├── mysql └── .gitignore ├── node ├── .gitignore ├── app1 │ └── index.js └── ecosystem.config.js ├── ssl └── .gitignore └── www └── default ├── httpdocs └── index.php └── logs └── .gitkeep /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Davide Cesarano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker-compose LAMP 2 | This is a boilerplate for LAMP based projects that run on Docker-Compose. 3 | The main services included are: 4 | * Ubuntu 18.04 5 | * Apache 2 6 | * MariaDB 7 | * PHP 7.4 8 | * Node.js 9 | * Composer 10 | 11 | ## Usage 12 | ``` 13 | $ git clone https://github.com/davidecesarano/docker-compose-lamp.git 14 | $ cd docker-compose-lamp 15 | $ docker-compose up -d 16 | ``` 17 | -------------------------------------------------------------------------------- /backp-docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.6" 2 | services: 3 | webserver: 4 | build: 5 | context: ./bin/php7.4-apache 6 | container_name: php7.4-apache 7 | restart: always 8 | ports: 9 | - target: 80 10 | published: 80 11 | protocol: tcp 12 | mode: host 13 | - target: 443 14 | published: 443 15 | protocol: tcp 16 | mode: host 17 | volumes: 18 | - ./www:/var/www/html 19 | - ./config/apache2/custom.conf:/etc/apache2/mods-enabled/my.conf 20 | - ./config/php/php.ini:/etc/php/7.4/apache2/conf.d/custom.ini 21 | - ./config/vhosts:/etc/apache2/sites-enabled 22 | - ./ssl:/etc/letsencrypt 23 | links: 24 | - mysql 25 | nodejs: 26 | build: 27 | context: ./bin/nodejs 28 | container_name: nodejs 29 | restart: always 30 | ports: 31 | - target: 3000 32 | published: 3000 33 | protocol: tcp 34 | mode: host 35 | volumes: 36 | - ./node:/opt/node 37 | mysql: 38 | build: 39 | context: ./bin/mariadb 40 | container_name: mariadb 41 | restart: always 42 | ports: 43 | - target: 3306 44 | published: 3306 45 | protocol: tcp 46 | mode: host 47 | environment: 48 | MYSQL_ROOT_PASSWORD: docker 49 | TZ: Europe/Rome 50 | volumes: 51 | - ./mysql:/var/lib/mysql 52 | - ./config/mysql/my.cnf:/etc/mysql/conf.d/my.cnf -------------------------------------------------------------------------------- /bin/mariadb/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mariadb:latest -------------------------------------------------------------------------------- /bin/nodejs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | ENV DEBIAN_FRONTEND noninteractive 4 | RUN apt-get update && apt-get install --assume-yes apt-utils 5 | 6 | # software 7 | RUN apt-get install -y curl zip nano software-properties-common 8 | 9 | # locale 10 | RUN apt-get install -y language-pack-en-base language-pack-it 11 | RUN locale-gen en_US.UTF-8 12 | ENV LANG en_US.UTF-8 13 | ENV LC_ALL en_US.UTF-8 14 | ENV TZ=Europe/Rome 15 | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 16 | 17 | # install nodejs 18 | RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \ 19 | && apt-get install -y nodejs build-essential \ 20 | && mkdir /opt/node 21 | 22 | # install apt-transport-https for yarn repository 23 | RUN apt-get install apt-transport-https -y 24 | 25 | # add yarn repository 26 | RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 27 | RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list 28 | 29 | # update 30 | RUN apt-get update -y 31 | 32 | # install yarn 33 | RUN apt-get install yarn -y 34 | RUN apt-get install build-essential 35 | 36 | # install pm2 37 | RUN npm i -g pm2 38 | 39 | # start apache2 and pm2 apps 40 | ENTRYPOINT pm2-runtime /opt/node/ecosystem.config.js -------------------------------------------------------------------------------- /bin/php7.4-apache/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4.2-apache-buster 2 | 3 | # Surpresses debconf complaints of trying to install apt packages interactively 4 | # https://github.com/moby/moby/issues/4032#issuecomment-192327844 5 | 6 | ARG DEBIAN_FRONTEND=noninteractive 7 | 8 | # Update 9 | RUN apt-get -y update --fix-missing && \ 10 | apt-get upgrade -y && \ 11 | apt-get --no-install-recommends install -y apt-utils && \ 12 | rm -rf /var/lib/apt/lists/* 13 | 14 | 15 | # Install useful tools and install important libaries 16 | RUN apt-get -y update && \ 17 | apt-get -y --no-install-recommends install nano wget \ 18 | dialog \ 19 | libsqlite3-dev \ 20 | libsqlite3-0 && \ 21 | apt-get -y --no-install-recommends install default-mysql-client \ 22 | zlib1g-dev \ 23 | libzip-dev \ 24 | libicu-dev && \ 25 | apt-get -y --no-install-recommends install --fix-missing apt-utils \ 26 | build-essential \ 27 | git \ 28 | curl \ 29 | libonig-dev && \ 30 | apt-get install -y iputils-ping && \ 31 | apt-get -y --no-install-recommends install --fix-missing libcurl4 \ 32 | libcurl4-openssl-dev \ 33 | zip \ 34 | openssl && \ 35 | rm -rf /var/lib/apt/lists/* && \ 36 | curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 37 | 38 | # Install xdebug 39 | RUN pecl install xdebug-3.1.4 && \ 40 | docker-php-ext-enable xdebug && \ 41 | mkdir /var/log/xdebug 42 | 43 | # Install redis 44 | RUN pecl install redis-5.1.1 && \ 45 | docker-php-ext-enable redis 46 | 47 | # Install imagick 48 | RUN apt-get update && \ 49 | apt-get -y --no-install-recommends install --fix-missing libmagickwand-dev && \ 50 | rm -rf /var/lib/apt/lists/* && \ 51 | pecl install imagick && \ 52 | docker-php-ext-enable imagick 53 | 54 | # Other PHP7 Extensions 55 | 56 | RUN docker-php-ext-install pdo_mysql && \ 57 | docker-php-ext-install pdo_sqlite && \ 58 | docker-php-ext-install bcmath && \ 59 | docker-php-ext-install mysqli && \ 60 | docker-php-ext-install curl && \ 61 | docker-php-ext-install tokenizer && \ 62 | docker-php-ext-install json && \ 63 | docker-php-ext-install zip && \ 64 | docker-php-ext-install -j$(nproc) intl && \ 65 | docker-php-ext-install mbstring && \ 66 | docker-php-ext-install gettext && \ 67 | docker-php-ext-install calendar && \ 68 | docker-php-ext-install exif 69 | 70 | 71 | # Install Freetype 72 | RUN apt-get -y update && \ 73 | apt-get --no-install-recommends install -y libfreetype6-dev \ 74 | libjpeg62-turbo-dev \ 75 | libpng-dev && \ 76 | rm -rf /var/lib/apt/lists/* && \ 77 | docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg && \ 78 | docker-php-ext-install gd 79 | 80 | # Insure an SSL directory exists 81 | RUN mkdir -p /etc/apache2/ssl 82 | 83 | # Enable SSL support 84 | RUN a2enmod ssl && a2enmod rewrite 85 | 86 | # Enable apache modules 87 | RUN a2enmod rewrite headers 88 | 89 | # Cleanup 90 | RUN rm -rf /usr/src/* -------------------------------------------------------------------------------- /bin/php8.3-apache/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.3-apache-bookworm 2 | 3 | # Surpresses debconf complaints of trying to install apt packages interactively 4 | # https://github.com/moby/moby/issues/4032#issuecomment-192327844 5 | 6 | ARG DEBIAN_FRONTEND=noninteractive 7 | 8 | # Update 9 | RUN apt-get -y update --fix-missing && \ 10 | apt-get upgrade -y && \ 11 | apt-get --no-install-recommends install -y apt-utils && \ 12 | rm -rf /var/lib/apt/lists/* 13 | 14 | 15 | # Install useful tools and install important libaries 16 | RUN apt-get -y update && \ 17 | apt-get -y --no-install-recommends install nano wget \ 18 | dialog \ 19 | libsqlite3-dev \ 20 | libsqlite3-0 && \ 21 | apt-get -y --no-install-recommends install default-mysql-client \ 22 | zlib1g-dev \ 23 | libzip-dev \ 24 | libicu-dev && \ 25 | apt-get -y --no-install-recommends install --fix-missing apt-utils \ 26 | build-essential \ 27 | git \ 28 | curl \ 29 | libonig-dev && \ 30 | apt-get install -y iputils-ping && \ 31 | apt-get -y --no-install-recommends install --fix-missing libcurl4 \ 32 | libcurl4-openssl-dev \ 33 | zip \ 34 | openssl && \ 35 | rm -rf /var/lib/apt/lists/* && \ 36 | curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 37 | 38 | # Install xdebug 39 | RUN pecl install xdebug-3.3.1 && \ 40 | docker-php-ext-enable xdebug && \ 41 | mkdir /var/log/xdebug 42 | 43 | # Install redis 44 | RUN pecl install redis-6.0.2 && \ 45 | docker-php-ext-enable redis 46 | 47 | # Install imagick 48 | RUN apt-get update && \ 49 | apt-get -y --no-install-recommends install --fix-missing libmagickwand-dev && \ 50 | rm -rf /var/lib/apt/lists/* 51 | 52 | # Imagick Commit to install 53 | # https://github.com/Imagick/imagick 54 | ARG IMAGICK_COMMIT="28f27044e435a2b203e32675e942eb8de620ee58" 55 | 56 | RUN cd /usr/local/src && \ 57 | git clone https://github.com/Imagick/imagick && \ 58 | cd imagick && \ 59 | git checkout ${IMAGICK_COMMIT} && \ 60 | phpize && \ 61 | ./configure && \ 62 | make && \ 63 | make install && \ 64 | cd .. && \ 65 | rm -rf imagick && \ 66 | docker-php-ext-enable imagick 67 | 68 | # Other PHP8 Extensions 69 | 70 | RUN docker-php-ext-install pdo_mysql && \ 71 | docker-php-ext-install pdo_sqlite && \ 72 | docker-php-ext-install bcmath && \ 73 | docker-php-ext-install mysqli && \ 74 | docker-php-ext-install curl && \ 75 | docker-php-ext-install zip && \ 76 | docker-php-ext-install -j$(nproc) intl && \ 77 | docker-php-ext-install mbstring && \ 78 | docker-php-ext-install gettext && \ 79 | docker-php-ext-install calendar && \ 80 | docker-php-ext-install exif 81 | 82 | 83 | # Install Freetype 84 | RUN apt-get -y update && \ 85 | apt-get --no-install-recommends install -y libfreetype6-dev \ 86 | libjpeg62-turbo-dev \ 87 | libpng-dev && \ 88 | rm -rf /var/lib/apt/lists/* && \ 89 | docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg && \ 90 | docker-php-ext-install gd 91 | 92 | # Insure an SSL directory exists 93 | RUN mkdir -p /etc/apache2/ssl 94 | 95 | # Enable SSL support 96 | RUN a2enmod ssl && a2enmod rewrite 97 | 98 | # Enable apache modules 99 | RUN a2enmod rewrite headers 100 | 101 | # Cleanup 102 | RUN rm -rf /usr/src/* -------------------------------------------------------------------------------- /config/apache2/custom.conf: -------------------------------------------------------------------------------- 1 | # prefork MPM 2 | # StartServers: number of server processes to start 3 | # MinSpareServers: minimum number of server processes which are kept spare 4 | # MaxSpareServers: maximum number of server processes which are kept spare 5 | # MaxRequestWorkers: maximum number of server processes allowed to start 6 | # MaxConnectionsPerChild: maximum number of requests a server process serves 7 | 8 | 9 | StartServers 30 10 | MinSpareServers 30 11 | MaxSpareServers 50 12 | ServerLimit 1024 13 | MaxClients 1024 14 | MaxConnectionsPerChild 0 15 | -------------------------------------------------------------------------------- /config/mysql/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | max_connections = 1000 3 | interactive_timeout = 30 4 | wait_timeout = 30 5 | sql-mode = "ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" -------------------------------------------------------------------------------- /config/php/php.ini: -------------------------------------------------------------------------------- 1 | memory_limit = 128M 2 | post_max_size = 100M 3 | upload_max_filesize = 20M -------------------------------------------------------------------------------- /config/vhosts/default.conf: -------------------------------------------------------------------------------- 1 | 2 | ServerName localhost 3 | DocumentRoot /var/www/html/default/httpdocs 4 | 5 | 6 | Options Indexes FollowSymLinks MultiViews 7 | AllowOverride All 8 | Require all granted 9 | 10 | 11 | ErrorLog /var/www/html/default/logs/error.log 12 | CustomLog /var/www/html/default/logs/access.log combined 13 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | webserver: 4 | build: 5 | context: ./bin/php8.3-apache 6 | container_name: php8.3-apache 7 | restart: always 8 | ports: 9 | - "80:80" 10 | - "443:443" 11 | volumes: 12 | - ./www:/var/www/html 13 | - ./config/apache2/custom.conf:/etc/apache2/mods-enabled/my.conf 14 | - ./config/php/php.ini:/usr/local/etc/php/php.ini 15 | - ./config/vhosts:/etc/apache2/sites-enabled 16 | - ./logs/apache2:/var/log/apache2 17 | - ./ssl:/etc/letsencrypt 18 | extra_hosts: 19 | - "host.docker.internal:host-gateway" 20 | -------------------------------------------------------------------------------- /mysql/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /node/.gitignore: -------------------------------------------------------------------------------- 1 | !app1 2 | !ecosystem.config.yaml 3 | !.gitignore -------------------------------------------------------------------------------- /node/app1/index.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | http.createServer(function (req, res) { 3 | res.write('Hello World!'); //write a response to the client 4 | res.end(); //end the response 5 | }).listen(3000); //the server object listens on port 8080 -------------------------------------------------------------------------------- /node/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name: "app1", 4 | cwd: "/opt/node/app1/", 5 | script: "index.js", 6 | watch: true, 7 | env: { 8 | NODE_ENV: "development", 9 | }, 10 | env_production: { 11 | NODE_ENV: "production", 12 | } 13 | }] 14 | } -------------------------------------------------------------------------------- /ssl/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /www/default/httpdocs/index.php: -------------------------------------------------------------------------------- 1 |