php comes with some extensions
Use the keyword docker-php-ext-install the file directly in the Dockerfile
RUN docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install bcmath \
&& docker-php-ext-install sockets \
&& docker-php-ext-install zip \
&& docker-php-ext-install sysvmsg
pecl extension
On the site https://pecl.php.net extension can use pecl install installation, for example redis swoole and other extensions, pay attention to whether there is need to use pecl command in the mirror when the command to install, not install
RUN pecl install swoole-4.2.12 \
&& docker-php-ext-enable swoole \
&& pecl install inotify-2.0.0 \
&& docker-php-ext-enable inotify
After pecl install will start the https://pecl.php.net the download package and installation, so the following are also possible.
RUN wget http://pecl.php.net/get/redis-${PHPREDIS_VERSION}.tgz -O /tmp/redis.tar.tgz \
&& pecl install /tmp/redis.tar.tgz \
&& rm -rf /tmp/redis.tar.tgz \
&& docker-php-ext-enable redis
Download the installation package extensions
Some extensions are the top two ways not want to install or use the source code, you can use this way. In fact, the essence of the above two methods is to download and install methods, so they will have phpize confirm the existence of such orders, if not configured phpize environment variables have to write the whole path. , But also to see if the installation make command
The following is swoft download swoole extension installation method
RUN wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz \
&& mkdir -p swoole \
&& tar -xf swoole.tar.gz -C swoole --strip-components=1 \
&& rm swoole.tar.gz \
&& ( \
cd swoole \
&& phpize \
&& ./configure --enable-mysqlnd --enable-sockets --enable-openssl --enable-http2 \
&& make -j$(nproc) \
&& make install \
) \
&& rm -r swoole \
&& docker-php-ext-enable swoole
The following is the official website to download php extension method
FROM php:5.6-cli
RUN curl -fsSL 'https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz' -O xcache.tar.gz \
&& mkdir -p xcache \
&& tar -xf xcache.tar.gz -C xcache --strip-components=1 \
&& rm xcache.tar.gz \
&& ( \
cd xcache \
&& phpize \
&& ./configure --enable-xcache \
&& make -j$(nproc) \
&& make install \
) \
&& rm -r xcache \
&& docker-php-ext-enable xcache
More detailed instructions, please docker php mirror illustrate
the use of this method to note the following:
- RUN last command can not have a slash, otherwise an error such as the following
&& docker-php-ext-enable xcache \
- The most sure to download the same package suffixes and decompressed, or unzipped when will complain
- The first step in the wget parameters is -O, not -o, uppercase. The docker hup is wrong
problem
- Question 1
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
ERROR: `phpize' failed
Solutions, installation autoconf. centos use yum, unbantu using the apt-get, alpine is apk
RUN apk update \
&& apk add autoconf \
&& docker-php-ext-install pcntl \
&& pecl install redis-5.0.0 \
&& docker-php-ext-enable redis
COPY . /var/www/html
COPY ./docker/nginx-php7/sites-enabled /etc/nginx/sites-enabled
- Question 2
error at no acceptable C compiler found in $ PATH when ./configure
configure: error: in `/var/www/html/redis':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
Workaround; install gcc
apk add gcc
- Question 3
is also in error when ./configure, C compiler can not create executables
configure: error: in `/var/www/html/redis':
configure: error: C compiler cannot create executables
See `config.log' for more details
Since I am using a docker's alpine mirroring solutions please refer to the solution as follows:
apk add gcc g++
More than three problem is that I have encountered during installation redis extended time, Dockerfile follows
FROM richarvey/nginx-php-fpm:latest
RUN apk update \
&& apk add autoconf \
&& apk add gcc g++\
&& apk add make \
&& docker-php-ext-install pcntl \
&& wget https://pecl.php.net/get/redis-5.0.1.tgz -O redis.tgz \
&& mkdir -p redis \
&& tar -xf redis.tgz -C redis --strip-components=1 \
&& rm redis.tgz \
&& ( \
cd redis \
&& phpize \
&& ./configure --with-php-config=/usr/local/bin/php-config \
&& make -j$(nproc) \
&& make install \
) \
&& rm -r redis \
&& docker-php-ext-enable redis
COPY . /var/www/html
COPY ./docker/nginx-php7/sites-enabled /etc/nginx/sites-enabled