You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP 7 Docker容器卷挂载配置及localhost访问异常排查

Alright, let’s walk through the most likely issues with your docker-compose.yml setup—since your container starts up fine but browser access throws an error, these are the top things to check:

1. Incorrect Volume Mount Path

The official PHP7 Apache container uses /var/www/html as its default document root. If your volume is mounted to the wrong directory (like /var/www or a custom path you made up), Apache won’t find your index.php file at all.

  • Double-check your volumes section in docker-compose.yml—it should look like this:
    volumes:
      - ./your-local-volume-dir:/var/www/html
    
  • Verify the file exists inside the container with:
    docker exec -it <your-container-name> ls /var/www/html
    

2. File Permission Problems

Linux-based containers are strict about file permissions. If your local index.php is owned by root or lacks read permissions for the Apache user (www-data), the server can’t load it—leading to 500 errors or blank pages.

  • Check permissions inside the container:
    docker exec -it <your-container-name> ls -l /var/www/html/index.php
    
  • Fix this either by adjusting local file permissions, or adding a user directive to your docker-compose.yml:
    user: "www-data:www-data"
    
    Or run this command after starting the container:
    docker exec -it <your-container-name> chown www-data:www-data /var/www/html/index.php
    

3. Using the Wrong PHP Image

If you’re using the php:7-cli image instead of php:7-apache, there’s no web server listening on port 80 at all! The CLI image is only for running PHP scripts directly, not serving web pages.

  • Make sure your image line in docker-compose.yml specifies an Apache variant:
    image: php:7-apache
    

4. Port Conflict on Your Host

Even though you mapped 55211:80, port 55211 might already be taken by another process on your Windows machine.

  • Check for port conflicts in PowerShell:
    netstat -ano | findstr :55211
    
  • If you see results, kill the conflicting process or pick a different host port (like 55212:80).

5. Apache Doesn’t Prioritize index.php

Some default Apache configurations only look for index.html first. Even if index.php exists, Apache might not load it unless you explicitly set the directory index.

  • Add a .htaccess file to your local volume directory with this line:
    DirectoryIndex index.php index.html
    
  • Or customize the Apache config in your docker-compose setup if you’re using a custom config file.

If you share your actual docker-compose.yml content, we can pinpoint the exact issue faster—but these are the most common fixes for your scenario.

内容的提问来源于stack exchange,提问作者klewis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:48:38