Hướng dẫn replace php version mac
The solutions above did not work for me on Big Sur I kept on getting: Show
Nội dung chính
To fix this I used the following steps: Step 1 | Tap into another repository of formulae
Step 2 | Install the desired PHP version
Other options are:
Step 3 | Link the PHP Version
Step 4 | Restart TerminalStep 5 | Check PHP version
You should now see the new version.
This also solved my issues with PHP syntax in Visual Studio Code. The latest macOS versions of Big Sur and Catalina currently ship with PHP 7.3 and have a deprecation notice that they intend to drop support for PHP altogether in a future upgrade. You can see this by running a [email protected] Documents % php -v 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 So moving forward the best solution is to use Homebrew to install and then choose whichever version of PHP you want including 7.4 and version 8. So once you have Homebrew installed on your macOS a particular PHP Homebrew formulae will need to be added from this maintainer, what is great about this, is all PHP versions are available whereas only some versions are available on the default Homebrew formulas. After Homebrew install, follow the below: Add the PHP formulaebrew tap shivammathur/php Choose the PHP version – example uses 7.4brew install shivammathur/php/[email protected] Other options are
Link the PHP Version brew link --overwrite --force [email protected] Change your version to match Restart the TerminalRun… php -v You should now see the new version, to change to another version just repeat the process from the brew unlink php && brew link --overwrite --force [email protected] Using new PHP in macOS Shipped ApacheIf 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 and comment it out and add in the new PHP version path: #LoadModule php7_module libexec/apache2/libphp7.so LoadModule php7_module /usr/local/opt/[email protected]/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/[email protected]/lib/httpd/modules/libphp5.so #LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so #LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so #LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so PHP 8 and macOS ApacheOne extra step is needed for PHP 8 and macOS bundled Apache: sudo nano /etc/apache2/httpd.conf Add the new PHP 8 and comment out the old one. LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so Go to the end of the file and add:
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
brew untap homebrew/php Run brew cleanup: brew cleanup How do I upgrade PHP to 8.0 on Mac?Upgrading with Homebrew. Normal upgrade. brew upgrade php.. Upgrade with shivammathur/homebrew-php. brew tap shivammathur/php brew install shivammathur/php/[email protected] To switch between versions, use the following command: brew link --overwrite --force [email protected] ... . Next steps. Check the current version by running php -v : php -v.. How do I update PHP to 7.4 on Mac?How do I update PHP to latest version?How do I change the PHP version?. Log in to your one.com control panel.. Scroll down to the Advanced settings tile and select PHP and database settings.. Scroll down to Update PHP version.. Select the PHP version you want to switch to and click Update.. How do I find PHP version on Mac?2 Answers. Go to File > Preferences > User Settings > Settings.json.. Change the value of php. validate. executablePath according to the installed directory of php7. "php.validate.executablePath": "/Applications/MAMP/bin/php/php7.0.14/bin/php". Relaunch VM Code.. |