English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

DockerPHPInstallation

PHP-Image installieren

Methode 1: docker pull php

Suchen Docker Hub php-Images:

Durch Sortieren nach können andere Versionen von php angezeigt werden, Standard ist die neueste Version php:latest

Darüber hinaus können wir den Befehl docker search php verwenden, um verfügbare Versionen anzuzeigen:

w3codebox@w3codebox:~/php-fpm$ docker search php
NAME                    BESCHREIBUNG                                     STARS   OFFIZIELL   AUTOMATISIERT
php                                   Während es für die Web-Entwicklung konzipiert ist, ist das PH...   1232      [OK]       
richarvey/nginx-php-fpm Container läuft Nginx + PHP-FPM-fähig...   207                  [OK]
phpmyadmin/phpmyadmin   Eine Web-Oberfläche für MySQL und MariaDB.          123                  [OK]
eboraas/apache-php        PHP5 auf Apache (mit SSL-Unterstützung), gebaut o...   69                   [OK]
php-zendserver           Zend Server - die integrierte PHP-Anwendung...   69        [OK]       
Million12/nginx-php       Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS...   67                   [OK]
webdevops/php-nginx     Nginx mit PHP-FPM                              39                   [OK]
webdevops/php-apache    Apache mit PHP-FPM (basierend auf webdevops/php)    14                   [OK]
phpunit/phpunit           PHPUnit ist ein Programmierer-orientierte Testf...   14                   [OK]
tetraweb/php              PHP 5.3, 5.4, 5.5, 5.6, 7.0 für CI und Ausführung...   12                   [OK]
webdevops/php             PHP (FPM und CLI) Service Container             10                   [OK]
...

Here we pull the official image, tag as5.6-fpm

w3codebox@w3codebox:~/php-fpm$ docker pull php:5.6-fpm

After the download is complete, we can find the REPOSITORY as php, the tag as5.6-The fpm image.

w3codebox@w3codebox:~/php-fpm$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php                 5.6-fpm 025041cd3aa5        6 days ago          456.3 MB

Nginx + PHP deployment

Nginx deployment can be viewed at:DockerNginxInstallation,Some Nginx configurations can be referred to in this article.

Start PHP:

$ docker run --name myphp-fpm -v ~/nginx/www:/www  -d php:5.6-fpm

Command description:

  • --name myphp-fpm : Name the container myphp-fpm。

  • -v ~/nginx/www:/www : Mount the project directory www in the host to the container /www

Create ~/nginx/conf/conf.d directory:

mkdir ~/nginx/conf/conf.d

Add the following in this directory: ~/nginx/conf/conf.d/w3codebox-test-php.conf The file, content as follows:

server {
    listen       80;
    server_name localhost;
    location / {
        root   /usr/share/nginx/html;
        index index.html index.htm index.php;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~\.php$ {
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME  /www/$fastcgi_script_name;
        include fastcgi_params;
    }
}

Configuration file description:

  • php:9000: Represents php-The URL of the fpm service, we will explain it specifically below.

  • /www/: Is myphp-fpm The storage path of the PHP file, mapped to the local ~/nginx/www directory.

Start nginx:

docker run --name w3codebox-php-nginx -p 8083:80 -d \
    -v ~/nginx/www:/usr/share/nginx/html:ro \
    -v ~/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
    --link myphp-fpm:php \
    nginx
  • -p 8083:80PortKarten,Den nginx Darin 80KartenZurLokalen 8083 Port.

  • ~/nginx/www:IstVerzeichnisFürDieSpeicherungDerLokalenHtmlDateien,/usr/share/nginx/htmlIstVerzeichnisFürDieSpeicherungDerHtmlDateienImContainer.

  • ~/nginx/conf/conf.d:IstVerzeichnisFürDieSpeicherungDerLokalenNginxKonfigurationsdateien,/etc/nginx/conf.dIstVerzeichnisFürDieSpeicherungDerNginxKonfigurationsdateienImContainer.

  • --linkmyphp-fpm:php:Den myphp-fpm NetzwerkIn nginx,DurchVeränderung nginx Der /etc/hosts,DenDomainNamen php Karten 127.0.0.1,DockerDurchphp:9000Besuchenphp-fpm。

NunErstellenWirIn ~/nginx/wwwVerzeichnisunterErstellen index.php,CodeWie folgt:

<?php
echo phpinfo();
?>

BrowserÖffnen http://127.0.0.1:8083/index.php,wie folgt angezeigt wird: