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.
Related
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)
When I look at a phpinfo page on my ubuntu server it says the php version is 5.5.9. But when I do a php -i or -v from command line it says php version 5.3.3 and it doesn't list the modules I've installed in 5.5.9.
I guess I have two versions running. How do I get rid of 5.3.3 so command line reports 5.5.9?
Do a locate bin/php to see all files on your system that might possibly be PHP binaries. Then do a which php to see which one would be executed. I have one in /usr/bin/php and a self-compiled version in /usr/local/bin/php53, of varying versions.
To run things on the command line with the other version, you can specify the full path of PHP thus: /usr/local/bin/php /command/to/run and it will run that. Or, add the path to the new version to your system path at the start, and this will "see" the new PHP version before the old one.
If you are running this thing from cron, I tend to recommend using the full path to the PHP interpreter anyway - I think it's a good habit, in case the available paths are different between your environment and the cron environment.
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.
i am trying to setup a new symfony framework project on ubuntu by following the documentation. But all the commands mentioned in the docs starting with 'php' give out the following error.
The program 'php' is currently not installed. You can install it by typing:
sudo apt-get install php5-cli
bash: php: command not found.
But php is installed and running on the system! How do i get past this error ?
Thanks in advance.
There are several different PHP packages; probably the one that is installed is the PHP module for Apache, not the command-line (CLI) version invoked as php.
Just run the command like it says, and you should be fine.
Is php on your path? (does it start if you just type in 'php' at the prompt or do you need to specify a path?)
If so, then its possible that the path is hardcoded to look elsewhere for your PHP executable. Try grepping the scripts to see where its looking.
If php is NOT on your path then try adding it, e.g. if php is in /usr/local/bin (and /usr/local/bin is not currently on your path)
export PATH=$PATH:/usr/local/bin
HTH
C.