OSX El Capitan Permanently change PHP version - php

I have installed PHP 7.0 from here http://php-osx.liip.ch/ and followed instructions to add the new php to my $PATH but in a new terminal window php -v still shows the old default version.
The new version is used if I source .profile or source .bash_profile (tried both)
I have even added the new PHP path to my .bashrc but still no luck.
How can I get my mac to always use the new version of PHP by default?
Note:
Symink not an option as I'm on El Capitan.
~/.bashrc:
export PATH=/usr/local/php5/bin:$PATH
export PATH=/usr/local/bin:$PATH
export PATH=$HOME/.composer/vendor/bin:$PATH

You should use ~/.bash_profile instead of ~/.bashrc file on Mac.
If source ~/.bash_profile can solve the problem, that means the file is not sourced when you open a new terminal. If you are using zsh, you should add source ~/.bash_profile to your ~/.zshrc file.
However, brew is a better option.

Related

How to use MAMP PHP on macOS big Sur

I updated the to MacOS Big Sur and then switched to MAMP Pro 6.3 from MAMP 4.x.
which php commands results the
usr/php/bin/
I updated the path using following.
vim ~/.bash_profile
export PATH=/Applications/MAMP/bin/php/php7.4.12/bin:$PATH export
PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
Press esc and then
:wq
source ~/.bash_profile
Now when I do which php it shows MAMP's php7.4.12 but if close and re-open the terminal, it again says
usr/php/bin
Btw, PHP 7.4.12 is set as Default version in MAMP Pro from PHP settings in MAMP Pro.
Versoins
macOS Big Sur version 11.1
MAMAP 6.3
Since you're using MAMP PRO 6.x you can enable Activate command line shortcuts for the selected PHP version, pear & pecl within the MAMP PHP settings. This will add aliases to your .profile file. If this does not work right away find the .zshrc file if you have it and add source ~/.profile; within it.
Open a terminal.
edit this file:
nano .zshrc
add these two lines:
export MAMP_PHP=/Applications/MAMP/bin/php/php7.4.12/bin
export PATH="$MAMP_PHP:$PATH"
NOTE: if you want another version, replace php7.4.12 for the version you want.
Save the changes o file and then close the terminal and reopen it.
Now run "which php" and you will see the desire version of Php.

Update PHP Version of XAMPP on macOS

I’m fairly new to mac and try to learn some things by playing around.
Currently I’m trying to get an new PHP version on XAMPP running on my macbook. I've read different threads and tutorials for this (e.g. Is there way to use two PHP versions in XAMPP?) but I'm stuck. Here is what I got:
macOS Mojave with XAMPP 5.6.31-0 with PHP version 5.6.31
$ which PHP says /usr/bin/php
$ PHP -v says 7.1.19
So this means macOS has PHP7 out of the box?
So I tried to make XAMPP load PHP7 from the mac path by editing the /xamppfiles/etc/httpd.conf by:
<IfDefine JUSTTOMAKEAPXSHAPPY>
#LoadModule php4_module modules/libphp4.so
#LoadModule php5_module modules/libphp5.so
LoadModule php7_module /usr/libexec/apache2/libphp7.so
</IfDefine>
But after restarting the apache phpinfo() stays hat 5.6.31. Even if I delete the PHP 7 + 5 lines and expect PHP4 to be loaded it stays at 5.
So what am I doing wrong?
Disclaimer: I know it would be the easiest way to download a newer XAMPP version or use the build in apache from mac. But for learning reasons I would like to get this done.
The best way is install Homebrew, and then in your terminal, write this:
$ brew upgrade php // upgrade php formula
$ brew install php#7.2
$ brew link php#7.2 // create an alias to this keg-only version; see comments output during installation
$ echo 'export PATH="/usr/local/opt/php#7.2/bin:$PATH"' >> ~/.bash_profile // add the alias to your path; see comments output during installation
$ source ~/.bash_profile // reload .bash_profile to use the new settings immediately
greetings!
After a lot of research and implementation, the best one that works for me without using the homebrew command this
go to this link https://php-osx.liip.ch/#install
copy the url of the php version you want to install
paste it inside your terminal, it will require for your password, kindly provide it
After installation is complete, add the default path of php to your bash profile by doing this export PATH=/usr/local/php5/bin:$PATH you can simply copy and paste, after check your php version. i believe it will have change.
Go to your localhost PHPmyAdmin, click on "Export" and export all the databases as one.
Go to your XAMPP folder, go to the "Htdocs" folder and copy all your project files to a different folder outside the XAMPP folder.
Go to the XAMPP folder and click the uninstall icon. It will remove xampp. I noticed it leaves your database and htdocs folder intact. Steps 1 and 2 were just a precaution.
Go to and download the latest XAMPP that has the PHP version you want. You can find it at https://www.apachefriends.org/download.html
Click on the downloaded file and install it. It will complete and you will have the PHP version you want install and your Htdocs and database will be intact. In case your database and htdocs is not there, simply recopy the project files you copied and import the database you exported.

