3 Star 27 Fork 0

youshengyouse / dnmp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

Laravel+Vue开发前后端分离网站

——DNMP开发环境搭建(Docker + Nginx + MySQL5.7 + PHP7.2(预装了 composer) + Redis)

laravel 官方推荐的使用homesteadvalet来搭建开发环境,但基于 docker 搭建开发环境更方便。 laravel学习请加 QQ: 2922800186,vue学习请加QQ: 3180555323

本架构文件适用于Windows、Linux、MacOs

本教程配套视频

GitHub 地址 Gitee 地址

laravel和vue珠联璧合

一.准备工作

  1. 编辑器选择,php建议使用phpstorm,js/css/html等使用vscode

  2. 软件安装

  3. clone项目:

    $ git clone git@gitee.com:advance/dnmp.git
  4. 如果不是root用户,还需将当前用户加入docker用户组:

    $ sudo gpasswd -a ${USER} docker
  5. 拷贝并命名配置文件(为了统一,windows 用户请在 git bash 下工作),启动:

    $ cd dnmp
    $ docker-compose up -d s1 s2 s3 s4 s5
    # 根据需要启动指定服务,这5个服务第一次从镜像构建到容器运行约耗时9分钟
    # 默认安装了5个常用服务: nginx为s1, php为s2,mysql为s3, phpmyadmin为s4,redis为s5
    # .env,docker-compose.yml修改得up -d相应服务就行,如果Dockerfile有修改,请带参考--build
    # 如果只是服务的配置文件进行了修改,如nginx的nginx.conf修改了,请进入容器启动相应服务,如$ docker exec -it s1 nginx -s reload
  6. 在物理理(宿主机)浏览器中访问:

二: PHP

2.1 安装扩展

PHP 的很多功能都是通过扩展实现,而安装扩展较费时间,默认除了 php 内置扩展外,只安装了pdo_mysql,mysqli,mbstring,gd,curl,opcache,想安装其它扩展,请修改.env 文件

PHP_EXTENSIONS=pdo_mysql,opcache,redis       # 扩展以英文逗号隔开

然后重新构建 php 镜像。

docker-compose build s2

2.2 使用 composer 安装依赖

docker exec -it c2 sh
cd /www/localhost
composer update

三:mysql

mysql 数据库放在宿主机上的,没有在容器中,方便管理,第一次启动后,文件夹dnmp\data\mysql5的内容如下

mysql

四:Nginx

  1. 修改host文件,增加如 127.0.0.1 01.laravel.bendi
  2. 配置nginx,增加配置文件 dnmp/services/nginx/conf/sites/laravel.conf,后重启nginx,docker exec -it s1 nginx -s reload

五:管理命令

5.1 服务器启动和构建命令

如需管理服务,请在命令后面加上服务器名称,例如:

$ docker-compose up                 # 创建并且启动所有容器
$ docker-compose up -d              # 创建并且后台运行方式启动所有容器
$ docker-compose up s1 s2 s3        # 创建并且启动nginx、php、mysql的多个容器
$ docker-compose up -d s1 s2 s3     # 创建并且已后台运行的方式启动nginx、php、mysql容器
$ docker-compose start s2           # 启动服务
$ docker-compose stop s2            # 停止服务
$ docker-compose restart s2         # 重启服务
$ docker-compose build s2           # 构建或者重新构建服务
$ docker-compose rm s2              # 删除并且停止php容器
$ docker-compose down               # 停止并删除容器,网络,图像和挂载卷

# 当php.ini修改了,得 docker-compose restart s2
# 当nginx.conf修改了,得docker-compose restart s1
# 当docker-compose.yml中哪个服务修改了,得docker-compose up -d 修改的服务名
# 当Dockerfile修改了,得docker-compose up -d --build 修改的服务名

5.2 添加快捷命令

为了提高效率,对于使用频率较高的命令,写成别名的形式,打开~/.bashrc或者~/.zshrc文件,加上:

alias d1='docker exec -it c1 sh'
alias d2='docker exec -it c2 sh'   # 如果想进入php服务器,命令行输入 d2 就行
alias d3='docker exec -it c3 bash'
alias d5='docker exec -it c5 sh'
alias delc='docker rm -f `docker ps -aq`'       # 删除所有容器
alias deli='docker rmi -f `docker images -aq`'  # 删除所有镜像
alias dc12345='docker-compose up -d s1 s2 s3 s4 s5'  # 删除所有镜像
alias dc123='docker-compose up -d s1 s2 s3'  # 删除所有镜像

常见问题

mysql的root密码问题

如果发现的.env中修改了MYSQL_ROOT_PASSWORD的值,mysql镜像也重新生成了,如果密码仍为修改之前的,那是因为镜像尽管重新生成了,但数据库已储存在宿主机中了,得以原来的密码进入mysql后进行修改就行

Docker 容器时间

容器时间在.env 文件中配置TZ变量,所有支持的时区请看时区列表·维基百科或者PHP 所支持的时区列表·PHP 官网

捐赠

本Docker构建文件填坑,测试,文档编写,视频录制编辑,花了整整两天,你的打赏,是对我最大的鼓励

pay

参考:

License

MIT

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

专门新手定制的 Docker + PHP +Mysql+Nginx开发环境 展开 收起
Docker
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Docker
1
https://gitee.com/advance/dnmp.git
git@gitee.com:advance/dnmp.git
advance
dnmp
dnmp
master

搜索帮助