DNMP (Docker + Nginx/Openresty + MySQL5,8 + PHP5,7,8 + Redis + ElasticSearch + MongoDB + RabbitMQ) is a full-featured LNMP one-click installation program that supports Arm CPU .
There are some recommendations for overseas job opportunities. Friends who are interested can take a look.
100%
open source100%
compliant with Docker standardspdo_mysql
, mysqli
, mbstring
, gd
, curl
, opcache
, etc., and can be flexibly configured according to the environment.100%
availabilityinstall-php-extensions apcu
/
├── 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 代码目录
- `git`
- `Docker`(系统需为Linux,Windows 10 Build 15063+,或MacOS 10.12+,且必须要`64`位)
- `docker-compose 1.7.0+`
clone
project: ```
$ git clone https://github.com/yeszao/dnmp.git
```
root
user, you also need to add the current user to the docker
user group: ```
$ sudo gpasswd -a ${USER} docker
```
copy
command), and start: ```
$ cd dnmp # 进入项目目录
$ cp env.sample .env # 复制环境变量文件。note:安装php扩展请查看文档中的3.2小节
$ cp docker-compose.sample.yml docker-compose.yml # 复制 docker-compose 配置文件。默认启动3个服务:
# Nginx、PHP7和MySQL8。要开启更多其他服务,如Redis、
# PHP5.6、PHP5.4、MongoDB,ElasticSearch等,请删
# 除服务块前的注释
$ docker-compose up # 启动
```
http://localhost
or https://localhost
(self-signed HTTPS demo) to see the effect. The PHP code is in the file ./www/localhost/index.php
. First, you need to start other versions of PHP, such as PHP5.4, then delete the comments in front of PHP5.4 in the docker-compose.yml
file, and then start the PHP5.4 container.
After PHP5.4 is started, open the Nginx configuration and modify the host address of fastcgi_pass
from php
to php54
, as follows:
fastcgi_pass php:9000;
for:
fastcgi_pass php54:9000;
Where php
and php54
are the names of the servers in the docker-compose.yml
file.
Finally, restart Nginx to take effect.
$ docker exec -it nginx nginx -s reload
There are two nginx
here, the first is the container name, and the second is the nginx
program in the container.
Many functions of PHP are implemented through extensions, and installing extensions is a slightly time-consuming process. Therefore, in addition to PHP's built-in extensions, we only install a few extensions by default in the env.sample
file. If you want to install more extensions, please Open your .env
file and modify the following PHP configuration, adding the required PHP extensions:
PHP_EXTENSIONS=pdo_mysql,opcache,redis # PHP 要安装的扩展列表,英文逗号隔开
PHP54_EXTENSIONS=opcache,redis # PHP 5.4要安装的扩展列表,英文逗号隔开
Then rebuild the PHP image.
docker-compose build php
For available extensions, please see the env.sample
comment block in the same file for description.
1. Enter the container:
docker exec -it php /bin/sh
install-php-extensions apcu
2.Support quick installation of extension list
Extension | PHP 8.4 | PHP 8.3 | PHP 8.2 | PHP 8.1 | PHP 8.0 | PHP 7.4 | PHP 7.3 | PHP 7.2 | PHP 7.1 | PHP 7.0 | PHP 5.6 | PHP 5.5 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
amqp | ||||||||||||
apcu | ||||||||||||
apcu_bc | ||||||||||||
ast | ||||||||||||
bcmath | ||||||||||||
bitset | ||||||||||||
blackfire | ||||||||||||
bz2 | ||||||||||||
calendar | ||||||||||||
cassandra* | ||||||||||||
cmark | ||||||||||||
csv | ||||||||||||
dba | ||||||||||||
ddtrace* | ||||||||||||
decimal | ||||||||||||
ds | ||||||||||||
ecma_intl* | ||||||||||||
enchant | ||||||||||||
ev | ||||||||||||
event | ||||||||||||
excimer | ||||||||||||
exif | ||||||||||||
ffi | ||||||||||||
ftp | ||||||||||||
gd | ||||||||||||
gearman | ||||||||||||
geoip | ||||||||||||
geos* | ||||||||||||
geospatial | ||||||||||||
gettext | ||||||||||||
gmagick | ||||||||||||
gmp | ||||||||||||
gnupg | ||||||||||||
grpc | ||||||||||||
http | ||||||||||||
igbinary | ||||||||||||
imagick | ||||||||||||
imap | ||||||||||||
inotify | ||||||||||||
interbase | ||||||||||||
intl | ||||||||||||
ion | ||||||||||||
ioncube_loader | ||||||||||||
jsmin | ||||||||||||
json_post | ||||||||||||
jsonpath | ||||||||||||
ldap | ||||||||||||
luasandbox | ||||||||||||
lz4* | ||||||||||||
zf | ||||||||||||
mailparse | ||||||||||||
maxminddb | ||||||||||||
mcrypt | ||||||||||||
memcache | ||||||||||||
memcached | ||||||||||||
memprof* | ||||||||||||
mongo | ||||||||||||
mongodb | ||||||||||||
mosquitto | ||||||||||||
msgpack | ||||||||||||
mssql | ||||||||||||
mysql | ||||||||||||
mysqli | ||||||||||||
newrelic | ||||||||||||
oauth | ||||||||||||
oci8 | ||||||||||||
odbc | ||||||||||||
opcache | ||||||||||||
opencensus | ||||||||||||
openswoole | ||||||||||||
opentelemetry | ||||||||||||
parallel* | ||||||||||||
parle* | ||||||||||||
pcntl | ||||||||||||
pcov | ||||||||||||
pdo_dblib | ||||||||||||
pdo_firebird | ||||||||||||
pdo_mysql | ||||||||||||
pdo_oci | ||||||||||||
pdo_odbc | ||||||||||||
pdo_pgsql | ||||||||||||
pdo_sqlsrv | ||||||||||||
pgsql | ||||||||||||
phalcon | ||||||||||||
php_trie | ||||||||||||
phpy* | ||||||||||||
pkcs11 | ||||||||||||
pq | ||||||||||||
propro | ||||||||||||
protobuf | ||||||||||||
pspell | ||||||||||||
psr | ||||||||||||
pthreads* | ||||||||||||
raphf | ||||||||||||
rdkafka | ||||||||||||
recode | ||||||||||||
redis | ||||||||||||
relay | ||||||||||||
saxon* | ||||||||||||
seasclick | ||||||||||||
seaslog | ||||||||||||
shmop | ||||||||||||
simdjson* | ||||||||||||
smbclient | ||||||||||||
snappy | ||||||||||||
snmp | ||||||||||||
snuffleupagus | ||||||||||||
soap | ||||||||||||
sockets | ||||||||||||
sodium* | ||||||||||||
solr | ||||||||||||
sourceguardian | ||||||||||||
spx | ||||||||||||
sqlsrv* | ||||||||||||
ssh2 | ||||||||||||
stomp | ||||||||||||
swoole | ||||||||||||
sybase_ct | ||||||||||||
sync | ||||||||||||
sysvmsg | ||||||||||||
sysvsem | ||||||||||||
sysvshm | ||||||||||||
tensor | ||||||||||||
tideways | ||||||||||||
tidy | ||||||||||||
timezonedb | ||||||||||||
uopz | ||||||||||||
uploadprogress | ||||||||||||
uuid | ||||||||||||
uv | ||||||||||||
vips* | ||||||||||||
vld | ||||||||||||
xx | ||||||||||||
wikidiff2* | ||||||||||||
xdebug | ||||||||||||
xdiff | ||||||||||||
xhpr | ||||||||||||
xlswriter | ||||||||||||
xmldiff | ||||||||||||
xmlrpc | ||||||||||||
xpass* | ||||||||||||
xsl | ||||||||||||
yac | ||||||||||||
yaml | ||||||||||||
yar | ||||||||||||
zephir_parser | ||||||||||||
zip | ||||||||||||
zq | ||||||||||||
zookeeper | ||||||||||||
zstd |
Number of supported extensions: 150
This extension comes from https://github.com/mlocati/docker-php-extension-installer Reference sample file
~/.bashrc
file of the host. source ~ /.bashrc
~ 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
Method 1: Use the composer command on the host
~/dnmp
directory, then the cache path of composer is ~/dnmp/data/composer
.~/.bashrc
file of the host.What needs to be noted here is that the
~/dnmp/data/composer
directory in the example file needs to be the directory determined in the first step.
source ~ /.bashrc
cd ~ /dnmp/www/
composer create-project yeszao/fastphp project --no-dev
~/dnmp/data/composer
directory. You can specify the domestic warehouse in this file, for example: {
"config" : {},
"repositories" : {
"packagist" : {
"type" : " composer " ,
"url" : " https://mirrors.aliyun.com/composer/ "
}
}
}
Method 2: Use the composer command in the container
There is another way, which is to enter the container and then execute the composer
command. Take the PHP7 container as an example:
docker exec -it php /bin/sh
cd /www/localhost
composer update
To manage the service, add the server name after the command, 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 # 停止并删除容器,网络,图像和挂载卷
During development, we may often use docker exec -it
to enter the container. It is a trouble-free method to make commonly used command aliases.
First, check the available containers on the host:
$ docker ps # 查看所有运行中的容器
$ docker ps -a # 所有容器
The output NAMES
column is the name of the container. If the default configuration is used, the name is nginx
, php
, php56
, mysql
, etc.
Then, open the ~/.bashrc
or ~/.zshrc
file and add:
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 '
It will be very fast to enter the container next time. For example, enter the php container:
$ dphp
ifconfig docker0
Used to fill in the hosts
address of the extra_hosts
container to access the host machine
The location where the log file is generated depends on the value of each log configuration under conf.
Nginx log is the log we use most, so we put it separately in the root directory log
.
The log
directory maps the /var/log/nginx
directory of the Nginx container, so in the Nginx configuration file, where the log needs to be output, we need to configure it to the /var/log/nginx
directory, such as:
error_log /var/log/nginx/nginx.localhost.error.log warn;
In most cases, PHP-FPM's logs will be output to Nginx's logs, so no additional configuration is required.
Additionally, 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, follow the steps to open it (in the container).
$ 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
conf/php-fpm.conf
on the host, find the following line, delete the comment, and change the value to: php_admin_value[error_log] = /var/log/php/php-fpm.error.log
Because MySQL in the MySQL container is started by the mysql
user, it cannot add log files under /var/log
by itself. Therefore, we put the MySQL log in the same directory as data, that is, under the mysql
directory of the project, corresponding to the /var/log/mysql/
directory in the container.
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.
By default, this project does not enable phpMyAdmin for MySQL online management and phpRedisAdmin for redis online management in docker-compose.yml
They can be modified or deleted as needed.
The port address mapped by the phpMyAdmin container to the host is: 8080
, so the address to access phpMyAdmin on the host is:
http://localhost:8080
MySQL connection information:
3306
The port address mapped by the phpRedisAdmin container to the host is: 8081
, so the address to access phpMyAdmin on the host is:
http://localhost:8081
Redis connection information is as follows:
6379
For use in a production environment:
Refer to this issue: #91
Docker uses cron scheduled tasks
The container time is configured with the TZ
variable in the .env file. For all supported time zones, please see the time zone list·Wikipedia or the time zone list supported by PHP·PHP official website.
This can be divided into two situations,
The first case, in PHP code .
// 连接MySQL
$ dbh = new PDO ( ' mysql:host=mysql;dbname=mysql ' , ' root ' , ' 123456 ' );
// 连接Redis
$ redis = new Redis ();
$ redis -> connect ( ' redis ' , 6379 );
Because the container and the container are connected through the expose
port and are in the same networks
, the host
parameter of the connection directly uses the container name, and port
parameter is the port inside the container. For more information, please refer to "The Difference Between Docker-compose Ports and Expose".
In the second case, connect through the command line or Navicat and other tools on the host . If the host wants to connect mysql and redis, the container must map the port to the host through ports
. Taking mysql as an example, there is such ports
configuration in the docker-compose.yml
file: 3306:3306
, which means that the 3306 port of the host and the 3306 port of the container form a mapping, so we can connect like this:
$ mysql -h127.0.0.1 -uroot -p123456 -P3306
$ redis-cli -h127.0.0.1
The host
parameter cannot use localhost here because it communicates with mysql through the sock file by default, and the container and the host file system have been isolated, so it needs to be connected through TCP, so the IP needs to be specified.
1. The host executes ifconfig docker0
to get inet
, which is the ip
address to be connected.
$ 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 directly connect to the php container using 172.0.17.1:3306
8.0.28
or above, PHP version requires 7.4.7
or above to connect.How to generate a container name when the container name is not specified
MIT