Last active
December 20, 2022 14:52
-
-
Save crmcmullen/52e93b07f7ccb0d02abf95bbaac86ae4 to your computer and use it in GitHub Desktop.
Dockerfile: Apache / PHP 7.2 Development Environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:7.2-apache | |
# This Gist file accompanies my article on Medium for creating a PHP, MySQL and Redis development environment | |
# on macOS. This Dockerfile will create an APACHE, PHP 7.2 server that includes the Xdebug, Igbinary and | |
# Redis PHP extensions from PECL. It will also create PHP.ini overrides that will point session management | |
# to the Redis server created in this same article. | |
# | |
# The article can be found here: | |
# https://medium.com/@crmcmullen/php-how-to-run-your-entire-development-environment-in-docker-containers-on-macos-787784e94f9a | |
# run non-interactive. Suppresses prompts and just accepts defaults automatically. | |
ENV DEBIAN_FRONTEND=noninteractive | |
# update OS and install utils | |
RUN apt-get update; \ | |
apt-get -yq upgrade; \ | |
apt-get install -y --no-install-recommends \ | |
apt-utils \ | |
nano; \ | |
apt-get -yq autoremove; \ | |
apt-get clean; \ | |
rm -rf /var/lib/apt/lists/* | |
# make sure custom log directories exist | |
RUN mkdir /usr/local/log; \ | |
mkdir /usr/local/log/apache2; \ | |
mkdir /usr/local/log/php; \ | |
chmod -R ug+w /usr/local/log | |
# create official PHP.ini file | |
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini | |
# install MySQLi | |
RUN docker-php-ext-install mysqli | |
# update PECL and install xdebug, igbinary and redis w/ igbinary enabled | |
RUN pecl channel-update pecl.php.net; \ | |
pecl install xdebug-2.7.2; \ | |
pecl install igbinary-3.0.1; \ | |
pecl bundle redis-5.0.2 && cd redis && phpize && ./configure --enable-redis-igbinary && make && make install; \ | |
docker-php-ext-enable xdebug igbinary redis | |
# Delete the resulting ini files created by the PECL install commands | |
RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-igbinary.ini; \ | |
rm -rf /usr/local/etc/php/conf.d/docker-php-ext-redis.ini; \ | |
rm -rf /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini | |
# Add PHP config file to conf.d | |
RUN { \ | |
echo 'short_open_tag = Off'; \ | |
echo 'expose_php = Off'; \ | |
echo 'error_reporting = E_ALL & ~E_STRICT'; \ | |
echo 'display_errors = On'; \ | |
echo 'error_log = /usr/local/log/php/php_errors.log'; \ | |
echo 'upload_tmp_dir = /tmp/'; \ | |
echo 'allow_url_fopen = on'; \ | |
echo '[xdebug]'; \ | |
echo 'zend_extension="xdebug.so"'; \ | |
echo 'xdebug.remote_enable = 1'; \ | |
echo 'xdebug.remote_port = 9001'; \ | |
echo 'xdebug.remote_autostart = 1'; \ | |
echo 'xdebug.remote_connect_back = 0'; \ | |
echo 'xdebug.remote_host = host.docker.internal'; \ | |
echo 'xdebug.idekey = VSCODE'; \ | |
echo '[redis]'; \ | |
echo 'extension="igbinary.so"'; \ | |
echo 'extension="redis.so"'; \ | |
echo 'session.save_handler = "redis"'; \ | |
echo 'session.save_path = "tcp://redis-localhost:6379?weight=1&timeout=2.5"'; \ | |
} > /usr/local/etc/php/conf.d/php-config.ini | |
# Manually set up the apache environment variables | |
ENV APACHE_RUN_USER www-data | |
ENV APACHE_RUN_GROUP www-data | |
ENV APACHE_LOG_DIR /usr/local/log/apache2 | |
# Configure apache mods | |
RUN a2enmod rewrite | |
# Add ServerName parameter | |
RUN echo "ServerName localhost" | tee /etc/apache2/conf-available/servername.conf | |
RUN a2enconf servername | |
# Update the default apache site with the config we created. | |
RUN { \ | |
echo '<VirtualHost *:80>'; \ | |
echo ' ServerAdmin [email protected]'; \ | |
echo ' DocumentRoot /var/www/html'; \ | |
echo ' <Directory /var/www/html/>'; \ | |
echo ' Options Indexes FollowSymLinks MultiViews'; \ | |
echo ' AllowOverride All'; \ | |
echo ' Order deny,allow'; \ | |
echo ' Allow from all'; \ | |
echo ' </Directory>'; \ | |
echo ' ErrorLog /usr/local/log/apache2/error.log'; \ | |
echo ' CustomLog /usr/local/log/apache2/access.log combined' ; \ | |
echo '</VirtualHost>'; \ | |
} > /etc/apache2/sites-enabled/000-default.conf | |
EXPOSE 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment