docker Installation php fpm Service and Extension and Configuration Sample Tutorial Details
- 2021-08-12 04:01:03
- OfStack
In
mac
Used
brew
Install
php56
When, because
openssl
Yes
1.1
Version, resulting in various
google
I can't make a mistake. It's too tossing. Now use it
docker
Create 1
php56-fpm
Service container,
nginx
Directly mounted on the host machine.
PHP DockerHub Home Page
Create a container
# Create a container
docker run -d \
--name php56-fpm \
-p 9056:9000 \
-v /home/wwwroot:/var/www/html
--privileged=true
php:5.6-fpm
Note:
/var/www/html
Yes
brew
0
The working directory of the mirror.
-v /home/wwwroot:/var/www/html
Is to mount the host's site directory on the container. For example
/home/wwwroot/siteA
The access location in the container is
/var/www/html/siteA
.
nignx
Forwarding
php
When requested, the name of the script that will be executed
SCRIPT_NAME
And script file name
SCRIPT_FILENAME
Forward to
fpm
, and then
fpm
To read the script execution.
In use
fpm
Container, you need to pay attention to
nginx
Forwarded
SCRIPT_FILENAME
Whether it is
fpm
Valid site path in the container, if
nginx
Adj.
root
Is not directly mapped to
fpm
Site of the container
root
, we need to
php location
Redefined as
fpm
Site of the container
root
. In this way
fpm
To read the script correctly.
That is, on the host machine
openssl
2
To turn into
/var/www/html/siteA/public/index.php
Send to
fpm
Container, otherwise it will be reported
File not found
The mistake.
So
nginx
Configure
server
Note the following volume path conversion when:
server {
listen 8056;
....
# Site root directory of the host
root /home/wwwroot/siteA/public;
location ~* (^[/]*.php)[/|$] {
# Site root directory in container
root /var/www/html/siteA/public;
pass_proxy: 127.0.0.1:9056;
include fastcgi.conf;
}
}
But in 1 case, everyone is
docker nginx + docker php-fpm
, both containers 1 mapped the site directory, so there would be no such problem. Here's
nginx
Is directly installed on the host machine to cause
nginx
Forwarding
php
When requesting, you need to redefine the root directory of the next site.
Landing container
# See if the container is running
docker ps
# Landing container
docker exec -it php56-fpm /bin/bash
The docker image of the php is based on the ubuntu and we can use the tools required for the apt-get installation, such as vim/vi lrzsz net-tools and so on.
# In use apt-get Installation 1 Before some tools, you need update Update 1 Downsource
# Otherwise it will apt-get E: Unable to locate package
apt-get update
apt-get install vim
Install php/pecl extensions
Installing php extensions
That is, the official extension of php, such as shomp, which comes with it but does not open by default.
# See which extensions come with you
cd /usr/local/php/ext && ls -l
# Installation extension
dcoker-php-ext-install shmop
Installing pecl extensions
pecl is installed in the container, so you can install it directly by using pecl, and pay attention to extending the support for php version.
The primary purpose of docker-php-ext-enable is to generate the corresponding extension configuration file to/usr/local/etc/php/conf. d/docker-php-ext {extName}. ini facilitates php loading extensions.
# igbinary php5.6 The highest version is 2.0.8
pecl install igbinary-2.0.8
docker-php-ext-enable igbinary
# phpredis php5.6 The highest version is 4.3.0
pecl install redis-4.3.0
docker-php-ext-enable redis
# swoole php5.6 The highest version is 2.0.11
pcel install swoole-2.0.11
docker-php-ext-enable swoole
php/php-fpm Configuration
/usr/local/etc is the configuration directory of the php container, which contains the configuration files of php and php-fpm. The configuration directory structure is as follows:
root@aa739592b579:/usr/local# tree etc/
etc/
|-- pear.conf
|-- php # php Configuration directory
| |-- conf.d # php Extended configuration
| | |-- docker-php-ext-shmop.ini
| |-- php.ini # cp Adj. php.ini-development/production
| |-- php.ini-development
| |-- php.ini-production
|-- php-fpm.conf # php-fpm Configuration of Self-contained is mainly introduced php-fpm.d
|-- php-fpm.conf.default # php-fpm Configuration ontology Same as php-fpm.d/www.conf 1 To
|-- php-fpm.d # php-fpm Extended configuration of
|-- docker.conf
|-- www.conf # php-fpm Configuration ontology Pattern ah max/min children Ah, it's all here
|-- zz-docker.conf
You can map the host's configuration directory to the/usr/local/etc of the container, but be careful that the host's configuration directory is the same as the existing one of the container, or edit the configuration file directly in the container. According to the concept of docker, we should maintain a configuration file on the host machine and map it to the configuration directory of the container, so as to give full play to the reusability of docker container.
Mapping the host's php configuration file to the container
-v /opt/docker/conf/php/php.ini:/usr/local/etc/php/php.ini
-v /opt/docker/conf/php/php-fpm.ini:/usr/local/etc/php-fpm.d/www/conf
Frequently Asked Questions
1. File not found
The site root specified by nginx cannot be mapped directly to the fpm container, so re-specify the site root of the fpm container in location.
2. apt-get E: Unable to locate package
Execute apt-get update to refresh the source 1.
3. Relevant conventions of containers
Working directory:/var/www/html recommends mapping the host's site directory to this directory
Configuration directory:/usr/local/etc Note the configuration directory structure
php Extensions Directory:/usr/local/php/ext can view the extension packs that come with php. It is easier to install with docker-php-ext-install