0

I was using the built in macos big sur apache and php, but an update deleted all the preferences that i had in apache...as it allways does.

This time i wanted to install the homebrew version of apache and php, and followed all the indications:

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/8.0/

after i configure everything, check the config file with: sudo apachectl configtest and returned ok. i test my new php with: php -v and it returns the same php that i had before install the hombrew version:

WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Dec 21 2020 21:33:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies

if i run /usr/local/bin/php -v directly from the brew php folder:

PHP 8.0.3 (cli) (built: Mar  4 2021 20:45:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies

how can i use the brew php?

elgranchuchu
  • 333
  • 1
  • 5
  • 18
  • You need to remove the one that is pre installed in mac os and then install using brew – Adarsh Mohan Mar 15 '21 at 16:56
  • check you current php installation path : php --ini with both php versions. I do run internally 3 different php versions for some testing purposes (the one that you are using in apache must be adapted to the required one) https://stackoverflow.com/questions/34909101/how-can-i-easily-switch-between-php-versions-on-mac-osx – Christian Felix Mar 15 '21 at 17:02
  • It is not recommended, and is OMHO an *extremely poor practice* to tamper with OS vendor-supplied software @AdarshMohan That is what `/usr/local` is for - a place to add local variations. – Mark Setchell Mar 15 '21 at 17:56

2 Answers2

0

It's usually not a good idea to remove system binaries. Instead, you can add an alias in the ~/.zshrc file. At the end of the file, add:

alias php="/usr/local/bin/php"
shreyasm-dev
  • 2,711
  • 5
  • 16
  • 34
0

the solution was to put this in ~/.bash-profile

export PATH=/usr/local/bin:$PATH

the restart the pc, and it was ready, now when i php -v

PHP 8.0.3 (cli) (built: Mar  4 2021 20:45:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies
elgranchuchu
  • 333
  • 1
  • 5
  • 18