Install php 7 on mac with Homebrew - php

Hi just got a new fresh mac and I want to use the last version of php7.
So I have instal php 7.1 with homebrew successfully. But the php -v command show that I have the 5.6 version witch is the default version installed on mac.
How can I target the new version of php installed with homebrew.
I have followed this tutorial to do it : https://developerjack.com/blog/2016/installing-php71-with-homebrew/

You need to set your PATH environment variable to have /usr/local/bin at the start because that is where homebrew puts your installed binaries:
export PATH=/usr/local/bin:$PATH
Put that in your login profile too, so it works on future logins.
You may also need to rehash with:
hash -r
which causes your shell to forget where commands are, so it has to search afresh.

Related

PHP CLI on Apple M1 using Homebrew

I've followed this guide to install Homebrew on an M1 based Mac.
After that I ran
brew install php#7.4
which installed PHP successfully.
If I now run
brew upgrade php
I get
Error: php not installed
What I like to achieve is to update the PHP that comes shipped with macOS, which is 7.3.22 when I run php -v.
How can I update PHP using Homebrew? I understood that I need to put something in my PATH to point to the newer PHP version? Given this is a new machine I actually don't have a .bash_profile file, only a .zshrc (I'm using ZSH, I assume that this file will be used and that I don't need a .bash_profile?)
It's not advisable to upgrade the system-provided PHP, but it's also not necessary.
brew link can be used to decide which PHP is utilized. brew link php#7.4 should do the trick; this can be also used to switch PHP versions around, i.e. brew link php#8.0 will switch you over to that while leaving both versions installed and available directly.

How to install and use PHP on macOS via brew

it seems like a little bit stupid question, but Google for one hour and cannot find it:
How to install php on macOS via brew and use in in shell.
Install is simple (if you have brew already installed):
brew install php
But after installation, when i use php -v i still see default php on mac os and not the brew's one. Shoud I Add brew php binary into PATH, bash profile, or what?
Thank you!
homebrew creates symbolic links in /usr/local/bin to pretty much every binary it installs. So the answer to your question is to add that to your path in your login profile. That will probably be $HOME/.profile and you can add a line like:
export PATH=/usr/local/bin:$PATH
Then it will be set each time you login or open a new Terminal.
So in my case, the trouble was with some access permissions on specific folders on my Mac OS, so just sharing what I learned: if it's not working, carefully examile log / error feed, there can be a hint for you!
On April 1, 2018 Homebrew discontinued the Homebrew/php tap and went with a core install approach, which means many of the extensions now must be installed with PECL. I have written a two part blog series to help with installing Apache and PHP w/ PECL on later versions of MacOS. You can find it at the link below, I hope it helps!
https://medium.com/#crmcmullen/how-to-install-php-on-macos-10-13-high-sierra-and-10-14-mojave-using-homebrew-and-pecl-ef2276db3d62
Step 1: Install Homebrew
The first step is to install Homebrew and this is a tool (package manager for macOS) that will allow us to install easily PHP and basically any other package/tools.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install PHP
To install PHP we can use the command below. The first command will automatically install the latest version of PHP which is at the current moment of writing this post version 8.
brew install php
If other versions may be preferred we can specify the PHP version and the code will look like the following.
brew install php#7.4
Step 3: The php.ini Config
The default PHP configuration should be sufficient to get started but if there are any other configurations, we can change them through the php.ini located on this path. Do note the PHP version number which in this case is version 8.
/usr/local/etc/php/8.1/php.ini
Step 4: Check if PHP is running
To check if PHP is already running we can make use of the brew services command. First, we can list the services that we have installed.
brew services list
If PHP is not started we can then run the command below to start the service in the background.
brew services start php#8.1
Step 5: Checking PHP Version
Lastly to check the PHP version do run:
php -v
By now you will have PHP running on the background process and every time you logged in to the system it will start by default. Thanks for reading and have a good try.

php --version Alias setting goes wrong on Mac

