Issues in setting up my php environment

Hello All,

I wanted to setup my php environment on my macOS Catalina. After installing brew I am having strange issues.

$ php -v
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
zsh: abort php -v

but I am able to see apache running, and it is able to configure itself with php. So on the browser it works but not on command line.

After browsing for solution, I downgraded openssl

brew uninstall --ignore-dependencies openssl brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
brew switch openssl 1.0.2t php -v

this worked, but now apache did not start.
$ apachectl start
httpd: Syntax error on line 184 of /usr/local/etc/httpd/httpd.conf: Cannot load /usr/local/opt/php/lib/httpd/modules/libphp7.so into server: dlopen(/usr/local/opt/php/lib/httpd/modules/libphp7.so, 10): Library not loaded: /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib\n Referenced from: /usr/local/opt/php/lib/httpd/modules/libphp7.so\n Reason: image not found

Now I tried to reinstall php
$ brew reinstall php
openssl was also installed. Apache worked, php with apache worked, but commandline php is not working.

$ php -v
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
zsh: abort php -v

So if I fix the issue for command line, apache does not work with php. If I fix the issue for apache, then command line does not work. I am puzzled now what to do.

Please suggest.

Note: I have not installed mysql yet. After this is resolved. will move on to that.

Regards,
Shashidhar.G

You should absolutely not install that OpenSSL version, it has been unsupported for half a year already. What does which php output?

$ which php
/usr/local/bin/php

I did not install OpenSSL. it is installed when I reinstalled php.

What does ls -l /usr/local/bin/php say?

lrwxr-xr-x 1 Shashi admin 33 Oct 24 2017 /usr/local/bin/php -> …/Cellar/php70/7.0.24_16/bin/php

That is a very old unsupported php version. What are you running to install PHP? Because all you need to do is brew install php.

I was setting up Magento 2 environment. I have tried the following commands as well.

$brew uninstall php
$brew install php

So it fetched php 7.4.6, it is working perfectly on browser. Only command line is showing me

dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /usr/local/bin/php
  Reason: image not found
zsh: abort      php -v

That’s because php in the command line is pointing to php 7.0. You need to brew remove php70 first.

That worked. Thanks. How did you know I had php70? I didn’t

It says you have php70 here

ah right!!!. I must be blind to miss that.
Thanks a lot