diff --git a/Dockerfile b/Dockerfile index 32bb260..15cf9a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,19 @@ -FROM ubuntu:14.10 +FROM ubuntu:14.04 + MAINTAINER outer/edge -ENV DEBIAN_FRONTEND noninteractive -ENV HOME /root +COPY build.sh /build.sh +RUN /build.sh -# Install Default Packages -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - curl nano wget software-properties-common \ - ruby nodejs-legacy npm git-core apache2 libapache2-mod-php5 \ - php5-cli php5-mysql php5-sqlite php5-curl php5-intl && \ - apt-get clean && \ - rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* +COPY nginx.conf /etc/nginx/nginx.conf +COPY nginx-default /etc/nginx/conf.d/default +COPY php-fpm.conf /usr/local/etc/php-fpm.conf +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf -# Install composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -# Install bower -RUN npm install -g bower && npm cache clean - -# Setup apache -RUN a2enmod rewrite -ADD apache.conf /etc/apache2/sites-enabled/000-default.conf -ADD apache.sh /apache.sh -RUN chmod +x /apache.sh - -# Cache -VOLUME ["/root/.composer"] +EXPOSE 80 WORKDIR /var/www -EXPOSE 80 -CMD ["/apache.sh"] \ No newline at end of file +CMD ["/usr/bin/supervisord"] \ No newline at end of file diff --git a/LICENSE b/LICENSE index 999cf6f..5133bdd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 outer/edge +Copyright (c) 2015 outer/edge Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 33c8929..bc5764c 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,4 @@ -edge-docker-php -=============== +# edge-docker-php +Ubuntu 14.04 running Nginx 1.7 with Pagespeed and PHP 5.6 -Base docker image for running PHP web applications. - -Included packages ------------------ - - * Apache 2.4 - * PHP (mysql, sqlite, curl, intl) - * Ruby - * Node.js - * Git - -#### Package managers - - * Composer - * Rubygems - * Npm - * Bower +## Adding PHP extensions \ No newline at end of file diff --git a/apache.conf b/apache.conf deleted file mode 100644 index 1407cde..0000000 --- a/apache.conf +++ /dev/null @@ -1,11 +0,0 @@ - - DocumentRoot /var/www/public - - - AllowOverride all - Require all granted - - - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined - \ No newline at end of file diff --git a/apache.sh b/apache.sh deleted file mode 100644 index 23a8c3b..0000000 --- a/apache.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -source /etc/apache2/envvars -exec /usr/sbin/apache2 -D FOREGROUND \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..3008ee2 --- /dev/null +++ b/build.sh @@ -0,0 +1,71 @@ +#!/bin/bash +set -e + +NGINX_VERSION=1.7.10 +NPS_VERSION=1.9.32.3 +PHP_VERSION=5.6.7 + +DEBIAN_FRONTEND=noninteractive + +# build apt cache +apt-get update + +# install basic tools +apt-get install -y --no-install-recommends build-essential curl nano wget git-core ca-certificates supervisor + +# download ngx_pagespeed +apt-get install -y --no-install-recommends zlib1g-dev libpcre3-dev libssl-dev +mkdir /tmp/ngx_pagespeed +wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.tar.gz -O - | tar -zxf - --strip=1 -C /tmp/ngx_pagespeed +wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz -O - | tar -zxf - -C /tmp/ngx_pagespeed + +# download and install nginx +mkdir /tmp/nginx +wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -O - | tar -zxf - -C /tmp/nginx --strip=1 +cd /tmp/nginx +./configure \ + --prefix=/etc/nginx/ \ + --conf-path=/etc/nginx/nginx.conf \ + --sbin-path=/usr/sbin/nginx \ + --user=www-data \ + --group=www-data \ + --with-http_ssl_module \ + --with-http_spdy_module \ + --add-module=/tmp/ngx_pagespeed +make -j"$(nproc)" +make install +mkdir -p /etc/nginx/conf.d +mkdir -p -m 755 /var/cache/pagespeed +chown -R www-data:www-data /var/cache/pagespeed + +# download and install php +apt-get install -y --no-install-recommends libcurl4-openssl-dev libreadline6-dev libmcrypt-dev libxml2-dev libpng-dev libicu-dev +mkdir /tmp/php +wget http://php.net/get/php-$PHP_VERSION.tar.bz2/from/this/mirror -O - | tar -jxf - -C /tmp/php --strip=1 +cd /tmp/php +./configure \ + --with-config-file-path="/usr/local/etc/php" \ + --with-libdir=/lib/x86_64-linux-gnu \ + --with-fpm-user=www-data \ + --with-fpm-group=www-data \ + --disable-cgi \ + --enable-fpm \ + --enable-intl \ + --enable-mbstring \ + --enable-mysqlnd \ + --enable-opcache \ + --enable-zip \ + --with-curl \ + --with-openssl \ + --with-readline \ + --with-pdo-mysql \ + --with-mcrypt \ + --with-gd=shared +make -j"$(nproc)" +make install + +# cleanup +apt-get purge -y build-essential g++ +apt-get autoremove -y +apt-get clean +rm -rf /tmp/* /var/lib/apt/lists/* \ No newline at end of file diff --git a/nginx-default b/nginx-default new file mode 100644 index 0000000..2f74272 --- /dev/null +++ b/nginx-default @@ -0,0 +1,25 @@ +server { + listen 80; + root /var/www/public/; + + charset utf-8; + + #https://developers.google.com/speed/pagespeed/module/configuration + #pagespeed on; + + location / { + try_files $uri =404; + + fastcgi_index index.php; + fastcgi_pass unix:/var/run/php-fpm.sock; + include fastcgi.conf; + } + + location = /favicon.ico { log_not_found off; access_log off; } + location = /robots.txt { log_not_found off; access_log off; } + + # Deny .htaccess file access + location ~ /\.ht { + deny all; + } +} \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..c94bd02 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,27 @@ +worker_processes auto; +daemon off; +error_log stderr warn; + +events { + worker_connections 1024; +} + +http { + server_tokens off; + access_log off; + + include mime.types; + default_type application/octet-stream; + + keepalive_timeout 65; + + gzip on; + gzip_vary on; + + index index.php; + + pagespeed off; + pagespeed FileCachePath /var/cache/pagespeed; # Use tmpfs for best results + + include /etc/nginx/conf.d/*; +} \ No newline at end of file diff --git a/php-fpm.conf b/php-fpm.conf new file mode 100644 index 0000000..f7a763a --- /dev/null +++ b/php-fpm.conf @@ -0,0 +1,21 @@ +[global] + +daemonize = no +error_log = stderr + +[www] + +user = www-data +group = www-data + +listen = 127.0.0.1:9000 + +pm = dynamic +pm.max_children = 20 +pm.min_spare_servers = 2 +pm.max_spare_servers = 10 +pm.max_requests = 5000 + +clear_env = no + +catch_workers_output = yes \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..49af7fb --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon=true + +[program:nginx] +command=nginx +redirect_stderr=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 + +[program:php-fpm] +command=php-fpm +redirect_stderr=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0