gpt4 book ai didi

php - Alpine php-fpm配置出现问题(xdebug + netbeans,sendmail + mailhog)

转载 作者:行者123 更新时间:2023-12-02 18:37:12 25 4
gpt4 key购买 nike

我正在尝试为一个PHP应用程序设置开发环境,但是我无法解决这两个问题:

  • 发送电子邮件(我想使用正在运行的MailHog,但似乎我没有正确配置PHP)
  • xdebug (已安装并且日志正在运行,但我无法从NetBeans IDE 连接到它)

  • 这是我的配置:

    docker-compose.yml:
    version: "3.1"
    services:
    # MySQL
    database:
    environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_USER: testuser
    MYSQL_PASSWORD: testpass
    MYSQL_DATABASE: testdb
    image: mariadb
    restart: always
    volumes:
    - "./docker/mariadb/data:/var/lib/mysql"
    - "./docker/mariadb/init:/docker-entrypoint-initdb.d"
    # PHP
    php-fpm:
    build:
    context: ./docker/php-fpm
    environment:
    ENV_MODE: development
    ENV_BRANCH: test
    volumes:
    - "./:/var/www/app"
    # NGINX
    webserver:
    build:
    context: ./docker/nginx
    depends_on:
    - php-fpm
    environment:
    MYSQL_DATABASE: testdb
    MYSQL_USER: testuser
    MYSQL_PASSWORD: testpass
    MYSQL_ROOT_PASSWORD: root
    links:
    - database:mysql
    - mailhog
    ports:
    - "80:80"
    - "443:443"
    volumes:
    - "./:/var/www/inpage"
    - "./docker/nginx/nginx.conf:/etc/nginx/nginx.conf"
    - "./docker/nginx/inpage.inc.conf:/etc/nginx/inpage.inc.conf"
    - "./docker/nginx/inpage-site.inc.conf:/etc/nginx/app-site.inc.conf"
    - "./docker/nginx/sites/:/etc/nginx/sites-available"
    - "./docker/nginx/conf.d/:/etc/nginx/conf.d"
    # Adminer
    adminer:
    depends_on:
    - database
    environment:
    ADMINER_DEFAULT_SERVER: database
    image: adminer
    ports:
    - 8181:8080
    restart: always
    # MailHog
    mailhog:
    image: mailhog/mailhog
    command: -smtp-bind-addr 127.0.0.1:1025
    user: root
    expose:
    - 1025
    - 8025
    ports:
    - 1025:1025
    - 8025:8025

    docker / php-fpm / Dockerfile:
    # Customized Dockerfile from https://github.com/kporras07/docker-php.
    FROM php:7.0-fpm-alpine

    # Environment settings
    ENV XDEBUG_VERSION 2.3.3
    ENV PHP_MEMORY_LIMIT 256M
    ENV PHP_MAX_EXECUTION_TIME 120
    ENV PHP_POST_MAX_SIZE 100M
    ENV PHP_UPLOAD_MAX_FILESIZE 100M
    ENV PHP_INI_DIR /usr/local/etc/php

    # Configure, build & install PHP
    RUN docker-php-source extract \
    && apk --no-cache --update add \
    libxml2-dev \
    libpng \
    libpng-dev \
    libjpeg-turbo \
    libjpeg-turbo-dev \
    freetype-dev \
    freetype \
    libcurl \
    curl-dev \
    curl \
    icu-dev \
    g++ \
    autoconf \
    make \
    libmcrypt-dev \
    libmcrypt \
    libintl \
    openssl-dev \
    re2c \
    recode-dev \
    sqlite-dev \
    enchant-dev \
    krb5-dev \
    pcre-dev \
    imagemagick-dev \
    imagemagick \
    libtool \
    bzip2-dev \
    freetds-dev \
    freetype-dev \
    gmp-dev \
    imap-dev \
    readline-dev \
    recode-dev \
    zip \
    libzip \
    libzip-dev \
    libxslt \
    libxslt-dev \
    && rm -rf /tmp/* \
    && rm -rf /var/cache/apk/* \
    && docker-php-ext-configure bcmath \
    && docker-php-ext-configure bz2 \
    && docker-php-ext-configure json \
    && docker-php-ext-configure session \
    && docker-php-ext-configure ctype \
    && docker-php-ext-configure curl \
    && docker-php-ext-configure tokenizer \
    && docker-php-ext-configure simplexml \
    && docker-php-ext-configure dom \
    && docker-php-ext-configure mbstring \
    && docker-php-ext-configure zip \
    && docker-php-ext-configure iconv \
    && docker-php-ext-configure xml \
    && docker-php-ext-configure opcache \
    && docker-php-ext-configure pdo \
    && docker-php-ext-configure pdo_mysql \
    && docker-php-ext-configure pdo_sqlite \
    && docker-php-ext-configure gettext \
    && docker-php-ext-configure gmp \
    && docker-php-ext-configure intl --enable-intl \
    && docker-php-ext-configure mcrypt \
    && docker-php-ext-configure phar \
    && docker-php-ext-configure soap \
    && docker-php-ext-configure sockets \
    && docker-php-ext-configure xml \
    && docker-php-ext-configure xsl \
    && docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ \
    --with-jpeg-dir=/usr/include/ \
    --with-png-dir=/usr/include/ \
    && NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
    && docker-php-ext-install -j${NPROC} gd \
    && docker-php-source delete

    RUN docker-php-ext-install bcmath \
    bz2 \
    json \
    session \
    ctype \
    curl \
    tokenizer \
    simplexml \
    dom \
    mbstring \
    zip \
    iconv \
    xml \
    opcache \
    pdo \
    pdo_mysql \
    gettext \
    gmp \
    intl \
    mcrypt \
    phar \
    soap \
    sockets \
    xml \
    xsl

    RUN apk update \
    && apk add ca-certificates wget \
    && update-ca-certificates

    # Blackfire.io
    RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
    && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
    && mkdir -p /tmp/blackfire \
    && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
    && mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
    && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
    && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

    # Xdebug
    RUN pecl install xdebug
    RUN docker-php-ext-enable xdebug
    COPY ./xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

    ## mhsendmail for MailHog (https://github.com/mailhog/mhsendmail)
    RUN apk update && apk add \
    go \
    git
    RUN mkdir /root/go
    ENV GOPATH=/root/go
    ENV PATH=$PATH:$GOPATH/bin
    RUN go get github.com/mailhog/mhsendmail
    RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail
    COPY ./php.ini /usr/local/etc/php/conf.d/docker-php.ini

    # Fix iconv lib (https://github.com/docker-library/php/issues/240#issuecomment-305038173)
    RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
    ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

    # Cleanup
    RUN rm -rf /tmp/* \
    && rm -rf /var/cache/apk/* \
    && rm -rf tmp/*

    CMD ["php-fpm"]

    EXPOSE 9000

    docker / php-fpm / xdebug.ini:
    zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so
    xdebug.coverage_enable=0
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    ;xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    ;xdebug.remote_connect_back=1
    xdebug.remote_log=/tmp/xdebug.log
    ;xdebug.remote_autostart=true

    docker /php-fpm/php.ini:
    memory_limit = ${PHP_MEMORY_LIMIT}
    max_execution_time = ${PHP_MAX_EXECUTION_TIME}
    post_max_size=${PHP_POST_MAX_SIZE}
    upload_max_filesize=${PHP_UPLOAD_MAX_FILESIZE}
    sendmail_path = /usr/bin/mhsendmail -S mailhog:1025 -t

    最佳答案

    我在mailhog github issues页面上找到了该问题的mailhog“连接被拒绝”部分的解决方案。您需要替换自己的sendmail_path语句
    像这样的docker / php-fpm / php.ini(不支持-S选项,引号的位置很重要):

    sendmail_path = "/usr/bin/mhsendmail --smtp-addr=mailhog:1025"

    我还发现我不需要使用docker-compose文件中mailhog服务部分的 commanduserexpose部分。

    关于php - Alpine php-fpm配置出现问题(xdebug + netbeans,sendmail + mailhog),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53641108/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com