docker 搭建lnmp环境的方法步骤
创建项目目录
mkdirphp
创建如下项目结构
- sites目录放置项目文件
- services目录放置服务相关配置
- script放置自定义脚本
├──Readme.md ├──docker-compose.yml ├──script ├──services │├──mariadb ││└──Dockerfile │├──nginx ││├──Dockerfile ││├──conf.d │││└──default.conf ││└──nginx.conf │├──php ││└──Dockerfile │└──redis │└──Dockerfile └──sites ├──index.html └──index.php 8directories,10files
编辑docker-compose文件
version:"3" services: php: build:./services/php #ports: #-"9001:9000" container_name:lnmp-php restart:always volumes: -./sites:/www networks: lnmp_net: ipv4_address:101.11.11.10 nginx: build:./services/nginx ports: -"81:80" -"444:443" container_name:lnmp-nginx restart:always volumes: -./sites:/www -./services/nginx/nginx.conf:/etc/nginx/nginx.conf -./services/nginx/conf.d:/etc/nginx/conf.d:rw networks: lnmp_net: ipv4_address:101.11.11.11 networks: lnmp_net: driver:bridge ipam: config: -subnet:101.11.11.0/20
编辑services/nginx文件
FROMnginx:1.17.0-alpine #更新安装源 RUNsed-i's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g'/etc/apk/repositories #设置时区为上海 RUNapkupdate&&apkadd--upgrade\ &&apkaddtzdata\ &&cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime\ &&echo"Asia/Shanghai">/etc/timezone\ &&apkdeltzdata
编辑services/php文件
FROMphp:7.3.6-fpm-alpine3.9 #更新安装源 RUNsed-i's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g'/etc/apk/repositories #设置时区为上海 RUNapkupdate&&apkadd--no-cachetzdataautoconfgccg++makezlib-devcurl-dev\ &&cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime\ &&echo"Asia/Shanghai">/etc/timezone\ &&apkdeltzdata\ &&docker-php-ext-installmysqlipdo_mysqlopcache\ &&peclinstallgrpcprotobufxdebugyafyarswoole\ &&docker-php-ext-enablexdebugyafyarswoolegrpcprotobuf
以上我们的lnmp环境基本搭建完毕,下面我们针对Php解析做相关的配置
修改services/nginx/nginx.conf,可根据需求自行修改
usernginx; worker_processesauto; error_log/var/log/nginx/error.logwarn; pid/var/run/nginx.pid; events{ worker_connections1024; } http{ include/etc/nginx/mime.types; default_typeapplication/octet-stream; log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; access_log/var/log/nginx/access.logmain; sendfileon; #tcp_nopushon; keepalive_timeout65; #gzipon; include/etc/nginx/conf.d/*.conf; }
修改services/nginx/conf.d目录下文件
该目录是各个项目的配置文件,可根据需求配置单个或多个服务
server{ listen80; server_namelocalhost; #charsetkoi8-r; #access_log/var/log/nginx/host.access.logmain; #root/usr/share/nginx/html; root/www; indexindex.phpindex.htmlindex.htm; #error_page404/404.html; #redirectservererrorpagestothestaticpage/50x.html # error_page500502503504/50x.html; location=/50x.html{ root/usr/share/nginx/html; } #proxythePHPscriptstoApachelisteningon127.0.0.1:80 # #location~\.php${ #proxy_passhttp://127.0.0.1; #} #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000 # location~\.php${ #roothtml; fastcgi_pass101.11.11.10:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; } #denyaccessto.htaccessfiles,ifApache'sdocumentroot #concurswithnginx'sone # #location~/\.ht{ #denyall; #} }
启动服务
cdphp&&docker-composeup--build-d
上述的步骤根据网速的docker的配置执行时间个不相同,因为php中编译了些许扩展,也可根据自身需求做响应的删减
通过浏览器访问http://127.0.0.1:81,如果看到了phpinfo的输出信息,那么恭喜你,你的lnmp环境已经部署完成
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。