I want to update php version, currently I have 5.5.38 and I want 7.1
What I tried so far is using this command:
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1
I tried several different versions but none of them worked.
It opens bash_profile for a second and then I get Received SIGHUP or SIGTERM and message below:
Buffer written to /Users/Morpheus/.bash_profile.save.6
Not sure what went wrong and why it won't update...
Any ideas?
Thanks.
Install php
brew install php#7.2
Install the required PHP to your PATH
echo 'export PATH="/usr/local/opt/php#7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.2/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Then make sure it's all working
php -v
php --version
This command will show you where your ini file is loaded
php --ini
Use Homebrew:
I would probably recommend installing homebrew to manage such installations for you. With that installed you can just run the following command to install php7.1
brew update
brew install php#71
The simplest way to update the version of php on Mac is via Homebrew.
If you do not have brew please visit https://brew.sh/
or install via command in terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
When finished installing Homebrew, run the following commands:
brew update && brew upgrade
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew unlink php#56
brew install php#71
You might get an error if PHP 5.6 has not been installed by brew previously, but don't worry, you can simply continue.
You can also change the version to 7.0 by replacing the command from above commands from brew install php#71 to brew install php#70.
You can check the output by command.
php -v
If the output of php -v still doesn’t echoes the version 7, simply type this command and hit enter in terminal.
export PATH=/usr/local/php5/bin:$PATH
The solutions above did not work for me on Big Sur I kept on getting:
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
To fix this I used the following steps:
Step 1 | Tap into another repository of formulae
brew tap shivammathur/php
Step 2 | Install the desired PHP version
brew install shivammathur/php/php#7.4
Other options are:
php#5.6
php#7.0
php#7.1
php#7.2
php#7.3
php#7.4
php#8.0
php#8.1 or known as just PHP
Step 3 | Link the PHP Version
brew link --overwrite --force php#7.4
Step 4 | Restart Terminal
Step 5 | Check PHP version
php -v
You should now see the new version.
PHP 7.4.25 (cli) (built: Oct 21 2021 00:29:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies
This also solved my issues with PHP syntax in Visual Studio Code.
For me none of the mentioned worked. So to upgrade from php#7.3.11 to php#7.4 I had to install
brew update
brew install php#7.4
export PATH=/usr/local/php7.4/bin:$PATH
Then force overwrite as following:
brew link --overwrite --force php#7.4
then
php -v
output: PHP 7.4.24
Try to use below command
brew update
brew install php#72
If it shows below error,
"Error: No available formula with the name "php"
try
brew install php#7.2
try to use the command, its working fine with me
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
In case you guys run all install commands above but when checking the PHP version, it is still linking to the old version. So you guys may want to update the PATH.
In my case, I open the .bash_profile which located in HOME directory by command:
nano ~/.bash_profile
Then, I add the path to the new version of PHP:
PATH=/usr/local/Cellar/php/7.4.4/bin:<other_paths>
Finally, run source ~/.bash_profile command to refresh the terminal window and checking the PHP version again.
Hope this helps.
Try to use below command
brew update
brew upgrade php
or
brew reinstall php
You can brew upgrade php7
or brew uninstall old php version.
Last, I recommend you brew install php-version, php-version can help you change your php version
Im running Mac OS 10.13.8 and this worked all the way to PHP version 7.3
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3.8-20190811-205217
brew install php#x.y
brew link --overwrite --force php#x.y
For Mac remember this is the last step & don't forget to kill & restart the terminal
echo 'export PATH="/opt/homebrew/opt/php#8.0/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php#8.0/sbin:$PATH"' >> ~/.zshrc
Related
I try to update my PHP version to 7.4 on macOS Catalina with brew.
I did brew install php#7.4
If I check my version php -v, I still see the old version PHP 7.3.11?
What do I have to do?
Update:
After brew doctor I get:
Warning: Homebrew's sbin was not found in your PATH but you have
installed formulae that put executables in /usr/local/sbin. Consider
setting the PATH for example like so: echo 'export
PATH="/usr/local/sbin:$PATH"' >> ~/.profile
You can find my similar answer for php#7.2.
brew install php#7.4
brew link --force --overwrite php#7.4
brew services start php#7.4
export PATH="/usr/local/opt/php#7.4/bin:$PATH"
export PATH="/usr/local/opt/php#7.4/sbin:$PATH"
try:
brew update
brew upgrade php
php -v
brew services start php
or
brew services restart php
if you use apache server:
sudo apachectl restart
if you use ngnix
sudo nginx -s reload
Edit:
brew unlink php#7.3
brew link php#7.4
If anyone want to downgrade php from latest 8.1.2 to 7.4 on systems demand, try the below commands with homebrew:
Installing PHP 7.4 :
brew install php#7.4
brew services restart php
brew unlink php#8.1
brew link php#7.4
echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php#7.4/sbin:$PATH"' >> ~/.zshrc
Or
export PATH="/usr/local/opt/php#7.4/bin:$PATH"
export PATH="/usr/local/opt/php#7.4/sbin:$PATH"
Using terminal of MacOS. Don't use terminal in vscode.
I recently faced this issue, all the suggestion here didn't work until I ran:
xcode-select --install
Then ran the command I was trying before and the error stopped, for my case it was php
dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib
Referenced from: /usr/local/opt/php#7.4/bin/php
Reason: image not found
zsh: abort php -v
I move to directory by: cd /usr/local
Find the file location by: find /usr/local/ -name libphp7.so. (Then get the file location at: /usr/local//Cellar/php#7.4/7.4.23/lib/httpd/modules/libphp7.so. I copy this.)
I open the file by: sudo vim /etc/apache2/httpd.conf
Look for the line by: /libphp7.so
Uncomment the line and update the line by: LoadModule php7_module /usr/local//Cellar/php#7.4/7.4.23/lib/httpd/modules/libphp7.so
Restart apache by: sudo apachectl restart
Verify PHP by accessing http://localhost/phpinfo.php
How to configure PHP 7.4.X in to mac where as it shows 7.2.8 on Php -v command. I tried to install latest version of XXAMP which come with 7.4.8 but still the problem remains the same.
You can use brew to achieve this:
$ brew unlink php#7.2
$ brew install php#7.4
$ brew link php#7.4 --force
Then in the future you can reverse this by doing this:
$ brew unlink php#7.4
$ brew link php#7.2 --force
I am trying to install PHP 7.2 on my Mac
I did:
php --version
PHP 7.1.33 (cli) (built: Jan 26 2020 22:52:32) ( NTS )
So I started to install the PHP 72
brew update
brew upgrade
Then I couldnt unlink PHP71
brew unlink php71
Error: No such keg: /Users/tavelino/.brew/Cellar/php71
So I tried to remove PHP 71
brew remove --force --ignore-dependencies httpd
... Uninstalling httpd... (1,625 files, 27.2MB)
brew remove --force --ignore-dependencies php70-xdebug php71-xdebug
brew remove --force --ignore-dependencies php70-imagick php71-imagick
brew remove --ignore-dependencies --force php70 php71
Doesn't uninstall PHP71. And I have no idea what's going on
So I tried to install php72
brew install httpd php72
...
To have launchd start php#7.2 now and restart at login:
brew services start php#7.2
Or, if you don't want/need a background service you can just run:
php-fpm
Then I also runned
brew install php72 --with-httpd --with-thread-safety
Now if I check the version:
php -v
It still PHP 71
PHP 7.1.33 (cli) (built: Jan 26 2020 22:52:32) ( NTS )
So I am trying to find a way to change the version.
#Thais Avelino, I believe this sounds more like a PATH issue.
Below is basically what I did
brew install php#7.2, php7.2 is under an version alias now
echo 'export PATH="/usr/local/opt/php#7.2/bin:$PATH"' >> ~/.bash_profile, this might be a step for your case
source ~/.bash_profile to apply the change
$ php --version
PHP 7.2.31 (cli) (built: May 28 2020 23:54:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.31, Copyright (c) 1999-2018, by Zend Technologies
$ ls -al $(which php)
-r-xr-xr-x 1 rchen staff 13912836 Jul 4 16:33 /usr/local/opt/php#7.2/bin/php
Let me know if that works out, also attach brew --version and brew config if you still run into any issue. Thanks!
Experiment with the positioning of your php path. Try moving it to the beginning.
i.e. like so...
PATH="/usr/local/php5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin: ...etc.
I used packagephp-osx.liip.ch package to upgrade to 7.3. It creates php5 alias for the folder with version 7.3, hence php5 in the PATH.
Terminal kept showing older version (7.1.33) until I modified the PATH.
short question - how to install php7.1 on OS X Sierra and keep 5.6 as default.
I only want to run php 7.1 in terminal using php7 - and when using php the original 5.6 should be used ...
thanx in advance
tom
There are a number of ways to achieve this. I would install PHPBrew, since that allows you install as many PHP versions as you want without touching the system's PHP version.
I would also install Homebrew as it's likely there will be dependencies you need to resolve with specific extensions.
Another option would be to install PHP7 via Homebrew and alias it to php7. Or you could compile it from source. However, if you plan on having one or more PHP versions readily available alongside the system version then PHPBrew is probably the most flexible option.
Install PHP 5.6:
brew install php56
Install PHP 7.0:
php70
Switch to php5.6 in terminal:
brew unlink php70
brew link php56
Switch to php7.0 in terminal:
brew unlink php56
brew link php70
Source: Switching PHP version on mac with homebrew
maybe someone other is searching for a very clean solution too - here is what finally worked for me perfectly. this is based on the hints and tips from matthew daly and surfer 190 - thanx again!
takes just 5 minutes - here we go ...
first install xcode command line tools (just 160mb instead 4.5gb):
xcode-select --install
then install homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
short test if anything up to here is fine:
brew doctor
install php 7.1:
brew install php71
i found that some have problems with the above direct php install - this resolves these problems - and then try again the php install:
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
make a symlink to the original php-binary that came with osx:
ln -s /usr/bin/php /usr/local/bin/php5
here is the result - now php 7.1 is the default php version - and using php5 will use the old php-binary that came with your osx preinstalled:
php -v
php5 -v
I'm trying to setup Laravel's Valet which, as a dependency, requires PHP 7. When I try to install PHP 7 with Homebrew I get the following error:
Configuring SAPI modules
checking for Apache 2.0 handler-module support via DSO through APXS...
Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
The output of /usr/sbin/apxs follows:
apxs:Error: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/apr-1-config not found!.
configure: error: Aborting
READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/brew):
https://github.com/Homebrew/homebrew-php/issues
These open issues may also help:
php70-dbase https://github.com/Homebrew/homebrew-php/issues/3508
php70-intl not found https://github.com/Homebrew/homebrew-php/issues/3591
php70-opcache install issue https://github.com/Homebrew/homebrew-php/issues/3586
Problem installing php70-mcrypt, php70-opcache, php70-xdebug on El Capitan https://github.com/Homebrew/homebrew-php/issues/3587
Add php70-zmq formula https://github.com/Homebrew/homebrew-php/pull/3474
Problem installing homebrew/php/php70-imagick https://github.com/Homebrew/homebrew-php/issues/3571
Install PHP70: Incompatible library version https://github.com/Homebrew/homebrew-php/issues/3444
brew install php70-redis https://github.com/Homebrew/homebrew-php/issues/2762
Allow --enable-redis-igbinary for php70-redis https://github.com/Homebrew/homebrew-php/pull/3473
Add head formula for php70-uploadprogress https://github.com/Homebrew/homebrew-php/pull/3178
This is on a fresh install of MacOS Sierra (actual release, not a beta) with a fresh install of Homebrew (updated). I have installed, ran and agreed to the Xcode licensing agreement.
I have no idea what these errors mean. How can I fix them?
Right I've figured it out. I'm posting the steps to successfully install the require components below in case anybody else stumbles upon this issue:
1). make sure Homebrew is up to date:
brew update
2). Fix the PHP 7 error by making sure Xcode is installed and then typing the following into the Terminal:
brew install apr apr-util
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/opt/apr/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/opt/apr-util/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
3). Run the following command (otherwise the PHP installation will complain about missing libz):
xcode-select --install
4). You can now install PHP 7 with Homebrew:
brew install homebrew/php/php70
It may also be important for those using the macOS-delivered installation of Apache with PHP via Homebrew that (quote from Homebrew php70 install):
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-apache option. See brew options php70 for more details.
I used the following commands to make it work.
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew update && brew install apr apr-util
brew link apr-util --force
brew link apr --force
which apu-1-config
which apr-1-config
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
brew install php70
Here is how I upgrade PHP 5.6 to 7.2 in my Macbook Pro (macOS Sierra)
a. Update the brew package first.
$ brew update && brew upgrade
b. Unlink the old version of PHP if it was installed with Homebrew.
$ brew unlink php56
c. Install the new version of PHP.
$ brew install php72
After installation, it shows:
To enable PHP in Apache add the following to httpd.conf (/etc/apache2) and restart Apache:
d. Using vim edit httpd.conf of apache2.
$ sudo vim /etc/apache2/httpd.conf
Search “php5_module” then commend out the statements as follows:
#Comment out the PHP5 module
#LoadModule php5_module libexec/apache2/libphp5.so
Add the commands as follows:
#Enable PHP 7 module
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
e. 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/7.2/
f. Restart Apache service
$ sudo apachectl restart
g. check the php version:
$ php -v
PHP 7.2.7 (cli) (built: Jun 22 2018 06:29:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Done!
Please visit the article "Upgrade PHP version from 5.6 to 7.2 on macOS Sierra (10.12)"
of my blog for more information!
Cheer!