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

Laradock 7.0.0环境下apache2+php-fpm的file_get_contents连接拒绝求助

Fixing file_get_contents Connection Refused in Laradock 7.0.0 Multi-Project Setup

Hey there, I’ve dealt with similar connection headaches in Laradock before, so let’s walk through the most likely fixes for your file_get_contents issue:

1. Fix Container-to-Container Network Resolution

When you call file_get_contents('http://myproject.local') from PHP (running in the php-fpm container), the container doesn’t recognize your host machine’s /etc/hosts entry. Laradock’s containers share an internal network, so try these steps:

  • Jump into the php-fpm container to test connectivity: docker-compose exec php-fpm bash
  • Ping the apache2 container directly: ping apache2 — this should resolve to the apache container’s internal IP (proof they can talk to each other)
  • If you need to use myproject.local inside the container, add an extra host mapping to your docker-compose.yml:
    php-fpm:
      extra_hosts:
        - "myproject.local:apache2"
    
    Then restart the php-fpm container: docker-compose restart php-fpm

2. Complete Your Apache Virtual Host Config

Your current config cuts off mid-directory directive — make sure it includes all necessary rules to allow access:

<VirtualHost *:80>
    ServerName myproject.local
    DocumentRoot /var/www/myproject/public/
    Options Indexes FollowSymLinks

    <Directory "/var/www/myproject/public/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/myproject-error.log
    CustomLog ${APACHE_LOG_DIR}/myproject-access.log combined
</VirtualHost>

After updating, restart apache2 to apply changes: docker-compose restart apache2

3. Verify File Paths & Permissions

Make sure your project files are mounted correctly and accessible to the web server user:

  • In the php-fpm container, check if the path exists: ls -la /var/www/myproject/public/
  • If permissions are messed up, set them to the www-data user (the user PHP-FPM runs as):
    docker-compose exec php-fpm chown -R www-data:www-data /var/www/myproject
    

4. Check Container Logs for Clues

Logs almost always reveal the root cause. Run these commands to inspect errors:

  • Apache logs: docker-compose logs apache2 (look for 403 Forbidden or 500 Internal Server Error entries)
  • PHP-FPM logs: docker-compose logs php-fpm (check for file access errors or network-related warnings)

5. Confirm Port & Firewall Settings

  • Ensure you’re using the container’s internal port (80) instead of a mapped host port (like 8080) in your file_get_contents call.
  • Temporarily disable your host machine’s firewall to rule out external blocking (don’t forget to re-enable it afterward!).

Start with the network check — that’s the most common culprit in multi-container Laradock setups. If that doesn’t work, work through the config and permission checks, and don’t skip the logs!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:23:39