Docker-compose搭建LNMP
时间: 2024-01-17 21:05:40 浏览: 89
1.安装Docker和Docker-compose
2.创建一个LNMP目录
3.在LNMP目录下创建docker-compose.yml文件
```
version: '2'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/html:/usr/share/nginx/html
depends_on:
- php-fpm
php-fpm:
image: php:7.3-fpm
volumes:
- ./php-fpm:/var/www/html
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: dbname
MYSQL_USER: username
MYSQL_PASSWORD: password
volumes:
- ./mysql:/var/lib/mysql
```
4.创建nginx/conf.d目录,在该目录下创建default.conf文件
```
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
```
5.在LNMP目录下执行docker-compose up -d
6.访问http://localhost,如果能看到Nginx的欢迎页面,则表示成功搭建了LNMP环境。
阅读全文