Phpstorm docker php74-56 nginx db

Phpstorm 折磨的我头很大,难受

Docker 配置

image-20210210021359421

image-20210210021416355

version: "3"
services:
db:
hostname: db
image: mariadb:latest
container_name: db
restart: on-failure:3
volumes:
- ./server/db:/var/lib/mysql
ports:
- 31004:3306
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_PASSWORD=123456
- MYSQL_DATABASE=test
- MYSQL_USER=test

# php:
# hostname: php
# build:
# context: ./server
# dockerfile: Dockerfile.php74
# image: php74
# container_name: php74
# volumes:
# - ./www/html:/var/www/html
# restart: on-failure:3
# # ports:
# # - 9003:9003
# networks:
# - default


php:
hostname: php
build:
context: ./server
dockerfile: Dockerfile.php56
image: php56
container_name: php56
volumes:
- ./www/html:/var/www/html
restart: on-failure:3
# ports:
# - 9003:9003
networks:
- default

nginx:
hostname: nginx
container_name: nginx
image: nginx:latest
restart: on-failure:3
ports:
- 31003:80
links:
- php
volumes:
- ./server/default.conf:/etc/nginx/conf.d/default.conf:rw
- ./www:/var/www

networks:
default:

PHP 配置

docker-php56-xdebug.ini

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable = on
xdebug.remote_host = docker.for.mac.localhost
xdebug.remote_port = 9003
xdebug.idekey="PHPSTORM"

docker-php74-xdebug.ini

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.mode=debug
xdebug.remote_handler=dbgp
xdebug.client_host=docker.for.mac.localhost
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.idekey="PHPSTORM"

Dockerfile.php56

FROM php:5.6-fpm

COPY sources.list /etc/apt/sources.list

RUN apt update

RUN /usr/local/bin/pecl install xdebug-2.5.5

COPY docker-php56-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini

RUN /usr/local/bin/docker-php-source extract
RUN apt install net-tools iputils-ping -y

STOPSIGNAL SIGQUIT

EXPOSE 9000
CMD ["php-fpm"]

Dockerfile.php74

FROM php:7.4-fpm

COPY sources.list /etc/apt/sources.list

RUN apt update

RUN /usr/local/bin/pecl install xdebug-3.0.2

COPY docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini

RUN /usr/local/bin/docker-php-source extract
RUN apt install net-tools iputils-ping -y

STOPSIGNAL SIGQUIT

EXPOSE 9000
CMD ["php-fpm"]

sources.list

deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib

Nginx 配置

default.conf

server {
listen 80;
listen [::]:80;
server_name localhost;
root /var/www/html;

# security
# security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;

# . files
location ~ /\.(?!well-known) {
deny all;
}

# index.php
index index.php;

# index.php fallback
location / {
try_files $uri $uri/ /index.php?$query_string;
}

# additional config
# favicon.ico
location = /favicon.ico {
log_not_found off;
}

# robots.txt
location = /robots.txt {
log_not_found off;
}

# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
}

# svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
}

# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;

# handle .php
location ~ \.php$ {
# 404
try_files $fastcgi_script_name =404;

# default fastcgi_params
include fastcgi_params;

# fastcgi settings
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

# fastcgi params
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/var/www/html/:/usr/lib/php/:/tmp/";
}
}

# subdomains redirect
server {
listen 80;
listen [::]:80;
server_name *.localhost;
return 301 http://localhost$request_uri;
}

Phpstorm 配置

  1. Bing 一下激活密钥

  2. 安装插件

    image-20210210022041264

  1. image-20210210022200057

    image-20210210022252382

    image-20210210022322510

Important 👇

image-20210210022416104

👆Important

image-20210210022505004

  1. 其他的俺不会配置,俺不行

讨论

  1. xdebug 参数配置

    # 新版
    xdebug.mode=debug
    xdebug.client_host=docker.for.mac.localhost
    # xdebug.client_host 可不改,需要改的是客户端,客户端需要填写 服务器/本机 真实IP
    xdebug.start_with_request=yes
    xdebug.client_port=9003
    # php 糟老头子骗老子用 session,其实还是 idekeyß
    xdebug.idekey="PHPSTORM"
  2. 端口问题

    1. php-fpm 默认 9000 不需要映射

    2. php-fpm xdebug 默认 9003 不需要映射,否则端口冲突

    3. nginx 连接 php-fpm 可使用 docker 容器 特性 php:9000

    4. Nginx 配置文件不行 就在线 new 一个

    5. Php 安装其他拓展

      1. pecl install 就几m,一会儿就好了

      2. docker-php-source extract
        cp xdebug /usr/src/php
        docker-php-ext-configure xdebug
        docker-php-ext-install xdebug
        docker-php-ext-enable xdebug
        ls /usr/local/etc/php/conf.d/
    6. Php.ini 与 docker-php-ext-xdebug.ini 的区别 ?后者好 echo -e ''