Docker集成多项目LNMP环境(php7.1-fpm+mysql5.7+nginx+redis+composer)
├── README .md
├── docker-compose.yml
├── logs
│ └── default_access.log
├── nginx
│ └── default .conf
├── php-fpm
│ ├── Dockerfile
│ ├── php-ini-overrides.ini
│ └── sources.list //阿里云apt源
└── www //项目目录
└── default
确保已经安装docker
和docker-compose
git clone
到本地,cd /path/to/docker-lnmp
,启动docker-compose up -d
启动完毕就可以访问http://localhost:8000 看到phpinfo
页面了
docker-compose ps
查看所有服务是否已启动
进入php-fpm容器docker-compose exec php-fpm bash
,并新建一个laravel项目
app$ cd www && composer create-project --prefer-dist laravel/laravel blog "5.5.*"
复制一份nginx配置cp docker-lnmp/nginx/default.conf docker-lnmp/nginx/blog.test.conf
,并修改
server_name blog.test
...
access_log /app/logs/blog_access.log; //可选
#error_log /app/logs/blog_error.log; //可选
root /app/www/blog/public;
...
location / {
try_files $uri $uri/ /index.php?$query_string;
}
重启Nginx,docker-compose exec webserver nginx -s reload
在本地hosts添加127.0.0.1 blog.test
,浏览器打开http://blog.test:8000
连接mysql,redis请在.env
中host为(docker-compose.yml的services的名字)
DB_HOST=mysql
REDIS_HOST=redis
navicate连接mysql
host: 127.0.0.1
username: root
password: secret //在docker-compose.yml中配置的MYSQL_ROOT_PASSWORD=secret
port: 8002