Docker搭建php环境教程详解
docker安装
使用官方提供的安装脚本,安装最新版的Docker
curl-sSLhttps://get.docker.com/|sh
安装完成后,通过如下命令启动Docker的守护进程,并让它随系统启动自动加载
sudoservicedockerstart
sudochkconfigdockeron
##或者
sudosystemctlstartdocker
sudosystemctlenabledocker
添加用户(jerry)到Docker组
sudousermod-aGdockerjerry
命令笔记(centos),基于docker镜像2233466866/lnmp
下载镜像
dockerpull2233466866/lnmp
创建基本目录
mkdir-p/app/lnmp/default/docker/lnmp/data/mysql/docker/lnmp/conf/vhost/docker/lnmp/logs/docker/lnmp/temp/docker/lnmp/backup
下载容器配置文件到本地相应目录
dockerrun-itd-v/sys/fs/cgroup:/sys/fs/cgroup:ro--privileged=true--name=lnmp2233466866/lnmp
dockerexec-itlnmp/bin/bash
dockercplnmp:/etc/my.cnf/docker/lnmp/conf/my.cnf
dockercplnmp:/usr/local/nginx/conf/nginx.conf/docker/lnmp/conf/nginx.conf
cp/docker/lnmp/conf/my.cnf/docker/lnmp/backup/my.cnf
cp/docker/lnmp/conf/nginx.conf/docker/lnmp/backup/nginx.conf
查看或修改基本配置(代码目录,日志保存目录及vhost目录配置添加)
my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
nginx.conf
userwww; worker_processesauto; worker_cpu_affinityauto; worker_cpu_affinityauto; pidlogs/nginx.pid; events{ worker_connections102400; } http{ charsetutf-8; server_tokensoff; log_formatmain'$remote_addr-$remote_user[$time_iso8601]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; includemime.types; default_typeapplication/octet-stream; client_max_body_size20M; sendfileon; keepalive_timeout20; gzipon; gzip_varyon; gzip_comp_level1; gzip_typestext/cssapplication/javascriptapplication/jsonimage/pngimage/webpimage/apngimage/jpegimage/x-icon; autoindex_localtimeon error_log/logs/z_error.log; access_log/logs/z_$host.logmain; server{ listen80default; root/www/default; return500; } includevhost/*.conf; }
停止并删除测试容器
dockerstoplnmp
dockerrmlnmp
重新创建容器
dockerrun-dit\
-p80:80\
-p443:443\
-p3306:3306\
-p9000:9000\
-eTC="Asia/Shanghai"\
-v/sys/fs/cgroup:/sys/fs/cgroup:ro\
-v/app/lnmp:/www\
-v/docker/lnmp/data/mysql:/data/mysql\
-v/docker/lnmp/conf/my.cnf:/etc/my.cnf\
-v/docker/lnmp/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf\
-v/docker/lnmp/conf/vhost:/usr/local/nginx/conf/vhost\
-v/docker/lnmp/logs:/logs\
--privileged=true\
--name=lnmp\
2233466866/lnmp
mysql数据库配置(/etc/my.cnf)
/bin/mysql_secure_installation
cat/var/log/mysqld.log|grep'Atemporarypassword'
SETPASSWORD=PASSWORD('123456');
php.ini配置(/usr/local/php7/lib/php.ini)
mysqli.default_socket=/var/lib/mysql/mysql.sock
linux相关设置修改
添加不能登陆的用户www
groupaddwww
useradd-M-gwww-s/usr/sbin/nologinwww
修改时区(/etc/profile)
TZ='Asia/Shanghai';exportTZ
cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
多站点配置
www.test.test.conf
server{ listen80; server_nametest.test; rewrite^(.*)$$scheme://www.test.test$1permanent; } server{ listen80; server_namewww.test.test; if($time_iso8601~"^(\d{4}-\d{2}-\d{2})"){ set$ttt$1; } access_log/logs/$host-$ttt-access.logmain; root/www/test; location/{ indexindex.phpindex.htmlindex.htm; } location~*\.php{ includefastcgi_params; fastcgi_indexindex.php; fastcgi_pass127.0.0.1:9000; fastcgi_split_path_info^(.+\.php)(.*)$; fastcgi_paramPATH_INFO$fastcgi_path_info; fastcgi_paramSCRIPT_NAME$fastcgi_script_name; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。