Skip to content

Latest commit

ย 

History

History
576 lines (446 loc) ยท 25.7 KB

README-all-en.md

File metadata and controls

576 lines (446 loc) ยท 25.7 KB

DNMP (Docker + Nginx/Openresty + MySQL5, 8 + PHP5, 7,8 + Redis + ElasticSearch + MongoDB + RabbitMQ) is a full-featured modelLNMP one-click installer with Support for Arm CPUsใ€‚

It is best to read it in advance before usedirectory, in order to get started quickly, and problems can be eliminated in time.

QQ Exchange Group:

  • Group 1:572041090(Full)
  • Group 2:300723526(Full)
  • Group 3:878913761(bit)

[ENGLISH] - [GitHub Address] - [Gitee address]

DNMP Project Features:

  1. 100%open source
  2. 100%Follow docker standards
  3. backingMultiple versions of PHPCoexistence, can be switched arbitrarily (PHP5.4, PHP5.6, PHP7.1, PHP7.2, PHP7.3, PHP7.4, PHP8.0)
  4. Binding is supportedAny number of domain names
  5. backingHTTPS and HTTP/2
  6. PHP source code, MySQL data, configuration files, log filesAll can be directly modified in Host
  7. BuiltFull PHP extension installationcommand
  8. Supported by defaultpdo_mysqlใ€mysqliใ€mbstringใ€gdใ€curlใ€opcacheand other commonly used and popular extensions, flexibly configured according to the environment
  9. One-click selection of common services:
    • Multiple PHP versions: PHP5.4, PHP5.6, PHP7.0-7.4, PHP8.0
    • Web services: Nginx, Openresty
    • Databases: MySQL5, MySQL8, Redis, memcached, MongoDB, ElasticSearch
    • Message Queuing: RabbitMQ
    • Accessibility: Kibana, Logstash, phpMyAdmin, phpRedisAdmin, AdminMongo
  10. Apply in real projects, ensure100%available
  11. All mirrors originate fromDocker official repository, safe and reliable
  12. One configuration,Windowsใ€Linuxใ€MacOsAll available
  13. Supports quick installation extension commands install-php-extensions apcu
  14. Supports installing CERTBOT to obtain SSL certificates for free https

directory

1. Directory structure

/
โ”œโ”€โ”€ data                        ๆ•ฐๆฎๅบ“ๆ•ฐๆฎ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ esdata                  ElasticSearch ๆ•ฐๆฎ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ mongo                   MongoDB ๆ•ฐๆฎ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ mysql                   MySQL8 ๆ•ฐๆฎ็›ฎๅฝ•
โ”‚ย ย  โ””โ”€โ”€ mysql5                  MySQL5 ๆ•ฐๆฎ็›ฎๅฝ•
โ”œโ”€โ”€ services                    ๆœๅŠกๆž„ๅปบๆ–‡ไปถๅ’Œ้…็ฝฎๆ–‡ไปถ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ elasticsearch           ElasticSearch ้…็ฝฎๆ–‡ไปถ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ mysql                   MySQL8 ้…็ฝฎๆ–‡ไปถ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ mysql5                  MySQL5 ้…็ฝฎๆ–‡ไปถ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ nginx                   Nginx ้…็ฝฎๆ–‡ไปถ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ php                     PHP5.6 - PHP7.4 ้…็ฝฎ็›ฎๅฝ•
โ”‚ย ย  โ”œโ”€โ”€ php54                   PHP5.4 ้…็ฝฎ็›ฎๅฝ•
โ”‚ย ย  โ””โ”€โ”€ redis                   Redis ้…็ฝฎ็›ฎๅฝ•
โ”œโ”€โ”€ logs                        ๆ—ฅๅฟ—็›ฎๅฝ•
โ”œโ”€โ”€ docker-compose.sample.yml   Docker ๆœๅŠก้…็ฝฎ็คบไพ‹ๆ–‡ไปถ
โ”œโ”€โ”€ env.smaple                  ็Žฏๅขƒ้…็ฝฎ็คบไพ‹ๆ–‡ไปถ
โ””โ”€โ”€ www                         PHP ไปฃ็ ็›ฎๅฝ•

