docker-compose实现lnmp
时间: 2023-12-10 17:36:00 浏览: 120
以下是使用docker-compose实现lnmp的步骤:
1.安装Docker和Docker Compose
2.创建一个项目目录,例如:/home/lnmp
3.在目录下创建一个docker-compose.yml文件,内容如下:
```yaml
version: '3'
services:
nginx:
image: nginx
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./html:/usr/share/nginx/html
depends_on:
- php
php:
image: php:7.2-fpm
volumes:
- ./html:/var/www/html
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./mysql:/var/lib/mysql
```
4.在该目录下创建一个nginx.conf文件,内容如下:
```nginx
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
```
5.在该目录下创建一个html目录,用于存放网站文件。
6.在终端中进入该目录,运行以下命令启动容器:
```shell
docker-compose up -d
```
7.访问http://localhost即可看到网站。
阅读全文