7.19.3
Install PHP 7.19.3 with Composer and PHPUnit in a Dockerfile. This guide provides a complete Dockerfile for setting up a PHP development environment with essential tools.
PHP 7.19.3 Dockerfile
Dockerfile for PHP 7.19.3 with Composer and PHPUnit
This Dockerfile sets up a PHP 7.19.3 environment, including the installation of Composer for dependency management and PHPUnit for testing. It's designed for developers who need a consistent and isolated PHP development environment.
Install Essential PHP Extensions
The initial setup involves updating the package list and installing necessary system dependencies and PHP extensions. This includes clients for MySQL, development libraries for MySQL and other common extensions like cURL, Git, FreeType, JPEG, MCrypt, and ZIP.
Enable and Configure PHP Extensions
Key PHP extensions such as iconv, mcrypt, gd, zip, mysqli, opcache, mbstring, bcmath, and pcntl are enabled and configured. The GD extension is configured to support FreeType and JPEG. The mcrypt extension is installed from PECL.
Install Composer
Composer, the dependency manager for PHP, is installed. Instead of using the online installer, a specific version (1.10.7) is downloaded directly, made executable, and placed in the system's PATH for easy access.
Install PHPUnit
PHPUnit, the popular unit testing framework for PHP, is installed globally using Composer. The PATH environment variable is updated to include the vendor binaries directory, ensuring that PHPUnit can be executed directly from the command line.
Create Symlink for PHPUnit
A symbolic link is created to make the phpunit
executable easily accessible in the system's PATH, typically in /usr/bin/phpunit
.
FROM php:7.3.19-cli
RUN apt-get update \
&& apt-get install \
default-mysql-client \
default-libmysqlclient-dev \
curl git libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev libpng-dev \
libzip-dev -y
RUN docker-php-ext-install iconv \
&& pecl install mcrypt-1.0.3 \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-install zip \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install opcache \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install bcmath \
&& docker-php-ext-install pcntl
RUN curl -O "https://getcomposer.org/download/1.10.7/composer.phar" \
&& chmod a+x composer.phar \
&& mv composer.phar /usr/bin/composer
RUN composer global require phpunit/phpunit "^7.5"
ENV PATH /root/.composer/vendor/bin:$PATH
RUN ln -s /root/.composer/vendor/bin/phpunit /usr/bin/phpunit