Perhaps try specifying which openssl you want to use during configure and make, i.e. to successfully install php from source on my mac I used:
# install missing requirements
brew install re2c libiconv pkg-config
# configure (you can change PATH for a single command without needing to change your ~/.bashrc or ~/.bash_profile)
PATH=/opt/homebrew/Cellar/bison/3.8.2/bin/:/opt/homebrew/opt/libiconv/bin/:/opt/homebrew/bin/:$PATH ./configure --with-openssl
# make the executable, then check you don't have any errors in the installation
PATH=/opt/homebrew/Cellar/bison/3.8.2/bin/:/opt/homebrew/opt/libiconv/bin/:/opt/homebrew/bin/:$PATH make
make test
# if there are no errors, install the software
make install
Does this approach solve your problem?