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?
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"
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.