Mac os change php version

Switch between PHP versions in Mac with Homebrew & sphp

Many times I found me in the scenario where I need to use different versions for PHP at the same time for different projects. So here is a tiny guide of how to do this in the easy way.

First install different versions for php using Homebrew (If you haven’t installed Homebrew, just follow the at https://brew.sh/), to install this use:

brew install php@7.1 brew install php@7.2 brew install php@7.3 brew install php@7.4

Now you have to install sphp, you can do this with this script:

curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /usr/local/bin/sphp
Once it is downloaded in your computer just make it executable:

Cool, now restart your terminal and try to switch between versions with

Switching to php@7.4 Switching your shell Unlinking /usr/local/Cellar/php@5.6/5.6.36… 0 symlinks removed Unlinking /usr/local/Cellar/php@7.0/7.0.30… 0 symlinks removed Unlinking /usr/local/Cellar/php@7.1/7.1.32_1… 0 symlinks removed Unlinking /usr/local/Cellar/php@7.2/7.2.30_1… 0 symlinks removed Unlinking /usr/local/Cellar/php@7.3/7.3.18… 25 symlinks removed Unlinking /usr/local/Cellar/php/7.4.6… 0 symlinks removed Linking /usr/local/Cellar/php/7.4.6… 24 symlinks created You will need sudo power from now on
php --version PHP 7.4.6 (cli) (built: May 14 2020 10:40:11) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

I will be updating this article if I found some issues and some other troubleshooting tips.

Читайте также:  Constructor in cpp file

Troubleshooting

If the php version has not changed check first where does your php executable came from with, to work it should show something like this:

Check your ~/.bash_profile to be sure there no other php version loading after sphp. If there is some PHP loading just comment it, and restart your Terminal.

Leave a Comment Cancel reply

You must be logged in to post a comment.

Источник

Switching between multiple PHP versions on macOS

I recently needed to switch between PHP versions on my macOS environment to work on a legacy project.

As usual, I’d forgotten how to do this, so I’ve decided to publish the steps for my own and other’s reference.

The instructions below are for use with macOS 10.15 Catalina, and allow installation of PHP 5.6, 7.0, 7.1, 7.2, 7.3 & 7.4.

1. Prerequisites

You’ll need both Xcode Command Line Tools and Homebrew installed.

1.1 Install XCode Command Line Tools

1.2 Install Homebrew

Homebrew is a package manager for macOS. It’s like apt on Ubuntu.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

Check that brew has installed:

$ brew --version Homebrew 2.2.5

You can also run brew doctor to check everything is good to go.

2. Install Multiple PHP Versions

As of writing, only PHP 7.2, 7.3 and 7.4 are maintained and supported by Homebrew.

To install PHP 5.6, 7.0 & 7.1 we’ll need to ‘tap’ a repository for deprecated packages:

brew tap exolnet/homebrew-deprecated

Now, we can install all the available PHP versions:

brew install [email protected] brew install [email protected] brew install [email protected] brew install [email protected] brew install [email protected] brew install [email protected]

This may take a little time to install. Go make yourself a brew ☕️.

3. Switching between PHP versions

Once installed, you can switch between PHP versions by ‘linking’ and ‘unlinking’ in brew:

# Switch from 7.4 to 5.6 brew unlink [email protected] brew link [email protected] --force

You can combine brew unlink and brew link to swap between any installed version.

Open Source Alternatives

There are a few open source projects that aim to automate this for you, if you prefer:

Источник

How to easily switch between PHP versions on macOS?

How to easily switch between PHP versions on macOS? cover

Please support us by disabling your ad-block. The revenue help us create more content for the community.

In this post, we’ll learn how to switch between PHP versions in the macOS system. Firstly I assume that PHP is installed using Homebrew and if you have not done so, do follow this tutorial on How to install PHP 8 on macOS Big Sur using Homebrew.

Using Homebrew

By right when using Homebrew, we can install multiple different versions of PHP at the same time but only use it one version at a time. To see which PHP version you have installed do run the command below and if you see it’s ticked ✔︎ then it means it’s installed.

If none of the PHP is ticked then by default the PHP that’s on the system is the default one shipped with macOS. Installing different versions is very important as many projects use a different version of PHP. In this case, let’s assume that we have version 7.4 and 8.0.

By default PHP version on Homebrew is «[email protected]», «[email protected]» and «php» which means that the PHP that has no version number is the latest / highest version, in this current time of writing is version 8.0.

Changing PHP Version


To switch to the PHP version you can simply do run the command below. Switching from PHP version 7.4 to 7.3.

brew unlink [email protected] brew install [email protected] brew link [email protected] php -v

Warning when switching


Sometimes there will be a warning while switching mentioning that linking should use «force» and if that’s the case do use the flag option.

That’s all, by now you should be able to change to any PHP version that your project requires. One piece of advice is that it’s better to have a project to always stay up to date so having maintained aka latest PHP version is always a good practice.

Alternative Tags

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Front End Web Development Tools For Responsive Testing

How to install Xdebug extension on macOS Big Sur

Please support us by disabling your ad-block. The revenue help us create more content for the community.

Источник

Как изменить версию PHP в Mac?

5b3dd88341f74033402369.png

Здравствуйте! Уже какой день пытаюсь изменить версию PHP в Mac OS High Sierra.
php -v сейчас выдает :

Затем запускаю команду:

export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"

затем : which php
выдает такое:
5b3dd9308f160597422900.png
Проверяю опять версию PHP и все тоже самое
5b3dd88341f74033402369.png

Помогите , как исправить проблему. Спасибо

Средний 1 комментарий

TosterModerator

imdeveloper дорогой пользователь, настоятельно рекомендуем еще раз обратить самое пристальное внимание на п. 3.1 регламента работы сервиса (и, в особенности, на его последний абзац). В противном случае, ваши вопросы будут удаляться по причине тег-спама, а систематические нарушения приведут к блокировке учетной записи.

link_web

source ~/.profile export PATH=/usr/local/php5-7.1.19-20180625-094435/bin:$PATH ## # Your previous /Users/magentodev/.bash_profile file was backed up as /Users/magentodev/.bash_profile.macports-saved_2018-03-25_at_22:00:51 ## # MacPorts Installer addition on 2018-03-25_at_22:00:51: adding an appropriate PATH variable for use with MacPorts. export PATH="/opt/local/bin:/opt/local/sbin:$PATH" # Finished adapting your PATH environment variable for use with MacPorts.

link_web

iNickolay

iNickolay

Так же посмотрите
brew doctor

Если не поможет — попробуйте переустановить

brew unlink php@7.0 brew install php@7.1

link_web

MBP-Sergey:~ magentodev$ brew doctor Please note that these warnings are just used to help the Homebrew maintainers with debugging if you file an issue. If everything you use Homebrew for is working fine: please don't worry or file an issue; just ignore this. Thanks! Warning: "config" scripts exist outside your system or Homebrew directories. `./configure` scripts often look for *-config scripts to determine if software packages are installed, and what additional flags to use when compiling and linking. Having additional scripts in your path can confuse software installed via Homebrew if the config script overrides a system or Homebrew provided script of the same name. We found the following "config" scripts: /opt/local/bin/pkg-config /opt/local/bin/ncursesw6-config /opt/local/bin/pcre-config /opt/local/bin/ncurses6-config Warning: You have MacPorts or Fink installed: /opt/local/bin/port This can cause trouble. You don't have to uninstall them, but you may want to temporarily move them out of the way, e.g. sudo mv /opt/local ~/macports Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run `brew link` on these: python@2 Warning: Broken symlinks were found. Remove them with `brew prune`: /usr/local/bin/docker /usr/local/bin/docker-compose /usr/local/bin/docker-compose.backup /usr/local/bin/docker-credential-osxkeychain /usr/local/bin/docker-credential-osxkeychain.backup /usr/local/bin/docker-machine /usr/local/bin/docker-machine.backup /usr/local/bin/docker.backup /usr/local/bin/hyperkit /usr/local/bin/hyperkit.backup /usr/local/bin/notary /usr/local/bin/notary.backup /usr/local/bin/vpnkit /usr/local/bin/vpnkit.backup /usr/local/opt/php56 /usr/local/opt/php72

iNickolay

Warning: You have MacPorts or Fink installed:
/opt/local/bin/port

This can cause trouble. You don’t have to uninstall them, but you may want to
temporarily move them out of the way, e.g.

У вас стоит так же MacPorts, рекомендуется выбрать что-то одно.

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python@2

запустите brew link python@2

Источник

Change PHP version on Mac with Brew

This post goes over how to change PHP version on macOS with Homebrew:

Prerequisites

Latest

Install the latest PHP version:

PHP 8.2.1 (cli) (built: Jan 12 2023 02:29:10) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.1, Copyright (c) Zend Technologies with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies 

Version

Error: [email protected] has been disabled because it is a versioned formula! 

Then find an unsupported version of PHP from shivammathur/php :

If you get a symlink error, then unlink php :

Update your PATH in ~/.zshrc :

echo 'export PATH /cdn-cgi/l/email-protection" data-cfemail="daaab2aa9aedf4ee">[email protected]/bin:$PATH"' >> ~/.zshrc echo 'export PATH /cdn-cgi/l/email-protection" data-cfemail="f5859d85b5c2dbc1">[email protected]/sbin:$PATH"' >> ~/.zshrc source ~/.zshrc 
echo 'export PATH /cdn-cgi/l/email-protection" data-cfemail="1161796151263f25">[email protected]/bin:$PATH"' >> ~/.bashrc echo 'export PATH /cdn-cgi/l/email-protection" data-cfemail="2d5d455d6d1a0319">[email protected]/sbin:$PATH"' >> ~/.bashrc source ~/.bashrc 
PHP 7.4.33 (cli) (built: Jan 21 2023 06:43:54) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies 

Revert

Change back to the latest PHP version:

Update your ~/.zshrc or ~/.bashrc :

-export PATH /cdn-cgi/l/email-protection" data-cfemail="a2d2cad2e2958c96">[email protected]/bin:$PATH" -export PATH /cdn-cgi/l/email-protection" data-cfemail="e1918991a1d6cfd5">[email protected]/sbin:$PATH" +export PATH="/opt/homebrew/opt/php/bin:$PATH" +export PATH="/opt/homebrew/opt/php/sbin:$PATH" 

Please support this site and join our Discord!

Источник

Оцените статью