craftcms / craftcms/cms

Control Panel Doesn't Load Properly on Non-standard Port

Open
#10,687 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

Description

The control panel doesn't seem to load resources properly when running craft on non-standard ports. The links all reference the correct port but resources like images, scripts, and stylesheets drop the port number.

image

It just tries to load resources from localhost even though I configured the BASE_CP_URL to be localhost:5000.

docker-compose.yml
version: '3'
services:
  app:
    build:
      context: .
      dockerfile: .docker-config/php/Dockerfile
    expose:
      - 9000
    volumes:
      - ./craft:/var/www/html
    environment:
      COMPOSER_ALLOW_SUPERUSER: 1
      ENVIRONMENT: dev
      SECURITY_KEY: security_key
      DB_DSN: mysql:host=database;port=3306;dbname=craft
      DB_USER: user
      DB_PASSWORD: password
      DEFAULT_SITE_URL: http://localhost:5000
      BASE_CP_URL: http://localhost:5000

  database:
    build:
      context: .
      dockerfile: .docker-config/mysql/Dockerfile
    volumes:
      - ./craft/storage/db:/var/lib/mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_DATABASE: craft
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: password

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - 8085:80
    environment:
      PMA_HOST: database

  nginx:
    build:
      context: .
      dockerfile: .docker-config/nginx/Dockerfile
    ports:
      - 5000:80
    volumes:
      - ./craft/web:/var/www/html/web
    depends_on:
      - app
config/general.php
<?php
return [
  '*' => [
    // Control Panel access via environment variable
    'baseCpUrl' => craft\helpers\App::env('BASE_CP_URL') ?: null,

    // Control Panel trigger word
    'cpTrigger' => 'admin-login',
  ],
];

We do not use .env files.

Steps to reproduce
  1. Use above configuration
  2. Navigate to control panel
Additional info
  • Craft version: 3.7.36
  • PHP version: 8.1.3
  • Database driver & version: MySQL 8.0+
  • Plugins & versions: Will provide upon request

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with docker-compose.yml and config/general.php, then reproduce the control panel resource requests on port 5000. Trace how BASE_CP_URL is used for images, scripts, and stylesheets, and confirm the fix by verifying that every resource URL retains the configured port.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, mysql, php
Domain
backend, devops, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.