Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HOSTALIASES for PHP-FPM

Tags:

linux

php

There's a way to per-process override name resolution process-local override of name resolution? using HOSTALIASES. Do you think it's applicable to PHP-FPM workers too? I have this line in /etc/php-fpm.d/www.conf:

env[HOSTALIASES] = /etc/hosts.php-fpm

And when I examine $_SERVER, I see HOSTALIASES, but the actual override in the hosts.php-fpm (127.0.0.1 example.com) is not effective, it's returned from the nameservers. Do you have a suggestion on how to make (a similar solution) work?

like image 649
Aron Novak Avatar asked Aug 06 '15 15:08

Aron Novak


1 Answers

You're trying to use HOSTALIASES in the wrong way. To be respected, alias should meet 2 requirements:

  1. should not contain dots (here is code which, I believe, checks it). That is mentioned in man of hostname(7)
  2. target should be complete hostname. That is also mentioned in hostname doc.

So, your record in HOSTALIASES should look like

example someexample.com

In case you need to alias the ip, you can use something like xip.io

Generally, that should work with any php function which relies on gethostbyname (that also true for php-fpm).

like image 110
Evgeny Soynov Avatar answered Nov 15 '22 06:11

Evgeny Soynov