2. Quick to use

  1. Local installation
    • git
    • Docker(The system needs to be Linux, Windows 10 Build 15063+, or MacOS 10.12+, and must be.)64bit)
    • docker-compose 1.7.0+
  2. cloneProject: $ git clone https://github.com/yeszao/dnmp.git # ๅ‡ๅฆ‚้€Ÿๅบฆๅคชๆ…ข๏ผŒๅฏไปฅไฝฟ็”จๅŠ ้€Ÿๆ‹‰ๅ–้•œๅƒ $ git clone https://github.com.cnpmjs.org/yeszao/dnmp.git
  3. If the host is a Linux system and the current user is notrootUsers, you also need to join the current userdockerUser Groups: $ sudo gpasswd -a ${USER} docker
  4. Copy and name the configuration file (for Windows systems.)copycommand), start: $ cd dnmp # ่ฟ›ๅ…ฅ้กน็›ฎ็›ฎๅฝ• $ cp env.sample .env # ๅคๅˆถ็Žฏๅขƒๅ˜้‡ๆ–‡ไปถ $ cp docker-compose.sample.yml docker-compose.yml # ๅคๅˆถ docker-compose ้…็ฝฎๆ–‡ไปถใ€‚้ป˜่ฎคๅฏๅŠจ3ไธชๆœๅŠก๏ผš # Nginxใ€PHP7ๅ’ŒMySQL8ใ€‚่ฆๅผ€ๅฏๆ›ดๅคšๅ…ถไป–ๆœๅŠก๏ผŒๅฆ‚Redisใ€ # PHP5.6ใ€PHP5.4ใ€MongoDB๏ผŒElasticSearch็ญ‰๏ผŒ่ฏทๅˆ  # ้™คๆœๅŠกๅ—ๅ‰็š„ๆณจ้‡Š $ docker-compose up # ๅฏๅŠจ
  5. Access in a browser:http://localhostorhttps://localhost(Self-signed HTTPS demo) can see the effect of PHP code in the file./www/localhost/index.phpใ€‚

3.PHP and extensions

3.1 Switch the PHP version used by Nginx

First, you need to start another version of PHP, such as PHP 5.4, so that's the first stepdocker-compose.ymlDelete the comments that preceded PHP5.4 from the file and start the PHP5.4 container.

After PHP5.4 starts, open Nginx Configuration and modify itfastcgi_passThe host address of the company, by phptophp54As follows:

    fastcgi_pass   php:9000;

For:

    fastcgi_pass   php54:9000;

thereinto php and php54 bedocker-compose.ymlThe name of the server in the file.

At lastReboot Nginx Take effect.

$ docker exec -it nginx nginx -s reload

Here are twonginx, the first is the container name, and the second is in the containernginxProcedure.

3.2 Install PHP extensions

Many of php's features are implemented through extensions, and installing extensions is a slightly time-consuming process. So, in addition to the PHP built-in extension, inenv.sampleIn the file we only install a small number of extensions by default, If you want to install more extensions, open yours.envModify the following PHP configuration, Add the required PHP extensions:

PHP_EXTENSIONS=pdo_mysql,opcache,redis       # PHP ่ฆๅฎ‰่ฃ…็š„ๆ‰ฉๅฑ•ๅˆ—่กจ๏ผŒ่‹ฑๆ–‡้€—ๅท้š”ๅผ€
PHP54_EXTENSIONS=opcache,redis                 # PHP 5.4่ฆๅฎ‰่ฃ…็š„ๆ‰ฉๅฑ•ๅˆ—่กจ๏ผŒ่‹ฑๆ–‡้€—ๅท้š”ๅผ€

Then re-build the PHP image.

docker-compose build php

See the available extensions in the same fileenv.sampleComment block description.

3.3 Quickly install php extensions

1. Enter the container:

docker exec -it php /bin/sh

install-php-extensions apcu 

2. Support quick installation extension list