How to check php version in MacOS sierra?

I have mac os sierra machine. When I start a php project in vs code, I get the following warning
language server needs php 7, and the version found is 5.6.27.
So I used homebrew to upgrade to version 7 and confirmed it from the terminal. I am also running mamp which show version 7.
But in the terminal of vs code the php version is still 5.6.27. So I am bit confused?
I changed the value of php.validate.executablepath in settings.json in vs code from usr/bin/php to usr/local/bin/php, but still vs code terminal showing the older version (viz. 5.6.27)
This is because VM Code still checking /usr/bin/php directory which is php5
You have to configure the path to the PHP executable in the user settings file.
Follow the following steps to change it
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
If the problem remains same, then add the path to PHP7 to your environment variables, run where php and php --version to verify. To add path in your macos sierra do the following:
Within the Terminal, run vim ~/.bash_profile
Type i and then paste the following at the top of the file:
export PATH=/user/local/bin:$PATH
Hit ESC, Type :wq, and hit Enter.
In Terminal run source ~/.bash_profile
In Terminal, type in which php again and look for the updated string.
If everything went successful, it should output the new path to MAMP PHP install.
In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short)
To find out what version you're using, upload a php file to your server containing the following code...
<?php
phpinfo();
?>
It will tell you at the top of the page.

trying to use MAMP's PHP, but `which php` always returns native OSX version?

I want to use MAMP on my OSX box as I am learning Laravel development.
I have added the following line to ~/.bash_profile:
export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
I restarted terminal, restarted MAMP, but when I run which php the result is still /usr/bin/php.
Any tips? Thanks!
Your path can be changed, while the default OS response to the which command remains unchanged.
Example:
which php
/usr/bin/php
php
bash: Applications/MAMP/bin/php: No such file or directory
Run this command:
echo "$PATH"
[NOT a complete answer]

Upgraded to PHP 5.5 on mac - having to load PATH into terminal each time

Last night I upgraded to PHP 5.5.3 using http://php-osx.liip.ch/ on my new Macbook. I have OS X v10.8.5
Each time on launch terminal or iTerm, I have to put PATH=/usr/local/php5/bin:$PATH into the terminal to get it to properly set the path. Why?
I did put the same path into ~/.bash_profile and ~/.profile.
Running phpinfo in the browser, without touching terminal, does show PHP 5.5.3.
Open terminal and type:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
5.5 is a PHP version (if you want install a specific version), then check if it works:
php -v
In ~/.bash_profile add export PATH=/usr/local/php5/bin:$PATH
My ~/.profile is currently empty.
Now in terminal do
source ~/.bash_profile
Try php -v.
I've restarted terminal a few times with the correct results. Both phpinfo() and terminal php -v show PHP 5.5.4.
Hope this helps.

Categories