- Upgrade to PHP 8 with Homebrew on Mac
- # Upgrading with Homebrew
- # Normal upgrade
- # Upgrade with shivammathur/homebrew-php
- # Next steps
- # Valet
- # Extensions
- # Last step
- How to use the php that brew installed?
- 6 Answers 6
- According to the contributors of the Homebrew php formula.
- Change mac os x default php version
- 3 Answers 3
- How can I easily switch between PHP versions on Mac OSX?
- 7 Answers 7
- Using brew
- pixeline / php_upgrade_to_71.sh
- This comment has been minimized.
- n8jadams commented Jul 15, 2017
- This comment has been minimized.
- coulon-xyz commented Aug 24, 2017
- This comment has been minimized.
- TomMuc1 commented Sep 17, 2017
- This comment has been minimized.
- vaske commented Oct 5, 2017 •
- This comment has been minimized.
- adnauseum commented Oct 9, 2017
- This comment has been minimized.
- gusbemacbe commented Oct 12, 2017
- This comment has been minimized.
- TechNinjaWeb commented Oct 25, 2017
- This comment has been minimized.
- wbswjc commented Oct 25, 2017
- This comment has been minimized.
- Narven commented Nov 3, 2017
- This comment has been minimized.
- Peneheals commented Nov 15, 2017 •
- This comment has been minimized.
- amrutjadhav commented Nov 16, 2017
- This comment has been minimized.
- COil commented Dec 2, 2017
- This comment has been minimized.
- alemol commented Dec 11, 2017
- This comment has been minimized.
- bibibaonam commented Dec 14, 2017
- This comment has been minimized.
- latheva commented Jan 25, 2018
- This comment has been minimized.
- dib258 commented Feb 12, 2018
- This comment has been minimized.
- varshaan0sharma commented Mar 24, 2018
- This comment has been minimized.
- marknt15 commented Mar 30, 2018
- This comment has been minimized.
- huebs commented Apr 2, 2018 •
- This comment has been minimized.
- ToniTonish commented Apr 9, 2018
- This comment has been minimized.
- heberfomin commented Apr 11, 2018
- This comment has been minimized.
- artcoholic commented Apr 12, 2018
- This comment has been minimized.
- gotraveltoworld commented Apr 12, 2018 •
- This comment has been minimized.
- aoberoi commented Apr 13, 2018
- This comment has been minimized.
- clozed2u commented Apr 13, 2018 •
- This comment has been minimized.
- EugenMayer commented Apr 13, 2018
- This comment has been minimized.
- w0rd-driven commented Apr 14, 2018
Upgrade to PHP 8 with Homebrew on Mac
Do you want to learn more about PHP 8.1? There’s The Road to PHP 8.1. For the next 10 days, you’ll receive a daily email covering a new and exiting feature of PHP 8.1; afterwards you’ll be automatically unsubscribed, so no spam or followup. Subscribe now!
# Upgrading with Homebrew
Start by making sure brew is up-to-date:
Next, upgrade PHP. You can either use the built-in php recipe, use tap shivammathur/homebrew-php . I’d recommend the second approach, since it allows you to easily install several PHP versions and switch between them.
# Normal upgrade
# Upgrade with shivammathur/homebrew-php
To switch between versions, use the following command:
You can read more in the repository.
# Next steps
Check the current version by running php -v :
Restart Nginx or Apache:
And make sure that your local web server also uses PHP 8 by visiting this script:
The version should show 8.0.x .
Note: if you’re using Laravel Valet, please keep on reading, you need some extra steps in order for the web server to properly work.
# Valet
If you’re using Laravel Valet, you should do the following steps to upgrade it:
You can use valet use to switch between PHP versions:
Note that if you’re using an older Valet version (prior to v2.13.18), when switching from PHP 8 to PHP 7.4 there was a bug that didn’t properly update the changes. This was fixed in Valet 2.13.18 so that it now automatically removes the valet socket after having run valet use php@7.4 . If you need to do this manually, you can run:
# Extensions
PHP extensions are installed using pecl. I personally use Imagick, Redis and Xdebug. They can be installed like so:
You can run pecl list to see which extensions are installed:
You can search for other extensions using pecl search :
Make sure to restart your web server after installing new packages:
If you’re using Laravel Valet, you should restart it as well.
Make sure all extensions are correctly installed and loaded by checking both your PHP webserver and CLI installs:
If extensions aren’t properly loaded, there are two easy fixes.
First, make sure the extensions are added in the correct ini file. You can run php —ini to know which file is loaded:
Now check the ini file:
Note that if you’re testing installed extensions via the CLI, you don’t need to restart nginx, apache or Valet when making changes to ini settings.
The second thing you can do, if you’re updating from an older PHP version which also used pecl to install extension; is to reinstall every extension individually.
# Last step
Finally you should test and upgrade your projects for PHP 8 compatibility.
Источник
How to use the php that brew installed?
On my mac I’ve got php installed and working fine. I recently wanted to install mcrypt, so I did so using brew. Although it seemed to install fine, it doesn’t show up in my phpinfo(). So I think that the php that brew installed mcrypt in, isn’t the php that apache uses.
Does anybody know how I can:
- check whether there is a difference between the php installed by brew and the php which Apache uses?
- make apache use the php that brew installed?
All tips are welcome!
6 Answers 6
You have to make your Apache use the PHP that you just downloaded.
Open your httpd.conf (mine is at /etc/apache2/httpd.conf ) and look for the line that loads the PHP module, something like:
LoadModule php5_module path/to/php
Then, make it point to the PHP that brew installed for you with mcrypt support. Mine was at this path. Yours can vary depending on the PHP version that you installed.
Finally you will need to restart your Apache server to load the new configuration:
sudo apachectl restart
According to the contributors of the Homebrew php formula.
The contributors of the Homebrew php formula give the following instructions. The exact instructions reproduced here install php7.4. Substitute the php version you need.
(Avoid «special» ways of accomplishing your objective; they are often problematic. «Official» approaches are more likely to give you a predictable, maintainable setup.)
The contributors of the formula also provide the following instructions for enabling PHP in Apache:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
Finally, check DirectoryIndex includes index.php
The php.ini and php-fpm.ini file can be found in:
These instructions for enabling PHP in Apache appear in stdout when you install php. Alternatively in Terminal use brew info php or visit the Homebrew PHP formula page
Источник
Change mac os x default php version
In my mac (version 10.13.6 High Sierra) php -v output is PHP 7.1.32 . I need to update this 7.1 version to 7.3.
i tried to remove this version using brew unlink php7.1 but it’s not worked.
How can i upgrade php version.
3 Answers 3
$ brew upgrade php : ( get the latest homebrew php packages )
$ brew install php@7.4 : ( Install php 7.4 )
$ brew link php@7.4 : ( create an alias to this keg-only version; see comments output during installation )
$ echo ‘export PATH=»/usr/local/opt/php@7.4/bin:$PATH»‘ >>
/.bash_profile : ( Add the alias to your path; see comments output during installation )
/.bash_profile : ( Reload .bash_profile to use the new settings immediately )
then install the latest php version (PHP 8.0.8 in the time of writing):
link new version to /usr/local/Cellar/php/8.0.8:
then open the shell’s resource file, located in
/ (in my case Z-shell or ZSH):
press i to insert and somewhere in your resource file append a new path to your $PATH variable, like this:
or in the case of ZSH, you should also be able to do it like this:
then press esc to escape from insert mode, and press :wq to save/write and quit the editor. The final step is to source the file to apply new changes permanently.
Источник
How can I easily switch between PHP versions on Mac OSX?
I would like to test my application on PHP 5.3 up to PHP 7.0.
Where and how can I install the versions and how can I switch them by running a small script?
7 Answers 7
If you have both versions of PHP installed, you can switch between versions using the link and unlink brew commands.
For example, to switch between PHP 7.4 and PHP 7.3
PS: both versions of PHP have be installed for these commands to work.
I found this very good tutorial on how to install and switch php versions on OSX.
I can switch the version like
Exactly what I want!
Using brew
Show current version
Change to different version
(eg. changing from 5.5.x to version 7.0.latest) :
Example: Let us switch from php 7.4 to 7.3
If you get Warning: php@7.3 is keg-only and must be linked with —force Then try with:
If you install PHP with homebrew, you can switch between versions very easily. Say you want php56 to point to Version 5.6.17, you just do:
i think unlink & link php versions are not enough because we are often using php with apache(httpd), so need to update httpd.conf after switch php version.
i have write shell script for disable/enable php_module automatically inside httpd.conf , look at line 46 to line 54 https://github.com/dangquangthai/switch-php-version-on-mac-sierra/blob/master/switch-php#L46
Follow my steps:
1) Check installed php versions by brew, for sure everything good
Источник
pixeline / php_upgrade_to_71.sh
# 1. Install brew —> http://brew.sh/ |
# 2. run the following commands in your Terminal |
brew tap homebrew/dupes |
brew tap homebrew/versions |
brew tap homebrew/homebrew-php |
brew install —with-openssl curl |
brew install —with-homebrew-curl —with-apache php71 |
brew install php71-mcrypt php71-imagick |
# 3. Follow these instructions to make Apache and php-cli use the newer php executable and make the change persist after reboot. |
brew info php71 |
# restart apache |
sudo apachectl restart |
# apply PATH changes without relogging |
source |
This comment has been minimized.
Copy link Quote reply
n8jadams commented Jul 15, 2017
Thanks for this! I tried a million other ways and this is what eventually got it to work.
This comment has been minimized.
Copy link Quote reply
coulon-xyz commented Aug 24, 2017
This comment has been minimized.
Copy link Quote reply
TomMuc1 commented Sep 17, 2017
thanks for sharing — worked instantly 🙂
This comment has been minimized.
Copy link Quote reply
vaske commented Oct 5, 2017 •
Thanks for this one, I followed up instructions and after sudo apachectl restart I keep getting this kind of error:
Can’t find solution for it, if I revert back to php56 it works, but php71 or php70 runs into this issue, any idea what might cause it?
I already added ServerName localhost to httpd.conf
Also apache use /etc/php.ini which is ini file of php56 default one.
This comment has been minimized.
Copy link Quote reply
adnauseum commented Oct 9, 2017
Thanks for your time and effort!
This comment has been minimized.
Copy link Quote reply
gusbemacbe commented Oct 12, 2017
If you use macOS High Sierra, it comes already with php71. If you want to upgrade to php72, and in these commands, change from php71 to php72. And you have to write brew install homebrew/php/php72-mcrypt and brew install homebrew/php/php72-imagick .
This comment has been minimized.
Copy link Quote reply
TechNinjaWeb commented Oct 25, 2017
This was the solution for me. Thanks for your help!
This comment has been minimized.
Copy link Quote reply
wbswjc commented Oct 25, 2017
@vaske Try add 127.0.0.1 vaske-mbp.local to /etc/hosts .
This comment has been minimized.
Copy link Quote reply
Narven commented Nov 3, 2017
brew tap homebrew/dupes deprecated
This comment has been minimized.
Copy link Quote reply
Peneheals commented Nov 15, 2017 •
If you are using AMPPS or any other solution not just pure Apache, and imagick or other php extensions are not important, just use this:
This comment has been minimized.
Copy link Quote reply
amrutjadhav commented Nov 16, 2017
Saved me lot of time. Thanx for this gist.
This comment has been minimized.
Copy link Quote reply
COil commented Dec 2, 2017
Yeah thanks, I always forget the —with-apache stuff.
This comment has been minimized.
Copy link Quote reply
alemol commented Dec 11, 2017
In case of facing this warning:
$ brew install —with-homebrew-curl —with-apache php71
Warning: homebrew/php/php71 7.1.12_23 is already installed, it’s just not linked.
You can use brew link php71 to link this version.
Then this error:
$ brew link php71
Linking /usr/local/Cellar/php71/7.1.12_23.
Error: Could not symlink sbin/php-fpm
/usr/local/sbin is not writable.
The solution is this:
$ sudo mkdir /usr/local/sbin
$ sudo chown -R whoami :admin /usr/local/sbin
$ brew link php71
Linking /usr/local/Cellar/php71/7.1.12_23. 17 symlinks created
This comment has been minimized.
Copy link Quote reply
bibibaonam commented Dec 14, 2017
thank you so much, it works great.
This comment has been minimized.
Copy link Quote reply
latheva commented Jan 25, 2018
Thanks, it helped me a lot.
This comment has been minimized.
Copy link Quote reply
dib258 commented Feb 12, 2018
I had to make some modification to make gist work ! 🙂
This comment has been minimized.
Copy link Quote reply
varshaan0sharma commented Mar 24, 2018
brew install homebrew/php/php71-mcrypt worked for me
This comment has been minimized.
Copy link Quote reply
marknt15 commented Mar 30, 2018
At first I tried to make it work but there are errors and I thought of another way. The MAMP way.
Add this in you .bash_profile
I will try the brew php71 way some other time
This comment has been minimized.
Copy link Quote reply
huebs commented Apr 2, 2018 •
I believe I just ran into a related issue:
If you’re seeing this error when opening a new terminal:
/.bashrc for a line that looks like this:
And change it to this:
If you’re seeing this error when opening a new terminal:
/.bashrc for a line that looks like this:
And change it to this:
This comment has been minimized.
Copy link Quote reply
ToniTonish commented Apr 9, 2018
i’m sorry if this isn’t the correct section where report errors.
i got this when brew install —with-homebrew-curl php71
the error is Warning: php@7.1: this formula has no —with-homebrew-curl option so it will be ignored!
any advice on how to solve it? i need to change from SSL Version => SecureTransport to SSL Version => OpenSSL/1.0.2j
This comment has been minimized.
Copy link Quote reply
heberfomin commented Apr 11, 2018
Hello Guys,
First of all, I’m sorry, I’m not an expert in linux environment, worst in MacOs so, if I made any stupid question, please forgive me.
I’m trying to install extension for MACOS php mcrypt. My environment is MacOs High Sierra with 7.1.1 php.
I’ve tryed this:
$ brew install php71-mcrypt php71-imagick
But I received these errors:
Error: No available formula with the name «php71-mcrypt»
==> Searching for a previously deleted formula (in the last month).
Error: No previously deleted formula found.
==> Searching for similarly named formulae.
==> Searching local taps.
Error: No similarly named formulae found.
==> Searching taps.
==> Searching taps on GitHub.
Error: No formulae found in taps.
it seems that i’m trying to install something that doesn’t exist anymore.
Does anybody knows how could I resolve this?
This comment has been minimized.
Copy link Quote reply
artcoholic commented Apr 12, 2018
I have the same problem as heberfomin. Any help would be appreciated. Thank you!
This comment has been minimized.
Copy link Quote reply
gotraveltoworld commented Apr 12, 2018 •
In fact, Homebrew/php is deprecated, so you can not use this command to install php71.
Today, I also find this problem, I still search for solutions.
You could see origin information from this: https://github.com/Homebrew/homebrew-php
This comment has been minimized.
Copy link Quote reply
aoberoi commented Apr 13, 2018
This comment has been minimized.
Copy link Quote reply
clozed2u commented Apr 13, 2018 •
@gotraveltoworld You can still install older version of PHP via homebrew by using php@
This comment has been minimized.
Copy link Quote reply
EugenMayer commented Apr 13, 2018
@clozed2u problematic right now is xdebug though, but well, i do not need it.
This comment has been minimized.
Copy link Quote reply
w0rd-driven commented Apr 14, 2018
Ran into the depreciation today and the recommendation is buried at the end of Homebrew/homebrew-core#26362, to use pecl.
My need is fortunately only for imagick and xdebug and it was relatively trivial to run pecl install package but it just jams the extensions into php.ini haphazardly which don’t even point to the right location.
I was able to salvage the old files in /usr/local/etc/php/7.1/conf.d and for imagick the file is:
Where the directory /usr/local/Cellar/php@7.1/7.1.16_1/pecl/20160303/ is not /usr/local/Cellar/php@7.1/7.1.16_1/lib/php/20160303/ as it expects. I was getting errors like the following, repeated for each extension installed this way:
Fortunately it isn’t a huge manual change but this totally breaks the normal expected workflow and I sincerely hope I don’t have to do this manual hackery every time or I’m going to learn to stop updating php real quick.
Источник