diff --git a/99-xdebug.ini.disabled b/99-xdebug.ini.disabled new file mode 100644 index 0000000..e1a5731 --- /dev/null +++ b/99-xdebug.ini.disabled @@ -0,0 +1,12 @@ +[xdebug] +xdebug.remote_enable=on +xdebug.default_enable=on +xdebug.remote_autostart=off +xdebug.remote_port=9000 +xdebug.profiler_enable_trigger=1 +xdebug.profiler_output_name=xdebug-profile-cachegrind.out-%H-%R +xdebug.var_display_max_children = 128 +xdebug.var_display_max_data = 2048 +xdebug.var_display_max_depth = 128 +xdebug.max_nesting_level = 200 +xdebug.coverage_enable = 1 diff --git a/999-php.ini b/999-php.ini new file mode 100644 index 0000000..7b69ed7 --- /dev/null +++ b/999-php.ini @@ -0,0 +1,2 @@ +memory_limit = -1 +error_reporting = E_ALL | E_STRICT diff --git a/Dockerfile b/Dockerfile index c962853..5affc66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,6 @@ RUN apt-get update \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install gd -# Install Iconv -RUN docker-php-ext-install iconv - # Install MCrypt RUN apt-get update \ && apt-get install -y libmcrypt-dev \ @@ -21,13 +18,76 @@ RUN apt-get update \ && docker-php-ext-install intl # Install XDebug -RUN pecl install -o -f xdebug \ - && rm -rf /tmp/pear \ - && echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini +ENV XDEBUG_ENABLE 0 +RUN pecl install -o -f xdebug-2.5.5 \ + && rm -rf /tmp/pear +COPY ./99-xdebug.ini.disabled /usr/local/etc/php/conf.d/ # Install Mysql -RUN docker-php-ext-install mysql mysqli +RUN docker-php-ext-install mysql mysqli pdo_mysql + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php \ + && mv composer.phar /usr/local/bin/composer + +# Install mbstring +RUN docker-php-ext-install mbstring + +# Install soap +RUN apt-get update \ + && apt-get install -y libxml2-dev \ + && docker-php-ext-install soap + +# Install opcache +RUN docker-php-ext-install opcache + +# Install PHP zip extension +RUN docker-php-ext-install zip + +# Install Git +RUN apt-get update \ + && apt-get install -y git + +# Install xsl +RUN apt-get update \ + && apt-get install -y libxslt-dev \ + && docker-php-ext-install xsl + +# Define PHP_TIMEZONE env variable +ENV PHP_TIMEZONE Europe/Rome + +# Configure Apache Document Root +ENV APACHE_DOC_ROOT /var/www/html + +# Enable Apache mod_rewrite +RUN a2enmod rewrite + +# Additional PHP ini configuration +COPY ./999-php.ini /usr/local/etc/php/conf.d/ +# Install Blackfire.io Probe +RUN export VERSION=`php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;"` \ + && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/${VERSION} \ + && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \ + && mv /tmp/blackfire-*.so `php -r "echo ini_get('extension_dir');"`/blackfire.so \ + && echo "extension=blackfire.so\nblackfire.agent_socket=\${BLACKFIRE_PORT}" > $PHP_INI_DIR/conf.d/blackfire.ini + +# Sample index.php with phpinfo() and entrypoint COPY ./index.php /var/www/html/index.php +# Install ssmtp Mail Transfer Agent +RUN apt-get update \ + && apt-get install -y ssmtp \ + && apt-get clean \ + && echo "FromLineOverride=YES" >> /etc/ssmtp/ssmtp.conf \ + && echo 'sendmail_path = "/usr/sbin/ssmtp -t"' > /usr/local/etc/php/conf.d/mail.ini + +# Install MySQL CLI Client +RUN apt-get update \ + && apt-get install -y mysql-client + +######################################################################################################################## +# Start! +COPY ./start /usr/local/bin/ +CMD ["start"] diff --git a/README.md b/README.md index 1c87070..0300db4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,37 @@ Base PHP with Apache Docker Container ===================================== -Base Docker Container for PHP web development. Apache webserver integrated. +Dockerized environment for PHP web development and Apache web server. + +Features +-------- + +* Ability to set Apache document root through `APACHE_DOC_ROOT` environment variable. Default document root is `/var/www/html` +* Enabled Apache modules: rewrite +* Ability to set PHP `date.timezone` through `PHP_TIMEZONE` environment variable. Default timezone is `Europe/Rome` +* Enabled PHP extensions: gd, mcrypt, intl, mysql, mysqli, pdo_mysql, mbstring, soap, opcache, zip, xls +* Composer installed globally at `/usr/local/bin/composer` +* Xdebug PHP extension installed but not enabled +* Ability to enable xdebug PHP extension through `XDEBUG_ENABLE` environment variable which has to be set to `1` +* Ability to set xdebug.remote_enable setting through `HOST_IP` environment variable. +* Blackfire.io Probe installed +* GIT installed (required by Composer) +* sSMTP installed (as Mail Transfer Agent for PHP mail function) +* Ability to set sSMTP mailhub, AuthUser and AuthPass through `SSMTP_MAILHUB`, `SSMTP_AUTH_USER` and `SSMTP_AUTH_PASS` environment variables +* MySQL CLI Client installed + +Usage +----- + +Standalone usage example with host's current working directory as document root: + + $ docker run -p 80:80 -v .:/var/www/html webgriffe/php-apache-base:5.6 + +Credits +------- + +[Webgriffe®](http://www.webgriffe.com/) + + + diff --git a/start b/start new file mode 100755 index 0000000..c4e7a29 --- /dev/null +++ b/start @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -e + +# Configure PHP date.timezone +echo "date.timezone = $PHP_TIMEZONE" > /usr/local/etc/php/conf.d/timezone.ini + +# Configure Apache Document Root +mkdir -p $APACHE_DOC_ROOT +chown www-data:www-data $APACHE_DOC_ROOT +sed -i "s|DocumentRoot /var/www/html\$|DocumentRoot $APACHE_DOC_ROOT|" /etc/apache2/sites-available/000-default.conf +echo "" > /etc/apache2/conf-available/document-root-directory.conf +echo " AllowOverride All" >> /etc/apache2/conf-available/document-root-directory.conf +echo " Require all granted" >> /etc/apache2/conf-available/document-root-directory.conf +echo "" >> /etc/apache2/conf-available/document-root-directory.conf +a2enconf "document-root-directory.conf" + +# Enable XDebug if needed +if [ "$XDEBUG_ENABLE" = "1" ]; then + docker-php-ext-enable xdebug + mv /usr/local/etc/php/conf.d/99-xdebug.ini.disabled /usr/local/etc/php/conf.d/99-xdebug.ini + # Configure XDebug remote host + if [ -z "$HOST_IP" ]; then + # Allows to set HOST_IP by env variable because could be different from the one which come from ip route command + HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }') + fi; + echo "xdebug.remote_host=$HOST_IP" > /usr/local/etc/php/conf.d/xdebug_remote_host.ini +fi; + +# Configure sSMTP +if [ "$SSMTP_MAILHUB" ]; then + echo "mailhub=$SSMTP_MAILHUB" >> /etc/ssmtp/ssmtp.conf +fi; +if [ "$SSMTP_AUTH_USER" ]; then + echo "AuthUser=$SSMTP_AUTH_USER" >> /etc/ssmtp/ssmtp.conf +fi; +if [ "$SSMTP_AUTH_PASS" ]; then + echo "AuthPass=$SSMTP_AUTH_PASS" >> /etc/ssmtp/ssmtp.conf +fi; + +exec "apache2-foreground"