docker快速搭建lnmp开发环境
1、docker-composer配置文件
version: '3' services: nginx: image: nginx:latest ports: - 8080:80 volumes: - ./www:/usr/share/nginx/html depends_on: - php-fpm restart: always networks: - mylnmp php-fpm: image: php:7.2-fpm ports: - 9000:9000 volumes: - ./www:/usr/share/nginx/html depends_on: - mysql restart: always networks: - mylnmp mysql: image: mysql:latest ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: 123456 networks: - mylnmp restart: always networks: mylnmp: name: mylnmp
2、执行docker-compose up -d命令
3、修改nginx.conf
location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass php-fpm:9000; //使用docker-compose中的服务名称 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //这里还是要改 include fastcgi_params; }
4、测试
在根目录新增index.php
<?php phpinfo();
出现这个页面说明部署成功。
小结:docker可以快速搭建lnmp环境,无需在环境搭建上浪费时间,专注于业务的开发,且php版本灵活,可随意切换php版本。