├── 99-xdebug.ini.disabled ├── 999-php.ini ├── Dockerfile ├── README.md ├── index.php └── start /99-xdebug.ini.disabled: -------------------------------------------------------------------------------- 1 | [xdebug] 2 | xdebug.remote_enable=on 3 | xdebug.default_enable=on 4 | xdebug.remote_autostart=off 5 | xdebug.remote_port=9000 6 | xdebug.profiler_enable_trigger=1 7 | xdebug.profiler_output_name=xdebug-profile-cachegrind.out-%H-%R 8 | xdebug.var_display_max_children = 128 9 | xdebug.var_display_max_data = 2048 10 | xdebug.var_display_max_depth = 128 11 | xdebug.max_nesting_level = 200 12 | xdebug.coverage_enable = 1 13 | -------------------------------------------------------------------------------- /999-php.ini: -------------------------------------------------------------------------------- 1 | memory_limit = -1 2 | error_reporting = E_ALL | E_STRICT 3 | max_execution_time = 0 4 | max_input_time = 0 5 | post_max_size = 100M 6 | upload_max_filesize = 100M -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.0-apache 2 | MAINTAINER Webgriffe Srl 3 | 4 | # Install GD 5 | RUN apt-get update \ 6 | && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng16-16 \ 7 | && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \ 8 | && docker-php-ext-install gd 9 | 10 | # Install MCrypt 11 | RUN apt-get update \ 12 | && apt-get install -y libmcrypt-dev \ 13 | && pecl install mcrypt-1.0.4 \ 14 | && docker-php-ext-enable mcrypt 15 | 16 | # Install Intl 17 | RUN apt-get update \ 18 | && apt-get install -y libicu-dev \ 19 | && docker-php-ext-install intl 20 | 21 | ENV XDEBUG_ENABLE 0 22 | RUN pecl config-set preferred_state beta \ 23 | && pecl install -o -f xdebug-3.0.0 \ 24 | && rm -rf /tmp/pear \ 25 | && pecl config-set preferred_state stable 26 | COPY ./99-xdebug.ini.disabled /usr/local/etc/php/conf.d/ 27 | 28 | # Install Mysql 29 | RUN docker-php-ext-install mysqli pdo_mysql 30 | 31 | # Install Composer 32 | RUN curl -sS https://getcomposer.org/installer | php \ 33 | && mv composer.phar /usr/local/bin/composer 34 | 35 | # Install Oniguruma 36 | RUN apt-get update \ 37 | && apt-get install -y libonig-dev 38 | 39 | # Install mbstring 40 | RUN docker-php-ext-install mbstring 41 | 42 | # Install soap 43 | RUN apt-get update \ 44 | && apt-get install -y libxml2-dev \ 45 | && docker-php-ext-install soap 46 | 47 | # Install opcache 48 | RUN docker-php-ext-install opcache 49 | 50 | # Install PHP zip extension 51 | RUN apt-get update \ 52 | && apt-get install -y libzip-dev \ 53 | && docker-php-ext-install zip 54 | 55 | # Install Git 56 | RUN apt-get update \ 57 | && apt-get install -y git 58 | 59 | # Install xsl 60 | RUN apt-get update \ 61 | && apt-get install -y libxslt-dev \ 62 | && docker-php-ext-install xsl 63 | 64 | # Define PHP_TIMEZONE env variable 65 | ENV PHP_TIMEZONE Europe/Rome 66 | 67 | # Configure Apache Document Root 68 | ENV APACHE_DOC_ROOT /var/www/html 69 | 70 | # Configure Apache ServerName 71 | ENV APACHE_SERVER_NAME localhost 72 | 73 | # Enable Apache mod_rewrite 74 | RUN a2enmod rewrite 75 | 76 | # Additional PHP ini configuration 77 | COPY ./999-php.ini /usr/local/etc/php/conf.d/ 78 | 79 | COPY ./index.php /var/www/html/index.php 80 | 81 | # Install ssmtp Mail Transfer Agent 82 | RUN apt-get update \ 83 | && apt-get install -y ssmtp \ 84 | && apt-get clean \ 85 | && echo "FromLineOverride=YES" >> /etc/ssmtp/ssmtp.conf \ 86 | && echo 'sendmail_path = "/usr/sbin/ssmtp -t"' > /usr/local/etc/php/conf.d/mail.ini 87 | 88 | # Install imap 89 | RUN apt-get update \ 90 | && apt-get install -y libc-client-dev libkrb5-dev \ 91 | && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \ 92 | && docker-php-ext-install imap 93 | 94 | # Install MySQL CLI Client 95 | RUN apt-get update \ 96 | && apt-get install -y default-mysql-client 97 | 98 | ######################################################################################################################## 99 | 100 | # Start! 101 | COPY ./start /usr/local/bin/ 102 | CMD ["start"] 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Base PHP with Apache Docker Container 2 | ===================================== 3 | 4 | [![](https://images.microbadger.com/badges/version/webgriffe/php-apache-base.svg)](http://microbadger.com/images/webgriffe/php-apache-base "Get your own version badge on microbadger.com") 5 | [![](https://images.microbadger.com/badges/image/webgriffe/php-apache-base.svg)](http://microbadger.com/images/webgriffe/php-apache-base "Get your own version badge on microbadger.com") 6 | 7 | Dockerized environment for PHP web development and Apache web server. 8 | 9 | Features 10 | -------- 11 | 12 | * Ability to set Apache document root through `APACHE_DOC_ROOT` environment variable. Default document root is `/var/www/html` 13 | * Enabled Apache modules: rewrite 14 | * Ability to set PHP `date.timezone` through `PHP_TIMEZONE` environment variable. Default timezone is `Europe/Rome` 15 | * Enabled PHP extensions: gd, mcrypt, intl, mysql, mysqli, pdo_mysql, mbstring, soap, opcache, zip, xls 16 | * Composer installed globally at `/usr/local/bin/composer` 17 | * Xdebug PHP extension installed but not enabled 18 | * Ability to enable xdebug PHP extension through `XDEBUG_ENABLE` environment variable which has to be set to `1` 19 | * Ability to set xdebug.remote_enable setting through `HOST_IP` environment variable. 20 | * GIT installed (required by Composer) 21 | * sSMTP installed (as Mail Transfer Agent for PHP mail function) 22 | * Ability to set sSMTP mailhub, AuthUser and AuthPass through `SSMTP_MAILHUB`, `SSMTP_AUTH_USER` and `SSMTP_AUTH_PASS` environment variables 23 | * MySQL CLI Client installed 24 | 25 | Usage 26 | ----- 27 | 28 | Standalone usage example with host's current working directory as document root: 29 | 30 | $ docker run -p 80:80 -v $(pwd):/var/www/html webgriffe/php-apache-base 31 | 32 | Credits 33 | ------- 34 | 35 | [Webgriffe®](http://www.webgriffe.com/) 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | /usr/local/etc/php/conf.d/timezone.ini 7 | 8 | # Configure Apache Document Root 9 | mkdir -p $APACHE_DOC_ROOT 10 | chown www-data:www-data $APACHE_DOC_ROOT 11 | sed -i "s|DocumentRoot /var/www/html\$|DocumentRoot $APACHE_DOC_ROOT|" /etc/apache2/sites-available/000-default.conf 12 | echo "" > /etc/apache2/conf-available/document-root-directory.conf 13 | echo " AllowOverride All" >> /etc/apache2/conf-available/document-root-directory.conf 14 | echo " Require all granted" >> /etc/apache2/conf-available/document-root-directory.conf 15 | echo "" >> /etc/apache2/conf-available/document-root-directory.conf 16 | a2enconf "document-root-directory.conf" 17 | 18 | # Set ServerName Directive 19 | echo "ServerName $APACHE_SERVER_NAME" > /etc/apache2/conf-available/server-name.conf 20 | a2enconf "server-name.conf" 21 | 22 | 23 | # Enable XDebug if needed 24 | if [ "$XDEBUG_ENABLE" = "1" ]; then 25 | docker-php-ext-enable xdebug 26 | mv /usr/local/etc/php/conf.d/99-xdebug.ini.disabled /usr/local/etc/php/conf.d/99-xdebug.ini 27 | # Configure XDebug remote host 28 | if [ -z "$HOST_IP" ]; then 29 | # Allows to set HOST_IP by env variable because could be different from the one which come from ip route command 30 | HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }') 31 | fi; 32 | echo "xdebug.remote_host=$HOST_IP" > /usr/local/etc/php/conf.d/xdebug_remote_host.ini 33 | fi; 34 | 35 | # Configure sSMTP 36 | if [ "$SSMTP_MAILHUB" ]; then 37 | echo "mailhub=$SSMTP_MAILHUB" >> /etc/ssmtp/ssmtp.conf 38 | fi; 39 | if [ "$SSMTP_AUTH_USER" ]; then 40 | echo "AuthUser=$SSMTP_AUTH_USER" >> /etc/ssmtp/ssmtp.conf 41 | fi; 42 | if [ "$SSMTP_AUTH_PASS" ]; then 43 | echo "AuthPass=$SSMTP_AUTH_PASS" >> /etc/ssmtp/ssmtp.conf 44 | fi; 45 | 46 | exec "apache2-foreground" 47 | --------------------------------------------------------------------------------