首页 > 代码库 > docker 部署 nginx+php+mysql
docker 部署 nginx+php+mysql
系统:centos7
使用root账户
开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
安装docker
yum install docker -y
安装docker-compose
yum install epel-release -y
yum install -y python-pip
pip install -U docker-compose
部署nginx+php+mysql
开启docker
systemctl start docker
cd /home
mkdir www //网站目录
mkdir conf //配置文件
mkdir app //下载的应用
//拉取官方镜像
docker pull nginx:1.12.0
docker pull php:5.4-fpm
docker pull mysql:5.6
//下载到/home/app
去php官网下载php5.4.45
nginx官网下载nginx1.12.0
phpmyadmin官网下载phpmyadmin找php对应版本
都下载完并解压完成后,进入php文件
cp php.ini-development /home/conf/php.ini
进入nginx文件
cp conf/nginx.conf /home/conf/nginx.conf
cd /home/conf
vi nginx.conf
location / {
root /usr/share/nginx/html;
index index.html index.php index.htm;
}
location ~ \.php {//去除$
root /var/www/html;
fastcgi_pass fpm:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$; //nginx添加path_info支持
fastcgi_param PATH_INFO $fastcgi_path_info;//nginx添加path_info支持
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
cd /home/app
复制phpmyadmin解压出来的文件到/home/www并改名为phpmyadmin
//编写docker-compose
cd /home
docker images //查看镜像id
vi docker-compose.yml
php:
image: php镜像id
ports:
- 9000:9000
volumes:
- /home/www:/var/www/html
- /home/conf/php.ini:/usr/local/etc/php/php.ini
links:
- mysql
privileged: true
nginx:
image: nginx镜像id
ports:
- 80:80
volumes:
- /home/www:/usr/share/nginx/html
- /home/conf/nginx.conf:/etc/nginx/nginx.conf
links:
- php:fpm
privileged: true
mysql:
image: mysql镜像id
ports:
- 3306:3306
volumes:
- /home/data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=123
privileged: true
docker-compose编写完成后
执行
docker-compose up -d //使容器后台运行
docker exec -it home_mysql_1 bash //进入mysql容器
mysql -u -root -p
密码:123
执行 status
查看 UNIX socket地址并复制
执行use mysql
update user set Host = ‘%‘ where User = ‘root‘;
flush privileges;
完成后两次ctrl+d
退出容器
cd /home/conf
vi php.ini
搜索
mysql.default
mysqli.default
pdo_mysql.default
等号后加上复制出来的UNIX socket地址
cd /home
docker-compose restart
cd www
vi index.php
<?php
phpinfo();
?>
查看php信息
cd phpmyadmin
vi config.sample.inc.php
$cfg[‘Servers‘][$i][‘host‘] = ‘mysql‘;
退出后config.sample.inc.php改名为config.inc.php
从外部访问 http://ip地址/phpmyadmin/index.php
登录mysql成功后即可完成
docker 部署 nginx+php+mysql