基于DNMP + laravel 快速搭建本地项目开发环境(Mac版本)

2 篇文章 0 订阅
1 篇文章 0 订阅

好的东西需要分享!

如果把程序开发人员都比作奋勇向前的勇士,那么一套完整而又好用的开发环境就将是他们心驰神往的噬魂战场!

定义:完整好用的环境

  • 可以快速版本切换
  • 可以方便迁移,快速部署,切换不同环境开箱即用
  • 可以便捷引入新的技术,真正把精力用在技术研究,而非环境构建
  • … …

随着时间经验的积累,终于实现了一套令自己满意的开发战场,未来会更加完善!

快速使用

1.本地安装

  • git
  • docker
  • docker-compose

2.clone项目

git clone https://github.com/LiuweiGHub/dnmp

3.拷贝并命名配置文件&&启动

  • cd dnmo
  • cp env.sample .env
  • cp docker-compose.sample.yml docker-compose.yml
  • docker-compose up

Dnmp环境搭建完毕,是不是简单到开箱即用?
浏览器访问:http://localhost

结合laravel项目

当然真正的项目开发我们还需要把自己熟悉的框架整合进来,现以laravel框架为例:

  • cd ~/dnmp/www (注意是你自己的dnpm目录)
  • composer create-project --prefer-dist laravel/laravel demo
  • vi ~/dnmp/services/nginx/conf.d/localhost.conf
server {
    listen       80  default;
    server_name localhost;
    set $root_path /www/demo/public;
    root $root_path;

    index index.php index.html index.htm;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {

        fastcgi_pass php:9000;
        fastcgi_index /index.php;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include                       fastcgi_params;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}

laravel .env 数据库配置:
在这里插入图片描述
DB_HOST是docker-compose.yml服务名,DB_PORT是docker中MySQL的端口

重启dnmp : docker-comose restart 即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值