Skip to content

Commit

Permalink
docs:更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyaxian committed Jan 26, 2021
1 parent a4d9270 commit 3729ba8
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
104 changes: 56 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,85 @@
# Docker-LNMP
利用 Docker-Compose 编排 LNMP开发环境

利用 Docker-Compose 编排 LNMP 开发环境

### 清单
> 注: 完整版(docker-compose up -d)
- PHP7.2

> 注: 完整版(docker-compose.yml、docker-compose-fast.yml)
- PHP 7.2
- Nginx
- MySQL5.6
- MySQL 5.6
- Redis
- phpMyAdmin
- phpRedisAdmin
> 注: 精简版(docker-compose -f docker-compose-simplify.yml up -d)
- PHP7.2
- phpRedisAdmin

> 注: 精简版(docker-compose-simplify.yml)
- PHP 7.2
- Nginx
- MySQL5.6
- Redis
- MySQL 5.6
- Redis

### 目录结构
```
Docker-LNMP
|----docker Docker目录
|----docker Docker 目录
|--------config 配置文件目录
|------------proxy nginx配置文件目录
|--------files DockerFile文件目录
|------------cgi php-fpm DockerFile文件目录
|----------------Dockerfile php-fpm DockerFile文件
|------------proxy Nginx 配置文件目录
|--------files DockerFile 文件目录
|------------cgi php-fpm DockerFile 文件目录
|----------------Dockerfile php-fpm DockerFile 文件
|----------------docker-entrypoint.sh php-fpm 启动脚本
|------------proxy nginx DockerFile文件目录
|----------------Dockerfile nginx DockerFile文件
|----------------docker-entrypoint.sh nginx 启动脚本
|------------proxy Nginx DockerFile 文件目录
|----------------Dockerfile Nginx DockerFile 文件
|----------------docker-entrypoint.sh Nginx 启动脚本
|--------log 日志文件目录
|------------cgi php-fpm日志文件目录
|------------proxy nginx日志文件目录
|------------cgi php-fpm 日志文件目录
|------------proxy Nginx 日志文件目录
|----www 应用根目录
|--------index.php PHP例程
|--------index.php PHP 例程
|----README.md 说明文件
|----docker-compose.yml docker compose 配置文件(完整版: LNMP+Redis+phpMyAdmin+phpRedisAdmin)
|----docker-compose-simplify.yml docker compose 配置文件(精简版: LNMP+Redis)
|----docker-compose.yml docker compose 配置文件完整版: LNMP + Redis + phpMyAdmin + phpRedisAdmin
|----docker-compose-simplify.yml docker compose 配置文件精简版: LNMP + Redis
```

### 准备

```shell
# 安装docker和docker-compose
# 安装 Docker 和 Docker-Compose
yum -y install epel-release
yum -y install docker docker-compose

# 启动docker服务
# 启动 Docker 服务
service docker start

# 配置阿里云docker镜像加速器(建议配置加速器, 可以提升docker拉取镜像的速度)
# 配置阿里云 Docker 镜像加速器(建议配置加速器, 可以提升 Docker 拉取镜像的速度)
mkdir -p /etc/docker
vim /etc/docker/daemon.json

# 新增下面内容
{
"registry-mirrors": ["https://8auvmfwy.mirror.aliyuncs.com"]
}
# 重新加载配置、重启docker

# 重新加载配置、重启 Docker
systemctl daemon-reload
systemctl restart docker
```

### 安装

```shell
# 克隆项目
git clone https://github.com/duiying/Docker-LNMP.git
# 进入目录
cd Docker-LNMP
# 容器编排
docker-compose up -d
# 或使用加速版(推荐, 耗时约10分钟)
# 容器编排(使用加速版,推荐,耗时约 10 分钟)
docker-compose -f docker-compose-fast.yml up -d
# 或使用精简版
docker-compose -f docker-compose-simplify.yml up -d
```

### 测试
执行成功

执行成功

