1.拉取nginx镜像
docker pull nginx:alpine
2.运行nginx容器(如果本地有80可使用其他端口)
docker run --name lnmp-nginx -p 8000:80 -v /opt/nginx/html:/usr/share/nginx/html -v /opt/nginx/conf:/etc/nginx/conf.d -d nginx:alpine
3.配置nginx文件
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .*\.(gif|jpg|jpeg|png|css|js)$ {
root /usr/share/nginx/html/company/public;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /opt/html/company/public;
fastcgi_pass 172.17.0.3:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
路径根据自己的PHP目录调整
4.拉取php镜像
docker pull php:7.2-fpm
5.运行php容器
docker run -p 9000:9000 --name lnmp-php -v /opt/nginx/html:/opt/html -d php:7.2-fpm
6.进入php容器,添加mysql依赖库
docker-php-ext-install mysqli
docker-php-ext-install pdo_mysql
7.数据库使用其他mysql
8.使用php测试页面,添加到指定的目录
vim index.php
<?php
phpinfo();
?>
网友评论