Install PHP image

Source: Internet
Author: User
Tags fpm gpg zend server docker ps docker hub docker run

installation PHP Mirror

method One, through Dockerfile Build

Create Dockerfile

First, create the directory php-fpm, which is used to store the related things behind.

[Email protected]:~$ mkdir-p ~/php-fpm/logs ~/php-fpm/conf

The logs directory will be mapped to the log directory of the PHP-FPM container

The configuration file in the Conf directory will be mapped to the configuration file for the PHP-FPM container

Enter the created PHP-FPM directory and create the Dockerfile

From Debian:jessie

# Persistent/runtime Deps

ENV phpize_deps \

autoconf \

File \

g++ \

GCC \

Libc-dev \

Make \

Pkg-config \

Re2c

RUN apt-get update && apt-get install-y \

$PHPIZE _deps \

Ca-certificates \

Curl \

LIBEDIT2 \

libsqlite3-0 \

LIBXML2 \

--no-install-recommends && rm-r/var/lib/apt/lists/*

ENV php_ini_dir/usr/local/etc/php

RUN mkdir-p $PHP _INI_DIR/CONF.D

##<autogenerated>##

ENV Php_extra_configure_args--enable-fpm--with-fpm-user=www-data--with-fpm-group=www-data

##</autogenerated>##

ENV Gpg_keys 0BD78B5F97500D450838F95DFE857D9A90D90EC1 6e4f6ab321fdc07f2c332e3ac2bf0bc433cfc8b3

ENV php_version 5.6.22

ENV Php_filename Php-5.6.22.tar.xz

ENV php_sha256 C96980d7de1d66c821a4ee5809df0076f925b2fe0b8c362d234d92f2f0a178e2

RUN set-xe \

&& builddeps= "\

$PHP _extra_build_deps \

Libcurl4-openssl-dev \

Libedit-dev \

Libsqlite3-dev \

Libssl-dev \

Libxml2-dev \

Xz-utils \

" \

&& apt-get update && apt-get install-y $buildDeps--no-install-recommends && rm-rf/var/lib/apt/ lists/* \

&& curl-fsl "http://php.net/get/$PHP _filename/from/this/mirror"-O "$PHP _filename" \

&& echo "$PHP _sha256 * $PHP _filename" | Sha256sum-c-\

&& curl-fsl "http://php.net/get/$PHP _filename.asc/from/this/mirror"-O "$PHP _filename.asc" \

&& Export Gnupghome= "$ (mktemp-d)" \

&& for key in $GPG _keys; Do \

GPG--keyserver ha.pool.sks-keyservers.net--recv-keys "$key"; \

Done \

&& gpg--batch--verify "$PHP _filename.asc" "$PHP _filename" \

&& rm-r "$GNUPGHOME" "$PHP _filename.asc" \

&& mkdir-p/usr/src/php \

&& tar-xf "$PHP _filename"-c/usr/src/php--strip-components=1 \

&& rm "$PHP _filename" \

&& cd/usr/src/php \

&&./configure \

--with-config-file-path= "$PHP _ini_dir" \

--with-config-file-scan-dir= "$PHP _ini_dir/conf.d" \

$PHP _extra_configure_args \

--DISABLE-CGI \

#--ENABLE-MYSQLND is included here because it's harder to compile after the fact than extensions is (since it's a plugin For several extensions, not a extension in itself)

--ENABLE-MYSQLND \

#--enable-mbstring is included here because otherwise there ' s no-to-get pecl to use it properly (see HTTPS://GITHUB.C om/docker-library/php/issues/195)

--enable-mbstring \

--with-curl \

--with-libedit \

--WITH-OPENSSL \

--with-zlib \

&& make-j "$ (nproc)" \

&& make install \

&& {find/usr/local/bin/usr/local/sbin-type f-executable-exec strip--strip-all ' {} ' + | | true;} \

&& make clean \

&& apt-get purge-y--auto-remove-o apt::autoremove::recommendsimportant=false-o apt::autoremove:: Suggestsimportant=false $buildDeps

COPY docker-php-ext-*/usr/local/bin/

##<autogenerated>##

Workdir/var/www/html

RUN set-ex \

&& cd/usr/local/etc \

&& if [-D PHP-FPM.D]; Then \

# for some reason, Upstream's php-fpm.conf.default has "include=none/etc/php-fpm.d/*.conf"

Sed ' s!=none/!=!g ' php-fpm.conf.default | Tee php-fpm.conf >/dev/null; \

CP Php-fpm.d/www.conf.default php-fpm.d/www.conf; \