Extension PHP 5.5 PHP 5.6 PHP 7.0 PHP 7.1 PHP 7.2 PHP 7.3 PHP 7.4 PHP 8.0 PHP 8.1
amqp โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
apcu โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
apcu_bc โœ“ โœ“ โœ“ โœ“ โœ“
ast โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
bcmath โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
blackfire โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
bz2 โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
calendar โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
cmark โœ“ โœ“ โœ“ โœ“ โœ“
csv โœ“ โœ“ โœ“ โœ“
dba โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
decimal โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
ds โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
enchant โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
ev โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
event โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
excimer โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
exif โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
ffi โœ“ โœ“ โœ“
gd โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
gearman โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
geoip โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
geospatial โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
gettext โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
gmagick โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
gmp โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
gnupg โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
grpc โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
http โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
igbinary โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
imagick โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
imap โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
inotify โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
interbase โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
intl โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
ioncube_loader โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
jsmin โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
json_post โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
ldap โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
lzf โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
mailparse โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
maxminddb โœ“ โœ“ โœ“ โœ“ โœ“
mcrypt โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
memcache โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
memcached โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
mongo โœ“ โœ“
mongodb โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
mosquitto โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
msgpack โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
mssql โœ“ โœ“
mysql โœ“ โœ“
mysqli โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
oauth โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
oci8 โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
odbc โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
opcache โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
opencensus โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
openswoole โœ“ โœ“ โœ“ โœ“ โœ“
parallel* โœ“ โœ“ โœ“ โœ“
pcntl โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pcov โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pdo_dblib โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pdo_firebird โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pdo_mysql โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pdo_oci โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pdo_odbc โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pdo_pgsql โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pdo_sqlsrv* โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pgsql โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
propro โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
protobuf โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pspell โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
pthreads* โœ“ โœ“ โœ“
raphf โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
rdkafka โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
recode โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
redis โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
seaslog โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
shmop โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
smbclient โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
snmp โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
snuffleupagus โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
soap โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
sockets โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
solr โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
sourceguardian โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
spx โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
sqlsrv* โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
ssh2 โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
stomp โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
swoole โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
sybase_ct โœ“ โœ“
sysvmsg โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
sysvsem โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
sysvshm โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
tensor* โœ“ โœ“ โœ“ โœ“
tidy โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
timezonedb โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
uopz โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
uploadprogress โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
uuid โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
vips* โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
wddx โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
xdebug โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
xhprof โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
xlswriter โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
xmldiff โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
xmlrpc โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
xsl โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
yac โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
yaml โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
yar โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
zephir_parser โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
zip โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
zookeeper โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“
zstd โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“ โœ“

Number of supported extensions: 116

This extension comes fromhttps://github.com/mlocati/docker-php-extension-installer Refer to the sample files

3.4 Using php command line in Host (php-cli)

  1. referencebash.alias.sampleSample file, copy the corresponding php cli function to the host ~/.bashrcFile.
  2. To make a file work:
    source ~/.bashrc
  3. You can then execute php commands in the host:
    ~ php -v
    PHP 7.2.13 (cli) (built: Dec 21 2018 02:22:47) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.2.13, Copyright (c) 1999-2018, by Zend Technologies
        with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans

3.5 Use commoser

Method 1: Use the compare command in the host

  1. Determine the path to the compiler cache. For example, my dnmp download is in~/dnmpdirectory, that compiler's cache path is~/dnmp/data/composerใ€‚
  2. referencebash.alias.sampleA sample file that copies the corresponding php composer function to the host ~/.bashrcFile.

    It is important to note here that the sample file is in~/dnmp/data/composerThe directory needs to be the directory identified in the first step.

  3. To make a file work:
    source ~/.bashrc
  4. You can use a composer in any directory on the host:
    cd ~/dnmp/www/
    composer create-project yeszao/fastphp project --no-dev
  5. Optionally, the first time you use composer, it will be ~/dnmp/data/composer Generate one under the directoryconfig.jsonfile, in which you can specify a domestic repository, for example:
    {
        "config": {},
        "repositories": {
            "packagist": {
                "type": "composer",
                "url": "https://mirrors.aliyun.com/composer/"
            }
        }
    }
    

Method 2: Use the composer command inside the container

There is another way, which is to go into the container and executecomposerCommand, using the PHP7 container as an example:

docker exec -it php /bin/sh
cd /www/localhost
composer update

4. Administrative commands

4.1 Server Startup and Build Commands

To manage services, follow the command with the server name, for example:

