Upgrade PHP 8.0 on macOS Sonoma Using Homebrew
In this post, we will give you information about Upgrade PHP 8.0 on macOS Sonoma Using Homebrew. Here we will give you details about upgrading PHP 8.0 on macOS Sonoma Using Homebrew And how to use it also give you a demo for it if it is necessary.
First, make sure that your homebrew is up to date
brew tap shivammathur/php
Next, upgrade PHP. You can either use the built-in php recipe, but I recommend using the shivammathur/homebrew-php tap.
brew install shivammathur/php/php@8.0
Link the PHP Version
brew unlink php && brew link --overwrite --force php@8.0
Change your version to match
Restart the Terminal and Run…
php -v
You should now see the new version, to change to another version just repeat the process from the brew install… then unlink and link in the new PHP version by issuing a command like the below but with your correct version:
brew unlink php && brew link --overwrite --force php@8.0
Using new PHP in macOS Shipped Apache
If you are using macOS in-built shipped Apache, you can use the new PHP version by editing the Apache file:
sudo nano /etc/apache2/httpd.conf
Find the PHP module comment it out and add in the new PHP version path:
#LoadModule php7_module libexec/apache2/libphp7.so LoadModule php7_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp7.so
Restart Apache
sudo apachectl restart
Now the new PHP version will be used.
You could download all the versions and just uncomment the one you want if you intend to swap around:
#LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so #LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/php@7.3/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so #LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so
PHP 8 and macOS Apache
One extra step is needed for PHP 8 and macOS bundled Apache:
sudo nano /etc/apache2/httpd.conf
Add the new PHP 8 and comment on the old one.
LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so
Go to the end of the file and add:
<FilesMatch .php$> SetHandler application/x-httpd-php </FilesMatch>
Restart Apache
Removing Older Homebrew PHP version (optional)
If you have the older PHP formulas from an older Homebrew installation, you may wish to remove these:
rm -rf $(brew --cellar)/php
Remove old PHP Launch Agents and daemons, if present:
rm -f ~/Library/LaunchAgents/homebrew.mxcl.php* rm -f /Library/LaunchAgents/homebrew.mxcl.php* rm -f /Library/LaunchDaemons/homebrew.mxcl.php*
Remove the deprecated homebrew/php tap, if present:
brew untap homebrew/php
Run brew cleanup:
brew cleanup
Conclusion for Upgrade PHP 8.0 on macOS Sonoma Using Homebrew
Hope this code and post will help you implement Upgrade PHP 8.0 on macOS Sonoma Using Homebrew. if you need any help or any feedback give it in the comment section or if you have a good idea about this post you can give it in the comment section. Your comment will help us to help you more and improve us.