forked from cloudposse-archives/apache-php-fpm
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDockerfile
107 lines (86 loc) · 4.64 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
FROM ubuntu:16.04
MAINTAINER Andrew Beveridge <[email protected]>
ENV REFRESHED_AT 2017-05-20
ENV HTTPD_PREFIX /etc/apache2
# Suppress warnings from apt about lack of Dialog
ENV DEBIAN_FRONTEND noninteractive
LABEL maintainer="Andrew Beveridge <[email protected]>" \
org.label-schema.docker.dockerfile="/Dockerfile" \
org.label-schema.name="Ubuntu 16.04 with Apache2.4 and PHP 7, optimised using PHP-FPM" \
org.label-schema.url="https://andrewbeveridge.co.uk" \
org.label-schema.vcs-url="https://github.com/beveradb/docker-apache-php7-fpm.git"
# Initial apt update
RUN apt-get update && apt-get install -y apt-utils
# Install common / shared packages
RUN apt-get install -y \
curl \
git \
zip \
unzip \
vim \
locales \
software-properties-common \
python-software-properties
# Set up locales
RUN locale-gen en_US.UTF-8
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8
ENV LC_ALL C.UTF-8
RUN /usr/sbin/update-locale
# Add repository for latest built PHP packages, e.g. 7.1 which isn't otherwise available in Xenial repositories
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update
# Install PHP 7.1 with FPM and other various commonly used modules, including MySQL client
RUN apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \
php7.1-bcmath php7.1-bz2 php7.1-cli php7.1-common php7.1-curl \
php7.1-dev php7.1-fpm php7.1-gd php7.1-gmp php7.1-imap php7.1-intl \
php7.1-json php7.1-ldap php7.1-mbstring php7.1-mcrypt php7.1-mysql \
php7.1-odbc php7.1-opcache php7.1-pgsql php7.1-phpdbg php7.1-pspell \
php7.1-readline php7.1-recode php7.1-soap php7.1-sqlite3 \
php7.1-tidy php7.1-xml php7.1-xmlrpc php7.1-xsl php7.1-zip
# Install Apache2 with FastCGI module and MySQL client for convenience
RUN apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \
apache2 libapache2-mod-fastcgi apache2-utils \
libmysqlclient-dev mariadb-client
# Modify PHP-FPM configuration files to set common properties and listen on socket
RUN sed -i "s/;date.timezone =.*/date.timezone = UTC/" /etc/php/7.1/cli/php.ini
RUN sed -i "s/;date.timezone =.*/date.timezone = UTC/" /etc/php/7.1/fpm/php.ini
RUN sed -i "s/display_errors = Off/display_errors = On/" /etc/php/7.1/fpm/php.ini
RUN sed -i "s/upload_max_filesize = .*/upload_max_filesize = 10M/" /etc/php/7.1/fpm/php.ini
RUN sed -i "s/post_max_size = .*/post_max_size = 12M/" /etc/php/7.1/fpm/php.ini
RUN sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.1/fpm/php.ini
RUN sed -i -e "s/pid =.*/pid = \/var\/run\/php7.1-fpm.pid/" /etc/php/7.1/fpm/php-fpm.conf
RUN sed -i -e "s/error_log =.*/error_log = \/proc\/self\/fd\/2/" /etc/php/7.1/fpm/php-fpm.conf
# RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /etc/php/7.1/fpm/php-fpm.conf
RUN sed -i "s/listen = .*/listen = \/var\/run\/php\/php7.1-fpm.sock/" /etc/php/7.1/fpm/pool.d/www.conf
RUN sed -i "s/;catch_workers_output = .*/catch_workers_output = yes/" /etc/php/7.1/fpm/pool.d/www.conf
# Install Composer globally
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer \
&& chmod a+x /usr/local/bin/composer
# Remove default Apache VirtualHost, configs, and mods not needed
WORKDIR $HTTPD_PREFIX
RUN rm -f \
sites-enabled/000-default.conf \
conf-enabled/serve-cgi-bin.conf \
mods-enabled/autoindex.conf \
mods-enabled/autoindex.load
# Enable additional configs and mods
RUN ln -s $HTTPD_PREFIX/mods-available/expires.load $HTTPD_PREFIX/mods-enabled/expires.load \
&& ln -s $HTTPD_PREFIX/mods-available/headers.load $HTTPD_PREFIX/mods-enabled/headers.load \
&& ln -s $HTTPD_PREFIX/mods-available/rewrite.load $HTTPD_PREFIX/mods-enabled/rewrite.load
# Configure Apache to use our PHP-FPM socket for all PHP files
COPY php7.1-fpm.conf /etc/apache2/conf-available/php7.1-fpm.conf
RUN a2enconf php7.1-fpm
# Enable Apache modules and configuration
RUN a2dismod mpm_event
RUN a2enmod alias actions fastcgi proxy_fcgi setenvif mpm_worker
# Clean up apt cache and temp files to save disk space
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Symlink apache access and error logs to stdout/stderr so Docker logs shows them
RUN ln -sf /dev/stdout /var/log/apache2/access.log
RUN ln -sf /dev/stdout /var/log/apache2/other_vhosts_access.log
RUN ln -sf /dev/stderr /var/log/apache2/error.log
EXPOSE 80
# Start PHP-FPM worker service and run Apache in foreground so any error output is sent to stdout for Docker logs
CMD service php7.1-fpm start && /usr/sbin/apache2ctl -D FOREGROUND