$ docker-compose up                         # ๅˆ›ๅปบๅนถไธ”ๅฏๅŠจๆ‰€ๆœ‰ๅฎนๅ™จ
$ docker-compose up -d                      # ๅˆ›ๅปบๅนถไธ”ๅŽๅฐ่ฟ่กŒๆ–นๅผๅฏๅŠจๆ‰€ๆœ‰ๅฎนๅ™จ
$ docker-compose up nginx php mysql         # ๅˆ›ๅปบๅนถไธ”ๅฏๅŠจnginxใ€phpใ€mysql็š„ๅคšไธชๅฎนๅ™จ
$ docker-compose up -d nginx php  mysql     # ๅˆ›ๅปบๅนถไธ”ๅทฒๅŽๅฐ่ฟ่กŒ็š„ๆ–นๅผๅฏๅŠจnginxใ€phpใ€mysqlๅฎนๅ™จ


$ docker-compose start php                  # ๅฏๅŠจๆœๅŠก
$ docker-compose stop php                   # ๅœๆญขๆœๅŠก
$ docker-compose restart php                # ้‡ๅฏๆœๅŠก
$ docker-compose build php                  # ๆž„ๅปบๆˆ–่€…้‡ๆ–ฐๆž„ๅปบๆœๅŠก

$ docker-compose rm php                     # ๅˆ ้™คๅนถไธ”ๅœๆญขphpๅฎนๅ™จ
$ docker-compose down                       # ๅœๆญขๅนถๅˆ ้™คๅฎนๅ™จ๏ผŒ็ฝ‘็ปœ๏ผŒๅ›พๅƒๅ’ŒๆŒ‚่ฝฝๅท

4.2 Add shortcut commands

At the time of development, we may use it oftendocker exec -itEntering the container and aliasing the commands commonly used is a convenient way to do so.

First, review the available containers in the host:

$ docker ps           # ๆŸฅ็œ‹ๆ‰€ๆœ‰่ฟ่กŒไธญ็š„ๅฎนๅ™จ
$ docker ps -a        # ๆ‰€ๆœ‰ๅฎนๅ™จ

OutputNAMESThat column is the name of the container, or if the default configuration is used, then the name isnginxใ€phpใ€php56ใ€mysqlWait.

Then, open~/.bashrcor~/.zshrcfile, plus:

alias dnginx='docker exec -it nginx /bin/sh'
alias dphp='docker exec -it php /bin/sh'
alias dphp56='docker exec -it php56 /bin/sh'
alias dphp54='docker exec -it php54 /bin/sh'
alias dmysql='docker exec -it mysql /bin/bash'
alias dredis='docker exec -it redis /bin/sh'

The next time you enter the container, it is very fast, such as entering the php container:

$ dphp

4.3 View docker networks

ifconfig docker0

For filling inextra_hostsThe container accesses the hosthostsaddress

5. Use Log

The location where the log file is generated depends on the value of each log configuration under conf.

5.1 Nginx logs

Nginx logs are the logs we use the most, so we put them separately in the root directorylogUnder.

logThe directory will be mapped for the Nginx container/var/log/nginxdirectory, so in the Nginx configuration file, the location of the output log needs to be configured/var/log/nginxDirectories, such as:

error_log  /var/log/nginx/nginx.localhost.error.log  warn;

5.2 PHP-FPM logs

In most cases, PHP-FPM logs are output to Nginx's logs, so no additional configuration is required.

In addition, it is recommended to open the error log directly in PHP:

error_reporting(E_ALL);
ini_set('error_reporting', 'on');
ini_set('display_errors', 'on');

If you really need it, you can open it (in a container) by following the steps below.

  1. Go to the container, create a log file, and modify the permissions:
    $ docker exec -it php /bin/sh
    $ mkdir /var/log/php
    $ cd /var/log/php
    $ touch php-fpm.error.log
    $ chmod a+w php-fpm.error.log
  2. Open and modify the configuration file for PHP-FPM on the hostconf/php-fpm.conf, find the following line, delete the comment, and change the value to: php_admin_value[error_log] = /var/log/php/php-fpm.error.log
  3. Restart the PHP-FPM container.

5.3 MySQL logs

Because MySQL in the MySQL container is usedmysqlThe user starts, it cannot be self-contained/var/logAdd log files under Add log files. So, we put mySQL logs in the same directory as data, i.e. projectsmysqldirectory, corresponding to the container/var/log/mysql/Directory.