```
Creating cgi ... done
Creating proxy ... done
Expand All @@ -80,25 +89,21 @@ Creating phpredisadmin ...
Creating cgi ...
Creating proxy ...
```
访问IP, 效果图如下
![效果图](https://raw.githubusercontent.com/duiying/img/master/docker-lnmp.png)

访问 IP,效果图如下(可能需要等几秒钟):

<div align=center><img src="https://raw.githubusercontent.com/duiying/img/master/docker-lnmp.png" width="600"></div>

### 学习文档

- [如何新建一个站点](docs/如何新建一个站点.md)
- [如何安装yaf扩展](docs/如何安装yaf扩展.md)
- [如何安装swoole扩展](docs/如何安装swoole扩展.md)
- [如何安装 af 扩展](docs/如何安装Yaf扩展.md)
- [如何安装 Swoole 扩展](docs/如何安装Swoole扩展.md)

### 可能遇到的问题
```bash
# Error信息
The "https://packagist.phpcomposer.com/packages.json" file could not be down
# 解决方案
这是由于composer中国镜像失效, 修改Docker-LNMP/docker/files/cgi/Dockerfile
https://packagist.phpcomposer.com 改为 https://mirrors.aliyun.com/composer/
```

```bash
# Error信息
# Error 信息
ERROR: for mysql Cannot start service mysql: endpoint with name mysql already exists in network docker-lnmp_default
# 解决方案
这是由于端口被占用,需要清理此容器的网络占用
Expand All @@ -107,13 +112,16 @@ docker network disconnect --force docker-lnmp_default mysql
检查是否还有其它容器占用
格式:docker network inspect 网络模式
```
### 更新日志
- cgi容器支持crontab
- PHP支持rdkafka扩展
- PHP支持POSIX、PCNTL扩展
- cgi 容器支持 crontab
- PHP 支持 rdkafka 扩展
- PHP 支持 POSIX、PCNTL 扩展
- 新增学习文档
### Docker常用命令
### Docker 常用命令
```shell
# 删除所有容器
docker rm -f $(docker ps -aq)
Expand Down
2 changes: 1 addition & 1 deletion docker/files/cgi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN yum install -y --enablerepo=remi --enablerepo=remi-php72 \

RUN curl -sSL https://getcomposer.org/installer | php &&\
mv composer.phar /usr/local/bin/composer &&\
composer config -g repo.packagist composer https://packagist.phpcomposer.com &&\
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ &&\
composer global require fxp/composer-asset-plugin v1.4.2 -vvv

RUN sed -i 's/listen = 127.0.0.1:9000/listen = [::]:9000/p' /etc/php-fpm.d/www.conf &&\
Expand Down
2 changes: 1 addition & 1 deletion docker/files/cgi/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# @auther <1822581649@qq.com>
# @auther <wangyaxiandev@gmail.com>

/usr/sbin/init
/usr/sbin/crond
Expand Down
2 changes: 1 addition & 1 deletion docker/files/proxy/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# @auther <1822581649@qq.com>
# @auther <wangyaxiandev@gmail.com>

echo "info: nginx non-daemon startup"
nginx -c /etc/nginx/nginx.conf
Expand Down
5 changes: 0 additions & 5 deletions docs/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 如何安装swoole扩展
# 如何安装 Swoole 扩展

#### 如何安装swoole扩展
#### 如何安装 Swoole 扩展

```shell
# 进入PHP容器
# 进入 PHP 容器
[root@localhost Docker-LNMP]# docker exec -it cgi bash

# 解决gcc版本过低的问题
# 解决 gcc 版本过低的问题
yum -y install centos-release-scl
yum -y install devtoolset-7
scl enable devtoolset-7 bash
Expand All @@ -21,11 +21,11 @@ wget https://github.com/swoole/swoole-src/archive/v4.2.1.tar.gz &&\
sed -i '$a \\n[swoole]\nextension=swoole.so' /etc/php.ini &&\
cd ../ && rm -rf v4.2.1.tar.gz swoole-src-4.2.1

# 退出PHP容器
# 退出 PHP 容器
[root@510d01c199f5 /]# exit
exit

# 重启PHP容器
# 重启 PHP 容器
[root@localhost Docker-LNMP]# docker restart cgi
```

Expand Down
12 changes: 6 additions & 6 deletions docs/如何安装yaf扩展.md → docs/如何安装Yaf扩展.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 如何安装yaf扩展
# 如何安装 Yaf 扩展

#### 安装yaf扩展
#### 安装 Yaf 扩展

```shell
# 进入PHP容器
# 进入 PHP 容器
[root@localhost Docker-LNMP]# docker exec -it cgi bash

# 下载、安装
Expand All @@ -16,12 +16,12 @@ wget http://pecl.php.net/get/yaf-3.0.8.tgz &&\
sed -i '$a \\n[yaf]\nextension=yaf.so\nyaf.environ=product' /etc/php.ini &&\
cd ../ && rm -rf yaf-3.0.8.tgz yaf-3.0.8

# 退出PHP容器
# 退出 PHP 容器
[root@510d01c199f5 /]# exit
exit

# 重启PHP容器
# 重启 PHP 容器
[root@localhost Docker-LNMP]# docker restart cgi
```

![yaf](https://raw.githubusercontent.com/duiying/img/master/yaf.png)
<div align=center><img src="https://raw.githubusercontent.com/duiying/img/master/yaf.png" width="600"></div>
81 changes: 35 additions & 46 deletions docs/如何新建一个站点.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,63 @@
# 如何新建一个站点

比如部署一个Yii2项目 https://github.com/duiying/Yii2-Admin , 并且可以通过 http://frontend.yii2.test 访问
比如部署一个 Lumen 项目,并且可以通过 http://lumen-app.com 访问

#### 1. 配置Nginx
```shell
# Docker-LNMP/docker/config/proxy/conf.d 目录下新建一个配置文件 yii2-docker.conf
[root@localhost Docker-LNMP]# vim docker/config/proxy/conf.d/yii2-docker.conf
```
yii2-docker.conf 内容如下:
```
server {
**1、配置 Nginx**

listen 80;
Docker-LNMP/docker/config/proxy/conf.d 目录下新建一个配置文件 lumen-app.conf,lumen-app.conf 内容如下:

server_name frontend.yii2.test;
root /data/www/Yii2-Admin/frontend/web;
index index.php index.html index.htm;
```
server {
listen 80;
server_name lumen-app.com;
root /data/www/lumen-app/public;
index index.html index.htm index.php;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass cgi:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
```

#### 2. 克隆项目
**2、安装 Lumen 项目**

```shell
# Docker-LNMP/www 目录下安装 https://github.com/duiying/Yii2-Admin , 安装过程如下:
[root@localhost Docker-LNMP]# cd www
[root@localhost www]# ls
index.php
[root@localhost www]# git clone https://github.com/duiying/Yii2-Admin.git
[root@localhost www]# ls
index.php Yii2-Admin
# Docker-LNMP/www 目录下安装 Lumen 框架,安装过程如下:

# 更改目录权限
[root@localhost www]# chmod -R 777 Yii2-Admin/
$ cd www
$ ls
index.php
$ composer create-project laravel/lumen lumen-app "5.7.*"
```

#### 3. 修改本地hosts
**3、修改本地 hosts**

```
# 192.168.246.128是虚拟机IP地址
192.168.246.128 frontend.yii2.test
# 这里本地用的是 Macbook,所以这里填的是 127.0.0.1,如果你用的是虚拟机,需要将 127.0.0.1 改成虚拟机的 IP 地址,
127.0.0.1 lumen-app.com
```

#### 4. 重启Nginx
**4、重启 Nginx**

```shell
[root@localhost Docker-LNMP]# docker restart proxy
$ docker restart proxy
proxy
```

#### 5. 浏览器访问
http://frontend.yii2.test
**5、浏览器访问**

访问 http://lumen-app.com,可以看到页面显示出下面欢迎内容:

```
Lumen (5.7.8) (Laravel Components 5.7.*)
```

![yii2-index](https://raw.githubusercontent.com/duiying/img/master/yii2-index.png)
至此,一个 Lumen 项目部署完成。

0 comments on commit 3729ba8

Please sign in to comment.