一、mysql
1、启动容器
docker run --name mysql5.6 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6
2、创建目录
mkdir D:\wnmp\mysql\mysql5.6\conf | |
mkdir D:\wnmp\mysql\mysql5.6\data | |
mkdir D:\wnmp\mysql\mysql5.6\log |
3、拷贝容器中的配置
docker cp mysql5.6:/etc/mysql D:\wnmp\mysql\mysql5.6\conf | |
docker cp mysql5.6:/var/lib/mysql D:\wnmp\mysql\mysql5.6\data | |
docker cp mysql5.6:/var/log/mysql D:\wnmp\mysql\mysql5.6\log |
4、删除当前容器
docker stop mysql5.6 | |
docker rm mysql5.6 |
5、重新启动容器
docker run --name mysql5.6 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -v D:\wnmp\mysql\mysql5.6\conf:/etc/mysql/ -v D:\wnmp\mysql\mysql5.6\data:/var/lib/mysql -v D:\wnmp\mysql\mysql5.6\log:/var/log/mysql/ -d mysql:5.6
二、php
1、启动容器
docker run --name php8.1 -p 9000:9000 -d php:8.1-fpm
2、创建目录
mkdir D:\wnmp\php\php8.1\conf | |
mkdir D:\wnmp\php\php8.1\log | |
mkdir D:\wnmp\www |
3、拷贝容器中的配置
docker cp php8.1:/usr/local/etc D:\wnmp\php\php8.1\conf | |
docker cp php8.1:/usr/local/var/log D:\wnmp\php\php8.1\log | |
docker cp php8.1:/var/www/html D:\wnmp\www |
4、删除当前容器
docker stop php8.1 | |
docker rm php8.1 |
5、重新启动容器
docker run --name php8.1 -p 9000:9000 -v D:\wnmp\php\php8.1\conf\etc:/usr/local/etc -v D:\wnmp\php\php8.1\log:/usr/local/var/log -v D:\wnmp\www:/var/www/html -d php:8.1-fpm
6、进入容器,开启pdo_mysql扩展
docker-php-ext-install pdo_mysql
三、nginx
1、启动容器
docker run --name nginx1.22 -p 80:80 -d nginx:1.22
2、创建目录
mkdir D:\wnmp\nginx\nginx1.22\conf | |
mkdir D:\wnmp\nginx\nginx1.22\log |
3、拷贝容器中的配置
docker cp nginx1.22:/etc/nginx/ D:\wnmp\nginx\nginx1.22\conf | |
docker cp nginx1.22:/var/log/nginx/ D:\wnmp\nginx\nginx1.22\log |
4、删除容器
docker stop nginx1.22 | |
docker rm nginx1.22 |
5、重新启动容器
docker run --name nginx1.22 -p 80:80 -v D:\wnmp\www:/var/www/html -v D:\wnmp\nginx\nginx1.22\conf\nginx:/etc/nginx/ -v D:\wnmp\nginx\nginx1.22\log:/var/log/nginx/ -d nginx:1.22
6、本地访问
(1)、修改 D:\wnmp\nginx\nginx1.22\conf\nginx\conf.d\
目录下的 default.conf
文件
server { | |
listen 80; | |
listen [::]:80; | |
server_name localhost; | |
#access_log /var/log/nginx/host.access.log main; | |
location / { | |
root /var/www/html; | |
index index.php index.html index.htm; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location ~ \.php$ { | |
root /var/www/html; | |
fastcgi_pass 192.168.0.66:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
location ~ /\.ht { | |
deny all; | |
} | |
} |
(2)、在 D:\wnmp\www
目录下创建 index.php
文件,并且写入以下内容
echo 'test.com'; |
(3)、重启 nginx
docker restart nginx1.22
(4)、打开浏览器,输入 127.0.0.1
即可访问
7、域名访问
(1)、在 D:\wnmp\nginx\nginx1.22\conf\nginx\conf.d\
目录下新建 test.conf
文件,内容如下
server { | |
listen 80; | |
listen [::]:80; | |
server_name test.com; | |
#access_log /var/log/nginx/host.access.log main; | |
location / { | |
root /var/www/html/test; | |
index index.php index.html index.htm; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location ~ \.php$ { | |
root /var/www/html/test; | |
fastcgi_pass 192.168.0.66:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
location ~ /\.ht { | |
deny all; | |
} | |
} |
(2)、修改 C:\Windows\System32\drivers\etc
目录下的 hosts
文件
127.0.0.1 test.com | |
127.0.0.1 www.test.com |
(3)、在 D:\wnmp\www
目录下创建 test
目录,并在目录下创建 index.php
文件,并且写入以下内容
echo 'test.com'; |
(3)、重启 nginx
docker restart nginx1.22
(4)、打开浏览器,输入 test.com
即可访问
四、composer
1、安装composer
docker pull composer
2、使用composer
docker run --rm -it -v D:\wnmp\www\phpart:/app composer update
3、使用composer,并将缓存映射到主机(可选)
(1)、在 D:\wnmp\
目录下创建 composer
文件夹
(2)、执行以下命令
docker run --rm -it -v D:\wnmp\www\phpart:/app -v D:\wnmp\composer\:/tmp composer install
4、在phpstorm中使用composer镜像
(1)、打开 phpstorm 设置,搜索 composer
(2)、选择 远程解释器
,点击 CLI解释器
最右侧的 ...
,配置CLI解释器
(3)、点击 +
号,选择 From Docker, Vagrant, VM, WSL, Remote...
(4)、选择 docker
,新建服务器 ,直接确定即可
(5)、选择 composer
镜像,然后一直确定即可
(6)、最后,直接打开composer.json文件,点击phpstorm工具右上角的更新
即可
五、xdebug
1、进入容器,并下载xdebug
pecl install xdebug
2、打开php.ini文件
D:\wnmp\php\php8.1\conf\etc\php\php.ini
3、修改php.ini
[xdebug] | |
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so | |
xdebug.show_exception_trace=On | |
xdebug.remote_handler=dbgp | |
xdebug.remote_autostart=Off | |
xdebug.remote_enable=On | |
xdebug.mode=debug | |
xdebug.remote_port=9003 | |
xdebug.idekey=PHPSTORM | |
xdebug.remote_log=/tmp/xdebug_remote.log | |
xdebug.remote_connect_back=On | |
xdebug.remote_host= 192.168.0.66 | |
xdebug.client_host = 192.168.0.66 |
把remote_host(远程主机)和client_host(客户端主机)修改为局域网IP
然后重启PHP容器
注意:有个大坑,就是no-debug-non-zts-20200930
后面的日期不一定是这个,一定要看清刚才安装的
如果忘了,可以进入容器中输入以下命令查看后面的日期
cd /usr/local/lib/php/extensions/
然后再修改成正确的日期就可以了
4、配置 phpStorm(2022版本)
(1)、打开(设置—PHP—调试)
在xdebug选项中配置调试端口为:9000,9003(如果默认就是这样,那就不用配置了)
(2)、打开(DBGp代理),配置以下内容
IDE键:PHPSTORM | |
主机:192.168.0.66 | |
端口:9003 |