else \

# PHP 5.x don ' t use "include=" by default, so we'll create our own simple config this mimics PHP 7+ for consistency

mkdir PHP-FPM.D; \

CP Php-fpm.conf.default php-fpm.d/www.conf; \

{ \

Echo ' [Global] '; \

Echo ' include=etc/php-fpm.d/*.conf '; \

} | Tee php-fpm.conf; \

FH =

&& {\

Echo ' [Global] '; \

echo ' error_log =/proc/self/fd/2 '; \

Echo \

Echo ' [www] '; \

Echo '; If we send this to/proc/self/fd/1, it never appears '; \

echo ' access.log =/proc/self/fd/2 '; \

Echo \

echo ' clear_env = no '; \

Echo \

Echo '; Ensure worker stdout and stderr is sent to the main error log. \

echo ' catch_workers_output = yes '; \

} | Tee php-fpm.d/docker.conf \

&& {\

Echo ' [Global] '; \

echo ' daemonize = no '; \

Echo \

Echo ' [www] '; \

echo ' Listen = [::]:9000 '; \

} | Tee php-fpm.d/zz-docker.conf

EXPOSE 9000

CMD ["PHP-FPM"]

Create a mirror from dockerfile and replace it with your own name

[Email protected]:~/php-fpm$ Docker build-t php:5.6-fpm.

Once created, we can find the image we just created in the local image list

[Email protected]:~/php-fpm$ Docker Images

REPOSITORY TAG IMAGE ID CREATED SIZE

PHP 5.6-fpm 025041cd3aa5 6 days ago 456.3 MB

method Two, Docker Pull PHP

Find the PHP image on the Docker hub

[Email protected]:~/php-fpm$ docker Search PHP

NAME DESCRIPTION STARS Official automated

PHP while designed for web development, the PH ... 1232 [OK]

RICHARVEY/NGINX-PHP-FPM Container running Nginx + php-fpm capable ... 207 [OK]

Phpmyadmin/phpmyadmin A Web interface for MySQL and MariaDB. 123 [OK]

eboraas/apache-php PHP5 on Apache (with SSL support), built o ... [OK]

Php-zendserver Zend server-the integrated PHP applicati ... [OK]

million12/nginx-php Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS ... [OK]

Webdevops/php-nginx nginx with PHP-FPM [OK]

Webdevops/php-apache Apache with PHP-FPM (based on webdevops/php) [OK]

Phpunit/phpunit PHPUnit is a programmer-oriented testing f ... [OK]

tetraweb/php PHP 5.3, 5.4, 5.5, 5.6, 7.0 for CI and run ... [OK]

webdevops/php php (FPM and CLI) service container [OK]

...

Here we pull the official image, tagged as 5.6-fpm

[Email protected]:~/php-fpm$ Docker Pull PHP:5.6-FPM

After waiting for the download to complete, we can find the image in the local mirror list repository php, labeled 5.6-FPM.

Use PHP-FPM Mirror

Running the container

[Email protected]:~/php-fpm$ docker run-p 9000:9000--name myphp-fpm-v ~/nginx/www:/www-v $PWD/conf:/usr/local/etc/php -V $PWD/logs:/phplogs-d php:5.6-fpm

00c5aa4c2f93ec3486936f45b5f2b450187a9d09acb18f5ac9aa7a5f405dbedf

[Email protected]:~/php-fpm$

Command Description:

    • -P 9,000:9,000: Map the container's 9000 port to the host's 9000 port
    • --name MYPHP-FPM: Name the container myphp-fpm
    • -V ~/nginx/www:/www: Mount the directory www of the project in the host to the/www of the container
    • -V $PWD/conf:/usr/local/etc/php: Mount the Conf directory under the current directory in the host to the container's/usr/local/etc/php
    • -V $PWD/logs:/phplogs: Mount the logs directory under the current directory in the host to the container's/phplogs

To view container startup conditions

[Email protected]:~/php-fpm$ Docker PS

CONTAINER ID IMAGE COMMAND ... PORTS NAMES

00c5aa4c2f93 php:5.6-fpm "PHP-FPM" ... 0.0.0.0:9000->9000/tcp MYPHP-FPM

Access Phpinfo () via browser

PS: Here is the implementation of Web services through nginx+php, nginx configuration file Fastcgi_pass should be configured as MYPHP-FPM container IP.

Fastcgi_pass 172.17.0.4:9000;

Method of checking Container IP

Docker inspect container ID or container name |grep ' "IPAddress" '

Install PHP image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.