├── Dockerfile.apache ├── apache2-foreground ├── docker-php-ext-configure ├── docker-php-ext-install ├── LICENSE ├── apache2.conf ├── docker-php-ext-enable ├── README.md └── Dockerfile /Dockerfile.apache: -------------------------------------------------------------------------------- 1 | FROM draggho/docker-php5.3:base-0.0.2 2 | 3 | ARG DEBIAN_FRONTEND=noninteractive 4 | 5 | RUN a2enmod deflate env headers rewrite -------------------------------------------------------------------------------- /apache2-foreground: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Apache gets grumpy about PID files pre-existing 5 | rm -f /var/run/apache2/apache2.pid 6 | 7 | # sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf 8 | a2enmod rewrite 9 | 10 | exec apache2 -DFOREGROUND 11 | -------------------------------------------------------------------------------- /docker-php-ext-configure: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | ext="$1" 5 | extDir="/usr/src/php/ext/$ext" 6 | if [ -z "$ext" -o ! -d "$extDir" ]; then 7 | echo >&2 "usage: $0 ext-name [configure flags]" 8 | echo >&2 " ie: $0 gd --with-jpeg-dir=/usr/local/something" 9 | echo >&2 10 | echo >&2 'Possible values for ext-name:' 11 | echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort) 12 | exit 1 13 | fi 14 | shift 15 | 16 | set -x 17 | cd "$extDir" 18 | phpize 19 | ./configure "$@" 20 | -------------------------------------------------------------------------------- /docker-php-ext-install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | cd /usr/src/php/ext 5 | 6 | usage() { 7 | echo "usage: $0 ext-name [ext-name ...]" 8 | echo " ie: $0 gd mysqli" 9 | echo " $0 pdo pdo_mysql" 10 | echo 11 | echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure' 12 | echo 13 | echo 'Possible values for ext-name:' 14 | echo $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort) 15 | } 16 | 17 | exts=() 18 | while [ $# -gt 0 ]; do 19 | ext="$1" 20 | shift 21 | if [ -z "$ext" ]; then 22 | continue 23 | fi 24 | if [ ! -d "$ext" ]; then 25 | echo >&2 "error: $(pwd -P)/$ext does not exist" 26 | echo >&2 27 | usage >&2 28 | exit 1 29 | fi 30 | exts+=( "$ext" ) 31 | done 32 | 33 | if [ "${#exts[@]}" -eq 0 ]; then 34 | usage >&2 35 | exit 1 36 | fi 37 | 38 | for ext in "${exts[@]}"; do 39 | ( 40 | cd "$ext" 41 | [ -e Makefile ] || docker-php-ext-configure "$ext" 42 | make 43 | make install 44 | find modules -maxdepth 1 -name '*.so' -exec basename '{}' ';' | xargs --no-run-if-empty --verbose docker-php-ext-enable 45 | make clean 46 | ) 47 | done 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Helder Correia 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 | -------------------------------------------------------------------------------- /apache2.conf: -------------------------------------------------------------------------------- 1 | # see http://sources.debian.net/src/apache2/2.4.10-1/debian/config-dir/apache2.conf 2 | 3 | Mutex file:/var/lock/apache2 default 4 | PidFile /var/run/apache2/apache2.pid 5 | Timeout 300 6 | KeepAlive On 7 | MaxKeepAliveRequests 100 8 | KeepAliveTimeout 5 9 | User www-data 10 | Group www-data 11 | HostnameLookups Off 12 | ErrorLog /proc/self/fd/2 13 | LogLevel warn 14 | ServerName localhost 15 | 16 | IncludeOptional mods-enabled/*.load 17 | IncludeOptional mods-enabled/*.conf 18 | 19 | # ports.conf 20 | Listen 80 21 | 22 | Listen 443 23 | 24 | 25 | Listen 443 26 | 27 | 28 | 29 | Options FollowSymLinks 30 | AllowOverride All 31 | Require all denied 32 | 33 | 34 | 35 | Options Indexes FollowSymLinks 36 | AllowOverride All 37 | Require all granted 38 | 39 | 40 | AccessFileName .htaccess 41 | 42 | Require all denied 43 | 44 | 45 | LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined 46 | LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined 47 | LogFormat "%h %l %u %t \"%r\" %>s %O" common 48 | LogFormat "%{Referer}i -> %U" referer 49 | LogFormat "%{User-agent}i" agent 50 | 51 | CustomLog /proc/self/fd/1 combined 52 | 53 | 54 | SetHandler application/x-httpd-php 55 | 56 | DirectoryIndex index.php 57 | 58 | DocumentRoot /var/www/html 59 | -------------------------------------------------------------------------------- /docker-php-ext-enable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | cd "$(php -r 'echo ini_get("extension_dir");')" 5 | 6 | usage() { 7 | echo "usage: $0 module-name [module-name ...]" 8 | echo " ie: $0 gd mysqli" 9 | echo " $0 pdo pdo_mysql" 10 | echo 11 | echo 'Possible values for module-name:' 12 | echo $(find -maxdepth 1 -type f -name '*.so' -exec basename '{}' ';' | sort) 13 | } 14 | 15 | modules=() 16 | while [ $# -gt 0 ]; do 17 | module="$1" 18 | shift 19 | if [ -z "$module" ]; then 20 | continue 21 | fi 22 | if [ -f "$module.so" -a ! -f "$module" ]; then 23 | # allow ".so" to be optional 24 | module+='.so' 25 | fi 26 | if [ ! -f "$module" ]; then 27 | echo >&2 "error: $(readlink -f "$module") does not exist" 28 | echo >&2 29 | usage >&2 30 | exit 1 31 | fi 32 | modules+=( "$module" ) 33 | done 34 | 35 | if [ "${#modules[@]}" -eq 0 ]; then 36 | usage >&2 37 | exit 1 38 | fi 39 | 40 | for module in "${modules[@]}"; do 41 | if grep -q zend_extension_entry "$module"; then 42 | # https://wiki.php.net/internals/extensions#loading_zend_extensions 43 | line="zend_extension=$(readlink -f "$module")" 44 | else 45 | line="extension=$module" 46 | fi 47 | 48 | ext="$(basename "$module")" 49 | ext="${ext%.*}" 50 | if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then 51 | # this isn't perfect, but it's better than nothing 52 | # (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache') 53 | echo >&2 54 | echo >&2 "warning: $ext ($module) is already loaded!" 55 | echo >&2 56 | continue 57 | fi 58 | 59 | ini="/usr/local/etc/php/conf.d/docker-php-ext-$ext.ini" 60 | if ! grep -q "$line" "$ini" 2>/dev/null; then 61 | echo "$line" >> "$ini" 62 | fi 63 | done 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP 5.3 Apache 2 | 3 | PHP 5.3 [reached EOL](http://php.net/eol.php) on 14 Aug 2014 and thus, official docker support was [dropped](https://github.com/docker-library/php/pull/20). I still needed to run 5.3 so I built this image based on the latest official builds of PHP. 4 | 5 | # What is PHP? 6 | 7 | PHP is a server-side scripting language designed for web development, but which can also be used as a general-purpose programming language. PHP can be added to straight HTML or it can be used with a variety of templating engines and web frameworks. PHP code is usually processed by an interpreter, which is either implemented as a native module on the web-server or as a common gateway interface (CGI). 8 | 9 | > [wikipedia.org/wiki/PHP](http://en.wikipedia.org/wiki/PHP) 10 | 11 | ![logo](https://raw.githubusercontent.com/docker-library/docs/master/php/logo.png) 12 | 13 | # How to use this image. 14 | 15 | ## With Command Line 16 | 17 | For PHP projects run through the command line interface (CLI), you can do the following. 18 | 19 | ### Create a `Dockerfile` in your PHP project 20 | 21 | FROM orsolin/php:5.3-apache 22 | COPY . /usr/src/myapp 23 | WORKDIR /usr/src/myapp 24 | CMD [ "php", "./your-script.php" ] 25 | 26 | Then, run the commands to build and run the Docker image: 27 | 28 | docker build -t my-php-app . 29 | docker run -it --rm --name my-running-app my-php-app 30 | 31 | ### Run a single PHP script 32 | 33 | For many simple, single file projects, you may find it inconvenient to write a complete `Dockerfile`. In such cases, you can run a PHP script by using the PHP Docker image directly: 34 | 35 | docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp orsolin/php:5.3-apache php your-script.php 36 | 37 | ### Installing modules 38 | 39 | To install additional modules use a `Dockerfile` like this: 40 | 41 | ``` Dockerfile 42 | FROM orsolin/php:5.3-apache 43 | 44 | # Installs curl 45 | RUN docker-php-ext-install curl 46 | ``` 47 | 48 | Then build the image: 49 | 50 | ``` bash 51 | $ docker build -t my-php . 52 | ``` 53 | 54 | ### Without a `Dockerfile` 55 | 56 | If you don't want to include a `Dockerfile` in your project, it is sufficient to do the following: 57 | 58 | docker run -it --rm --name my-php-app -v "$PWD":/var/www/html orsolin/php:5.3-apache 59 | 60 | ## Credits 61 | 62 | A big credit to [helderco](https://github.com/helderco/docker-php-5.3) for the `fpm` version 63 | of this image. 64 | 65 | # License 66 | 67 | View [license information](http://php.net/license/) for the software contained in this image. 68 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:jessie 2 | 3 | # persistent / runtime deps 4 | RUN apt-get update && apt-get install -y --no-install-recommends \ 5 | ca-certificates \ 6 | curl \ 7 | libjpeg62-turbo-dev \ 8 | librecode0 \ 9 | libmysqlclient-dev \ 10 | libsqlite3-0 \ 11 | libxml2 \ 12 | && apt-get clean \ 13 | && rm -r /var/lib/apt/lists/* 14 | 15 | # phpize deps 16 | RUN apt-get update && apt-get install -y --no-install-recommends \ 17 | autoconf \ 18 | file \ 19 | g++ \ 20 | gcc \ 21 | libc-dev \ 22 | make \ 23 | pkg-config \ 24 | re2c \ 25 | && apt-get clean \ 26 | && rm -r /var/lib/apt/lists/* 27 | 28 | #### 29 | RUN apt-get update && apt-get install -y apache2-bin apache2-dev apache2.2-common --no-install-recommends && rm -rf /var/lib/apt/lists/* 30 | 31 | RUN rm -rf /var/www/html && mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html && chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html 32 | 33 | # Apache + PHP requires preforking Apache for best results 34 | RUN a2dismod mpm_event && a2enmod mpm_prefork 35 | 36 | RUN mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.dist 37 | COPY apache2.conf /etc/apache2/apache2.conf 38 | #### 39 | 40 | ENV PHP_INI_DIR /etc/php5/apache2 41 | RUN mkdir -p $PHP_INI_DIR/conf.d 42 | 43 | ENV GPG_KEYS 8657ABB260F056B1E5190839D9C4D26D0E604491 0A95E9A026542D53835E3F3A7DEC4E69FC9C83D7 0E604491 44 | RUN set -xe \ 45 | && for key in $GPG_KEYS; do \ 46 | gpg --keyserver pool.sks-keyservers.net --recv-keys "$key"; \ 47 | done 48 | 49 | # compile openssl, otherwise --with-openssl won't work 50 | RUN CFLAGS="-fPIC" && OPENSSL_VERSION="1.0.2d" \ 51 | && cd /tmp \ 52 | && mkdir openssl \ 53 | && curl -sL "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" -o openssl.tar.gz \ 54 | && curl -sL "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz.asc" -o openssl.tar.gz.asc \ 55 | && gpg --verify openssl.tar.gz.asc \ 56 | && tar -xzf openssl.tar.gz -C openssl --strip-components=1 \ 57 | && cd /tmp/openssl \ 58 | && ./config -fPIC && make && make install \ 59 | && rm -rf /tmp/* 60 | 61 | ENV PHP_VERSION 5.3.29 62 | 63 | # php 5.3 needs older autoconf 64 | # --enable-mysqlnd is included below because it's harder to compile after the fact the extensions are (since it's a plugin for several extensions, not an extension in itself) 65 | RUN buildDeps=" \ 66 | apache2-dev \ 67 | autoconf2.13 \ 68 | libcurl4-openssl-dev \ 69 | libreadline6-dev \ 70 | librecode-dev \ 71 | libsqlite3-dev \ 72 | libssl-dev \ 73 | libxml2-dev \ 74 | libpng-dev \ 75 | xz-utils \ 76 | " \ 77 | && set -x \ 78 | && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \ 79 | && curl -SL "http://php.net/get/php-$PHP_VERSION.tar.xz/from/this/mirror" -o php.tar.xz \ 80 | && curl -SL "http://php.net/get/php-$PHP_VERSION.tar.xz.asc/from/this/mirror" -o php.tar.xz.asc \ 81 | && gpg --verify php.tar.xz.asc \ 82 | && mkdir -p /usr/src/php \ 83 | && tar -xof php.tar.xz -C /usr/src/php --strip-components=1 \ 84 | && rm php.tar.xz* \ 85 | && cd /usr/src/php \ 86 | && ./configure --disable-cgi \ 87 | $(command -v apxs2 > /dev/null 2>&1 && echo '--with-apxs2=/usr/bin/apxs2' || true) \ 88 | --with-config-file-path="$PHP_INI_DIR" \ 89 | --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \ 90 | --with-jpeg-dir=/usr/lib \ 91 | --enable-ftp \ 92 | --enable-mbstring \ 93 | --enable-mysqlnd \ 94 | --with-mysql \ 95 | --with-mysqli \ 96 | --with-pdo-mysql \ 97 | --with-curl \ 98 | --with-openssl=/usr/local/ssl \ 99 | --enable-soap \ 100 | --with-png \ 101 | --with-gd \ 102 | --with-readline \ 103 | --with-recode \ 104 | --with-zlib \ 105 | && make -j"$(nproc)" \ 106 | && make install \ 107 | && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \ 108 | && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps \ 109 | && make clean 110 | 111 | RUN echo "default_charset = " > $PHP_INI_DIR/php.ini \ 112 | && echo "date.timezone = America/Sao_Paulo" >> $PHP_INI_DIR/php.ini 113 | 114 | COPY docker-php-* /usr/local/bin/ 115 | COPY apache2-foreground /usr/local/bin/ 116 | 117 | WORKDIR /var/www/html 118 | 119 | EXPOSE 80 120 | CMD ["apache2-foreground"] 121 | --------------------------------------------------------------------------------