You must be running a very old version of Debian. I'm running recent Ubuntu, which derives from Debian + here's what I see...
lxd: net11-zesty # dpkg -l | grep zlib
ii zlib1g:amd64 1:1.2.11.dfsg-0ubuntu1 amd64 compression library - runtime
ii zlib1g-dev:amd64 1:1.2.11.dfsg-0ubuntu1 amd64 compression library - development
So to fix your Debian install, upgrade Debian + latest zlib will install.
I you must build from scratch, use the LFS Build Instructions + be aware of problems. If you install zlib-1.2 over the top of your system zlib-1.3, likely you'll have many problems + may break your reboots.
Install this library someplace like /opt or /usr/local + build your PHP extension from source, using the zlib-1.2 install directory.
For your local machine, you'll do the same. I'm guessing your using Macs, since you mention brew. You'll have to be very careful here also, as trying to build one new library, hopefully will trigger rebuilding or relinking all code which depends on this library.
I use Macports as the dependency mechanism seems to work better.
If I were using brew, I'd like remove all code installed by brew + reinstall all brew built code. This should pick up all latest code, including zlib.
Last item. Since your trying to build a PHP extension, I'd strongly suggest you'll save your time + sanity by starting with a fresh, updated OS (like Ubuntu Zesty) + LAMP Stack, so you have latest Apache-2.4.29 + PHP-7.1.11 as your starting point. Then you can just install packages from normal PPAs + your problem will resolve itself with no source building.