docker-dnmp环境中安装hyperf框架

EN
EN
2024-03-07 / 0 评论 / 197 阅读 / 正在检测是否收录...

安装PHP8.2以及相关扩展

.env设置php

根据框架要求将php版本设置为 8.2 ,以及安装所需的扩展 opcache,redis,swoole,pcntl
lwzt0qz0.png

PHP80_VERSION=8.2.12
PHP80_PHP_CONF_FILE=./services/php80/php.ini
PHP80_FPM_CONF_FILE=./services/php80/php-fpm.conf
PHP80_LOG_DIR=./logs/php80
PHP80_EXTENSIONS=pdo_mysql,mysqli,mbstring,gd,curl,opcache,redis,swoole,pcntl

docker-compose.yml 端口映射与暴露

我设置的是9800端口

  php80:
    build:
      context: ./services/php80
      args:
        PHP_VERSION: php:${PHP80_VERSION}-fpm-alpine
        CONTAINER_PACKAGE_URL: ${CONTAINER_PACKAGE_URL}
        COMPOSER_URL: ${COMPOSER_URL}
        PHP_EXTENSIONS: ${PHP80_EXTENSIONS}
        TZ: "$TZ"
    container_name: php80
    expose:
      - 9501
      - 9800
    ports:
      - "9800:9800"
    volumes:
      - ${SOURCE_DIR}:/www/:rw
      - ${PHP80_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro
      - ${PHP80_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw
      - ${PHP80_LOG_DIR}:/var/log/php
      - ${DATA_DIR}/composer:/tmp/composer
    restart: always
    cap_add:
      - SYS_PTRACE
    networks:
      - default

设置完成后运行

进入到php8的控制台

docker exec -it php80 /bin/sh

进入www目录,安装框架

composer create-project hyperf/hyperf-skeleton 

将端口改成9800

hyperf-skeleton/config/autoload/server.php

  'mode' => SWOOLE_PROCESS,
    'servers' => [
        [
            'name' => 'http',
            'type' => Server::SERVER_HTTP,
            'host' => '0.0.0.0',
            'port' => 9800, # 这里
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
            ],
            'options' => [
                // Whether to enable request lifecycle event
                'enable_request_lifecycle' => false,
            ],
        ],
    ],

运行

php bin/hyperf.php start

lwztd9n7.png

访问 0.0.0.0:9800

lwztcxak.png

0

评论 (0)

取消