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

Laravel项目Docker构建PHP时出现Error 139问题求助

Fixing Error 139 (Segmentation Fault) When Building PHP Docker Image for Laravel

Hey there, let's work through this Error 139 you're facing while building your PHP Docker image for your Laravel project. Error 139 is almost always a segmentation fault—meaning the process crashed because it tried to access invalid memory. Here are actionable steps to diagnose and fix this:

Common Causes & Solutions

1. Validate Your Dockerfile Completeness & Compatibility

First up, your docker/app.docker file was cut off in your snippet, so make sure it's fully written and uses valid commands. Segfaults often pop up when installing incompatible PHP extensions or running broken shell commands.

  • Double-check extension installation lines (like docker-php-ext-install or pecl install). For example, if you're using a newer PHP version (8.0+), some older extensions might not be supported and can cause crashes. Stick to official, maintained extensions for your base PHP image.
  • Ensure you're not missing critical dependencies for extensions. For Laravel, you'll need things like pdo_mysql, mbstring, exif, pcntl, and bcmath—make sure each is installed with the correct prerequisites (e.g., libpng-dev for the GD extension).

2. Check Architecture Compatibility

If you're on an ARM-based system (like Apple Silicon M1/M2), using Docker images that don't support multi-architecture can trigger segfaults.

  • Try adding the --platform linux/amd64 flag to your build command to force x86_64 emulation:
    docker-compose build --platform linux/amd64 php
    
  • Alternatively, use official PHP base images that support ARM (most recent official php images are multi-arch now, like php:8.2-fpm-alpine).

3. Simplify & Debug the Build Process

Narrow down exactly which step in your Dockerfile is causing the crash by stripping it back to basics:

  • Start with a minimal Dockerfile (just the base PHP image + copying your Laravel files) and build it. If it works, add one command at a time (extension installs, composer install, etc.) until you hit the error. This will tell you exactly what's triggering the segfault.
  • Run the build with verbose output to get more details:
    docker-compose build --no-cache --progress=plain php
    
    The plain progress output will show you each command as it runs, making it easier to spot where the crash happens.

4. Fix File Permissions & Volume Usage

While volumes are great for runtime, relying on them during build can cause permission issues that lead to unexpected crashes:

  • In your Dockerfile, use COPY . /var/www to copy your Laravel project files into the image instead of relying on the volume mount during build. Volumes are for live code updates when running containers, not for building the image.
  • Ensure your project files have proper permissions. You can set them in the Dockerfile with:
    RUN chown -R www-data:www-data /var/www
    

5. Update Docker to the Latest Version

Outdated Docker versions can have bugs that cause segfaults during builds. Update Docker Desktop (or Docker Engine on Linux) to the latest stable release, then try rebuilding your image.

Next Steps

If none of these fix the issue, share the full content of your docker/app.docker file—this will help pinpoint the exact command or configuration causing the crash.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:04:32