I am running OSX El Capitan which comes (if I am not wrong) with PHP 5.5.
So I updated my PHP version using this Terminal command:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
And from the docs :
php-osx doesn't overwrite the php binaries installed by Apple, but
installs everything in /usr/local/php5. The new php binary is
therefore in /usr/local/php5/bin/php.
You can also adjust your PATH do include that directory, eg. write
into your ~/.profile file the following
So I did what have been suggested, but still, my php version (shown by php -v) is 5.5 rather than 5.6.
What I am missing here?
After editing ~/.profile or ~/.bash_profile you either have to restart your terminal or do source ~/.profile so the changes take effect immediately.
Related
I was given a macbook 2019 for work which has catalina 10.15.6 ... the default PHP is 7.3 .. can someone show me the step by step on how to avoid this default PHP version?. I found some tutorials online using homebrew in order to use multiple versions of PHP. but then am a bit skeptical to install the homebrew php yet, coz I scare it will conflict with the default PHP with the OSX . any idea ?
Homebrew manages the installation for you and updates the necessary paths.
With homebrew installed you can just run the following command to install php7.4
brew update
brew install php#7.4
Check your PHP version now
php -v
If it still prints out the old version, update your path:
echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.4/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Alternative one-line install
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.4
To do that, Within the terminal, Fire this command:
which php
This should output the path to the default PHP install which comes preinstalled by Mac OS X, by default it has to be
Now, We just need to swap this over to the PHP that is installed with MAMP, which is located at /Applications/Xampp/bin/php/php7.3/bin for example
Within the Terminal, run vim ~/.bash_profile
Type i and then paste the following at the top of the file:
export PATH=/Applications/Xampp/bin/php/php7.3/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 was 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).
source : https://gist.github.com/irazasyed/5987693
When I run php -v in cli I get the exact php version 7, but when i run exec("php -v") in web server I get php 5.5 even thought in phpinfo i see that I am runing php 7?! Any idea why I get the older version of PHP?
running exec you get the CLI version of PHP
you probably installed php5.5 as CLI and php7 as apache module
If you use CentOs, add this line at the end of /etc/bashrc (or ~/.profile for Ubuntu)
export PATH=$PATH:/your/path/to/php7/bin
Then run:
source /etc/bashrc
P/s It may be better if you edit /etc/profile.d. Take a look both of them.
UPDATE
In MacOS, let edit ~/.bash_profile (create it if it does not exist) with the same content.
I'm trying to install a package via Composer that requires PHP 5.6.0. My MAC is running PHP 5.5.31 but MAMP runs PHP 7.0. The package will not download because of the PHP requirement is not met since it's looking at my macOS version, not the version I actually use with MAMP. How can I get around this?
MAMP's PHP is located here:
/Applications/MAMP/bin/php/php7x.x/bin/
The default OSX PHP is located in
/usr/bin/php
/usr/bin is in PATH variable by default.
When you want OSX to use the MAMP version instead, you need to add /Applications/MAMP/bin/php/php7.x.x/bin/ to your PATH variable.
Simply edit ~/.bash_profile in your terminal and type
vim ~/.bash_profile
if you cannot find ~/.bash_profile then you have to create one with
touch ~/.bash_profile
and add the following line to end of the file:
export PATH=/Applications/MAMP/bin/php/php7.x.x/bin/:$PATH
You just have to look at the correct version of your MAMP's php and replace the x.x from the example above with that correct number. (e.g. 7.0.2)
If that went fine, relaunch your terminal.app and do php -vagain. Now you have to see the new version.
After that try to install the composer package again! Good luck
Help source: how-to-override-the-path-of-php-to-use-the-mamp-path
This was easy to me:
First backup system php sudo mv /usr/bin/php /usr/bin/~php
Then crate a symbolic link from /Applications/MAMP/bin/php/phpX.x.x/bin/php to /usr/bin/php using this: sudo ln -s /Applications/MAMP/bin/php/phpX.x.x/bin/php /usr/bin/php. Now you have your mamp php (with its config) available everywhere.
If you type 'which php' into Terminal it'll show you where it's looking for PHP. I'm guessing there are 2 different versions of PHP installed into different directories. In which case you might be able to use a bash script to set the correct path to the PHP version you want?
I've had similar issues on my Mac where I've installed software like git, but it's looking elsewhere for it (e.g. the version bundled with Xcode)
I am trying to update our PHP version (Current: 5.3.15) to the latest 5.4.16 i used this link for my Lion Mac PHP Install and all worked well.
So then i went onto our Mountain Lion Mac Server and did the same but its still showing via phpinfo page as 5.3.15 same if i do a php -v via the terminal.
i understand that this install places it into the usr/local area whereas i believe the server is getting the php etc from /usr/bin/php and not the local.
So how ca i update the main php scripting and not the local or link up the server to use the local updated version?
Replace the default location with a link to the new version:
sudo mv /usr/bin/php /usr/bin/php.orig
sudo ln -s /usr/local/bin/php /usr/bin/php
What does your $PATH look like on the command line? You need the path to your PHP binary in /usr/local to come before the path to the system's default installation of PHP.
One alternative would be to install PHP in the same place as the default version, thus overwriting it.
I'd be wary of only making a symbolic link from /usr/bin/php to your local version of PHP. This might work for executing PHP scripts, but when it comes time to compile custom extensions and what not, it could confuse phpize and mess up your build process.
Need to downgrade php to 5.2.x, so I followed this tutorial:
http://andreys.info/blog/2010-03-25/compile-php-5-2-on-osx-10-6-snow-leopard#comment-631
I'm on snow leopard 10.6.4, with xcode installed.
So I compiled php5.2.x and completed the tutorial. phpinfo() loaded within the browser at htp://localhost says 5.2.x, Great!! But, Terminal command "php --version" says 5.3.x ??
While compiling/installing php5.2.x, the new module file replaced the php5.3.x module here:
/usr/libexec/apache2/libphp5.so
So where is Terminal getting 5.3.x from?
Do I have two php versions being loaded?
Should I even care?
For a more direct solution to the problem:
Rename the OLD version of PHP
sudo mv /usr/bin/php /usr/bin/php5424
Create a Symbolic link for your new version of php so it can live in /usr/bin
sudo ln -s /usr/local/php5/bin/php /usr/bin/php
Check using which php. This should tell you which is being used.
Yes, looks like you have two installed at different locations.
Yes, mind what's being used where. Having multiple versions is absolutely valid (at least on a development or testing system) but you always should be aware of the versions being used.