slow-query-log-file     = /var/log/mysql/mysql.slow.log
log-error               = /var/log/mysql/mysql.error.log

The above is the configuration of the log file in mysql.conf.

6. Database management

This project defaults to docker-compose.ymlFor MySQL online management is not turned onphpMyAdmin, and for redis online managementphpRedisAdmin, which can be modified or deleted as needed.

6.1 phpMyAdmin

The port address of the phpMyAdmin container mapped to the host is:8080, so the address on the host to access phpMyAdmin is:

http://localhost:8080

MySQL connection information:

  • host: (MySQL container network for this project)
  • port๏ผš3306
  • username:(Manually entered in the phpmyadmin interface)
  • password:(Manually entered in the phpmyadmin interface)

6.2 phpRedisAdmin

The port address of the phpRedisAdmin container mapped to the host is:8081, so the address on the host to access phpMyAdmin is:

http://localhost:8081

The Redis connection information is as follows:

  • host: (Redis Container Network for this project)
  • port: 6379

7. Safe to use in a formal environment

To use in a formal environment, please:

  1. Turn off XDebug debugging in php .ini
  2. Security policies to enhance Access to MySQL databases
  3. Enhanced security policies for redis access

8 Frequently Asked Questions

8.1 How to use curl in PHP code?

Refer to this issue:yeszao#91

8.2 Docker uses cron to time tasks

Docker uses cron to time tasks

8.3 Docker container time

The container time is configured in an .env fileTZFor variables, see all supported time zonesList of time zones on WikipediaorList of time zones supported by PHPยท PHP official websiteใ€‚

8.4 How to connect to MySQL and Redis servers

There are two cases of this.

The first case, inPHP codeใ€‚

// ่ฟžๆŽฅMySQL
$dbh = new PDO('mysql:host=mysql;dbname=mysql', 'root', '123456');

// ่ฟžๆŽฅRedis
$redis = new Redis();
$redis->connect('redis', 6379);

Because containers are containersexposeThe ports are connected, and they are in the same onenetworksdown, so connectedhostParameters directly with the container name,portThe parameter is the port inside the container. Please refer to it for moreThe Difference Between Docker-compose Ports and Expoใ€‚

In the second case,In the hostPasscommand lineorNavicatand other tools connected. For the host to connect mysql and redis, the container must pass throughportsThe port is mapped to the host. Take mysql as an example.docker-compose.ymlThere is such a thing in the documentportsDisposition:3306:3306, that is, the 3306 port of the host and the 3306 port of the container form a map, so we can connect like this:

$ mysql -h127.0.0.1 -uroot -p123456 -P3306
$ redis-cli -h127.0.0.1

Over herehostThe parameter cannot be used localhost because it communicates with mysql through the sock file by default, and the container is isolated from the host file system, so it needs to be connected via TCP, so you need to specify the IP.

8.5 How php in a container connects to host MySQL

1. Host executionifconfig docker0getinetIt's about connectingipaddress

$ ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ...

2. Run the host Mysql command line

 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
 mysql>flush privileges;
// ๅ…ถไธญๅ„ๅญ—็ฌฆ็š„ๅซไน‰๏ผš
// *.* ๅฏนไปปๆ„ๆ•ฐๆฎๅบ“ไปปๆ„่กจๆœ‰ๆ•ˆ
// "root" "123456" ๆ˜ฏๆ•ฐๆฎๅบ“็”จๆˆทๅๅ’Œๅฏ†็ 
// '%' ๅ…่ฎธ่ฎฟ้—ฎๆ•ฐๆฎๅบ“็š„IPๅœฐๅ€๏ผŒ%ๆ„ๆ€ๆ˜ฏไปปๆ„IP๏ผŒไนŸๅฏไปฅๆŒ‡ๅฎšIP
// flush privileges ๅˆทๆ–ฐๆƒ้™ไฟกๆฏ

3. Then use the php container directly172.0.17.1:3306Just connect

8.6 SQLSTATE[HY000] [1130] Host '172.19.0.2' is not allowed to connect to this MySQL server

  1. Currently using mysql-server 8.0.28The above version, php version is required7.4.7The above can only be connected

License

MIT