3

I've running laradock 7.0.0 with the a multi project structure with the following containers:

docker-compose up -d apache2

That will run php-fpm and apache2

I configured my hosts file to connect to localhost:

/etc/hosts

127.0.0.1    myproject.local

I've create an site config for my apache2:

laradock/apache2/sites/myproject.conf

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

  <Directory "/var/www/myproject/public/">
    AllowOverride All
    <IfVersion < 2.4>
      Allow from all
    </IfVersion>
    <IfVersion >= 2.4>
      Require all granted
    </IfVersion>
  </Directory>
</VirtualHost>

I modify the php.ini settings to allow url include:

laradock/php-fpm/laravel.ini

allow_url_include=On

When going to myproject.local the website is showing. No problems so far. But when i do a file_get_contents, then i get an connection refused:

$json = file_get_contents('http://myproject.local/test.json');
var_dump($json);
exit;

Response:

Warning: file_get_contents(http://myproject.local/test.json): failed to open stream: Connection refused in /var/www/myproject/public/test.json

It seems that php-fpm can't find apache2. When i get the ip adres of the apache2 container:

docker exec -ti laradock_apache2_1 bash
ifconfig

Results in:

eth0 Link encap:Ethernet HWaddr 02:42:ac:16:00:04
inet addr:172.22.0.4

And i modify the hosts file on my php-fpm

docker exec -ti laradock_php-fpm_1 bash
nano /etc/hosts

Add rule:

172.22.0.4 myproject.local

Than the file_get_contents works. The problem with this fix is that the ip of the apache2 container is not always the same. And i'll have to do this every time for every project.

Is there a way to modify the Dockerfile or docker-compose.yml to link php-fpm to apache2 for every project in once?

0 Answers0