I am developing a PHP project. I am using Mac OS X now. To be honest, this is the first time developing a PHP project using Mac. I am a Windows. I installed PHP using Brew by running the following command.
brew install php
It gave me the php latest version, 7+. For my project, I need to use php version 5.6. So, I installed another PHP by running this command.
brew install php56
Up until this point when I enter "php --version" in the terminal, it is showing that I am using php version 7+. I found some solution to change php version and so I used one of them and run this command.
alias php='/usr/local/etc/php/5.6/php'
After running that command, when I type in "php --version" in the terminal, it is showing this error.
-bash: /usr/local/etc/php/5.6/php: No such file or directory
Now, I cannot use any PHP on my Mac right now. How can I fix that?

Change the PHP version for Plesk to PHP 7

I'm running Plesk Version 17.0.17 Update #16 on Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux
My problem is that I cant figure out how to update the global PHP version to 7.1 through Plesk
I need to do this as it is required by a package I am trying to install with Composer.
I cannot remove it because it says that "Plesk is using the old version to run" and I cant seem to change the version that Plesk uses. I can only set it for individual websites and I'm not interested in running more than one PHP version.
I have already installed the new version and I am able to run it when I create a symbolic link like this:
ln -s /opt/plesk/php/7.1/bin/php /usr/bin/php
When I do this everything works fine and the problem only occurs when Plesk updates it and overwrites the path causing me to have to do it again.
I cant just remove the old version through Plesk as it says it conflicts with Plesk itself as it uses it to run.
Summary:
I want Plesk to run PHP version 7.1 and remove the old version completely.
How can I do this?
Use this:
apt-get update; apt-get install php{X};
where {X} = version ex. 5
For PHP 5.5, PHP 5.6 and PHP 7.0:
apt-get update; apt-get install php{X};
Then update the package lists and perform the upgrade:
sudo apt-get update
Well you should make sure that no website is using the old php version. After that you should be able to remove the old php version from Plesk. You should not have to create a symbolic link manually. That can cause problems with Plesk.
Maybe better to said composer use specific PHP binary?
For example you can just add the following line into the .bashrc file from your user folder:
export PATH=/opt/plesk/php/7.1/bin:$PATH
Or
echo 'PATH=/opt/plesk/php/7.1/bin:$PATH' >> ~/.bashrc
To verify you have to relogin/recreate bash session and check $PATH variable:
echo $PATH
/opt/plesk/php/7.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

PHP 7.0 installed, but version doesn't change

I'm trying to install PHP 7.0, which works. But when I check my php -v in the cmd, it still says 5.5.36.
I tried it via php-liip, homebrew, install manually and via cmd. Nothing works. When I change version of PHP in MAMP (which I work with to try and install composer in a directory, that I need PHP 5.6 or higher for) i still doesn't matter.
The PHP 5.5 you're seeing was installed by Apple and is a default on your computer. It was installed at /usr/bin/php.
All of the installers you've used will not overwrite Apple's default installation - they will instead opt to create their own directories or use /usr/local/bin/ instead (thus the PHP interrupter would be installed at /usr/local/bin/php). In other words, you almost certainly have multiple php's ready to use right now. The next thing you need to do is tell bash (the default terminal/cmd on a Mac) to use the newly installed PHP interrupter.
When you run $ php on your command line, bash checks for an executable file on each of paths stored in the PATH environment variable. Once it finds one, it decides that that executable is the one you're looking for and runs that program. As of now, it's finding Apple's PHP 5.5 before it finds your fresh install of PHP 7.0 - assuming it finds PHP 7.0 at all.
You can fix this by updating PATH to check wherever PHP 7 is installed first. Instructions to do so can be found on SuperUser.StackExchange:
How should I set the PATH variable on my Mac so the Homebrew-installed tools are found?
To change php version in Ubuntu, try to use this comand
sudo update-alternatives --config php
and then select version what you need

Categories