├── Dockerfile ├── LICENSE └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/baseimage:0.9.19 2 | 3 | MAINTAINER Ahumaro Mendoza 4 | 5 | CMD ["/sbin/my_init"] 6 | 7 | ENV HOME /root 8 | ENV DEBIAN_FRONTEND noninteractive 9 | 10 | #Install core packages 11 | RUN apt-get update -q 12 | RUN apt-get upgrade -y -q 13 | RUN apt-get install -y -q php php-cli php-fpm php-gd php-curl php-apcu php-xml php-mbstring php-zip ca-certificates nginx git-core 14 | RUN apt-get clean -q && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 15 | 16 | #Get Grav 17 | RUN rm -fR /usr/share/nginx/html/ 18 | RUN git clone https://github.com/getgrav/grav.git /usr/share/nginx/html/ 19 | 20 | #Install Grav 21 | WORKDIR /usr/share/nginx/html/ 22 | RUN bin/composer.phar self-update 23 | RUN bin/grav install 24 | RUN chown -R www-data:www-data * 25 | RUN find . -type f | xargs chmod 664 26 | RUN find . -type d | xargs chmod 775 27 | RUN find . -type d | xargs chmod +s 28 | RUN umask 0002 29 | 30 | #Configure Nginx - enable gzip 31 | RUN sed -i 's|# gzip_types| gzip_types|' /etc/nginx/nginx.conf 32 | 33 | #Setup Grav configuration for Nginx 34 | RUN touch /etc/nginx/grav_conf.sh 35 | RUN chmod +x /etc/nginx/grav_conf.sh 36 | RUN echo '#!/bin/bash \n\ 37 | echo "" > /etc/nginx/sites-available/default \n\ 38 | ok="0" \n\ 39 | while IFS="" read line \n\ 40 | do \n\ 41 | if [ "$line" = "server {" ]; then \n\ 42 | ok="1" \n\ 43 | fi \n\ 44 | if [ "$ok" = "1" ]; then \n\ 45 | echo "$line" >> /etc/nginx/sites-available/default \n\ 46 | fi \n\ 47 | if [ "$line" = "}" ]; then \n\ 48 | ok="0" \n\ 49 | fi \n\ 50 | done < /usr/share/nginx/html/webserver-configs/nginx.conf' >> /etc/nginx/grav_conf.sh 51 | RUN /etc/nginx/grav_conf.sh 52 | RUN sed -i \ 53 | -e 's|root /home/USER/www/html|root /usr/share/nginx/html|' \ 54 | -e 's|unix:/var/run/php5-fpm.sock;|unix:/run/php/php7.0-fpm.sock;|' \ 55 | /etc/nginx/sites-available/default 56 | 57 | #Setup Php service 58 | RUN mkdir -p /run/php/ 59 | RUN touch /run/php/php7.0-fpm.sock 60 | RUN mkdir -p /etc/service/php-fpm 61 | RUN touch /etc/service/php-fpm/run 62 | RUN chmod +x /etc/service/php-fpm/run 63 | RUN echo '#!/bin/bash \n\ 64 | exec /usr/sbin/php-fpm7.0 -F' >> /etc/service/php-fpm/run 65 | 66 | #Setup Nginx service 67 | RUN mkdir -p /etc/service/nginx 68 | RUN touch /etc/service/nginx/run 69 | RUN chmod +x /etc/service/nginx/run 70 | RUN echo '#!/bin/bash \n\ 71 | exec /usr/sbin/nginx -g "daemon off;"' >> /etc/service/nginx/run 72 | 73 | #Setup SSH service 74 | RUN sed -i \ 75 | -e 's|#PasswordAuthentication no|PasswordAuthentication no|' \ 76 | -e 's|#UsePAM yes|UsePAM no|' \ 77 | /etc/ssh/sshd_config 78 | RUN rm -f /etc/service/sshd/down 79 | RUN /etc/my_init.d/00_regen_ssh_host_keys.sh 80 | 81 | #Expose configuration and content volumes 82 | VOLUME /root/.ssh/ /etc/nginx/ /usr/share/nginx/html/ 83 | 84 | #Public ports 85 | EXPOSE 80 22 86 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ahumaro Mendoza 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Grav-PHP-Nginx 2 | 3 | ## A modern approach for a lightweight yet efficient CMS 4 | 5 | ### At a glance 6 | 7 | This aproach for a lightweight Content Management System stack includes four main parts: 8 | 9 | + **Grav** as the lightweight _flat-file_ Content Management System. 10 | + **Nginx** as a fast and eficient webserver. 11 | + **PHP-FPM** as the FastCGI engine. 12 | + **Pushion** as the minimal linux container for this stack. 13 | 14 | The idea behind this solution is to have a very light and small footprint CMS that can run efficiently in a flexible environment. 15 | 16 | ### How to use it 17 | 18 | Its very important to note this container expose 3 volumes and 2 ports. 19 | You should properly map the ports when you run the container. 20 | 21 | 1. Run the container: 22 | 23 | **docker run -d -i -p 80:80 -p 2222:22 ahumaro/grav-php-nginx** 24 | 25 | The previous command run the container. If the container it not already in your system, it downloads the image from the Docker Hub. 26 | 27 | Two ports are mapped. In the example above, we are mapping port 80 in the host to the port 80 in the container. Also port 2222 in the host to port 22 in the container (This port can be used to access the container via SSH). 28 | 29 | 2. Test Grav site 30 | 31 | Just point your browser to **`http://your_server/`** and you are done. 32 | 33 | You can inspect your new running container to find out the location of the 3 volumes the container is exposing: 34 | + Volume **/usr/share/nginx/html/** 35 | 36 | Here you can find the Grav home folder where you can add and manage your content. 37 | 38 | + Volume **/etc/nginx/** 39 | 40 | (Optional) Here you can tweak Nginx configuration and sites 41 | 42 | + Volume **/root/.ssh/** 43 | 44 | (Optional) Here you can put your **public** key so you can access container via SSH. After that, open a SSH connection to root@your_server:2222 specifying your **private** key. 45 | 46 | ### Components 47 | 48 | **Grav** is a very fast and simple solution for a CMS. It use flat files to store content. Installation is very simple and is much more easy and light than other CMS's like Drupal or Joomla. 49 | Also is worth to mention that is a very well documented piece of software. 50 | 51 | **Nginx** is a webserver very light and efficient that is strong focused in a small memory footprint and high concurrency and performance. 52 | Also it can be configured as a reverse proxy to handle and solve many scenarios and, in conjunction with **PHP-FPM**, is the way to go to handle and enhance this CMS solution. 53 | 54 | **Pushion** base Docker container is a minimal Ubuntu base image modified and minified to be a lightweight Docker compatible container. 55 | The container is enhanced with key features like the ability to handle SSH access to the container and the ability to add additional daemons that run at the startup time of the container. 56 | 57 | ### Container philosophy 58 | 59 | In theory, the use of Docker and containers encourage the one process per container approach but, from the point of view of software as a service, this new container is focused in the one service per container philosophy. 60 | 61 | ### Dockerfile 62 | 63 | The definition for this new **Grav-PHP-Nginx** container perfirm several tasks at build time: 64 | 65 | + Define the base image as **phusion/baseimage:0.9.19**, an excelent minified Ubuntu 16.04 LTS Docker container. 66 | + Install and update the core components for this new container like Nginx, PHP-FPM, etc. 67 | + Get Grav up-to-date files from its GIT repository. 68 | + Run Grav install scripts. 69 | + Setup Nginx and Grav configuration site. 70 | + Setup PHP-FPM, Nginx and SSH services. 71 | + Expose Volumes and ports. 72 | 73 | This Docker container is ready and preconfigured. Just download and use it. 74 | 75 | ### Enjoy this container! 76 | ## Ahumaro Mendoza 77 | 78 | ahumaro@ahumaro.com 79 | 80 | www.ahumaro.com 81 | --------------------------------------------------------------------------------