基础环境
MAC
安装docker
安装教程请详细看
https://www.runoob.com/docker/macos-docker-install.html
安装centos镜像,并搭建lnmp环境
1.下载centos镜像
docker pull centos
2.创建并运行容器,并且进入bash命令行模式
dcoker run -it centos: latest /bin/bash
3.安装lnmp
安装方法请参考官网 https://lnmp.org/install.html
4.保存容器为镜像
# 查看容器
docker ps -a
# 将现有的有安装lnmp的容器生成为镜像
docker commit -m "说明" -a "作者" lnmp:1.0
# 查看/验证现有镜像
docker images
5.测试lnmp:1.0镜像
# 设置lnmp:1.0镜像创建的容器
# 容器80端口映射到宿主8080端口
# 宿主的目录/Users/sunsheng/www/wwwroot映射到容器目录/home/www/wwwroot
docker run -d -p 80:8080 -v /Users/sunsheng/www/wwwroot:/home/www/wwwroot lnmp:1.0
启动后宿主浏览器打开http://{ip地址}:8080
这里的ip地址可以在宿主主机的命令行中输入ifconfig可以看出来,我这里是192.168.31.110。所以我这里打开就是http://192.168.31.110:8080,理论上localhost来代替ip也是可以的,但是还没试过,下次再搭建容器的时候看看再补充。
6.进入容器,并安装xdebug扩展。
docker exec -it 容器ID /bin/bash
扩展的安装我就不说了(https://xdebug.org/wizard.php
用这个网站,就可以知道怎么安装xdebug了),只附上扩展安装好后的配置
[XDebug]
xdebug.enable=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
;这个是约定的调试码,需要在phpstorm里面设定
xdebug.remote_host=192.168.31.110
;这个是宿主ip
xdebug.remote_port=9000
;这个是xdebug对编辑器链接的端口
xdebug.remote_log=/var/log/php/xdebug_remote.log
设置phpstorm和运行
参考地址
https://www.jianshu.com/p/42eb347e0283?from=timeline
https://www.jianshu.com/p/c40a27129aca
网友评论