You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Change php-cli version in Terminal

I'm one of the many people who appreciated the pre-install of PHP 5.3.x with my new mac but needed to use 5.2.x for my local development environment. I performed one of the prescribed rollback methods and when using PHP through apache it works great. A phpinfo() shows: PHP Version 5.2.10.

However, when using PHP through the command line (which also includes cron jobs I've set up, etc.) it still thinks it is 5.3.x. A php -v from the command line shows: PHP 5.3.2 (cli).

I need these to be in sync for a variety of reasons, including using pear (which automatically builds extensions for 5.3.x instead of 5.2.x) and cronjobs, etc.

iMac, Mac OS X (10.6.4)

Posted on Oct 7, 2010 1:31 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 7, 2010 8:34 PM

jeremycellis wrote:
when using PHP through the command line (which also includes cron jobs I've set up, etc.) it still thinks it is 5.3.x. A php -v from the command line shows: PHP 5.3.2 (cli).


Assuming your default shell is bash, create a file named .bash_profile in your home directory and put these lines in it, where "path/to/php_5.3.x" is replaced by the appropriate path:

PATH=/path/to/php_5.3.x:$PATH
export PATH

Then make it executable with this command:

chmod u+x .bash_profile
8 replies
Question marked as Top-ranking reply

Oct 7, 2010 8:34 PM in response to jeremycellis

jeremycellis wrote:
when using PHP through the command line (which also includes cron jobs I've set up, etc.) it still thinks it is 5.3.x. A php -v from the command line shows: PHP 5.3.2 (cli).


Assuming your default shell is bash, create a file named .bash_profile in your home directory and put these lines in it, where "path/to/php_5.3.x" is replaced by the appropriate path:

PATH=/path/to/php_5.3.x:$PATH
export PATH

Then make it executable with this command:

chmod u+x .bash_profile

Oct 8, 2010 6:13 AM in response to William-Boyd-Jr

Thank you for your suggestion. I tried it but I'm still experiencing the problem. Also, while researching what my php path was (I assume you meant path to php_5.2.x, because that is what I'm trying to have installed everywhere) I discovered that both apache and CLI might be using the same path but are pulling different versions. This is very confusing.

When looking at the Environment section of phpinfo in a web page I see:

PATH /usr/bin:/bin:/usr/sbin:/sbin

When I do "which php" from the command line I see:

/usr/bin/php

So this is what I put in that ~/.bash_profile (I had already tried putting this in the preëxisting file ~/.profile) was:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
export PATH

However, after doing this (and restarting terminal to make sure that the PATH variable was reinitialized) "php -v" still reports:

PHP 5.3.2 (cli) (built: Aug 7 2010 00:04:41)

Any other suggestions?

Oct 8, 2010 7:43 AM in response to jeremycellis

jeremycellis wrote:
So this is what I put in that ~/.bash_profile (I had already tried putting this in the preëxisting file ~/.profile) was:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
export PATH


But the original PATH is just empty here. You aren't doing anything. You need to add the path to PHP 5.2 and it needs to come before any system paths. That way, when you type php on the command line, it will find PHP 5.2 and stop looking.

Apache runs as its own process and doesn't use your path. To use PHP 5.2 inside Apache, you had to have given it the exact path to Apache 5.2.

Oct 8, 2010 9:12 AM in response to etresoft

Hrmm. I see what you're saying. Here's the worry: I don't think I actually installed php 5.2.x for apache. I just found the instructions I used and in the end we built an .so and just put it in apache's libexec:

/usr/libexec/apache2/libphp5.so

So I don't think I actually have a php 5.2.x binary. Is it possible to actually downgrade the php 5.3.x CLI install? I wish macs came with apt-get or a similar package manager because I think this would be easier if so.

Thanks for your insight!

Oct 8, 2010 11:25 AM in response to Tony T1

Tony T1 wrote:
Does .bash_profile net to be executable?
Mine has always been -rw-r--r--@


I'm not sure that's an absolute requirement. I just though it would be prudent to give any script file executable permissions. The "man" page for bash says that it "reads and executes commands" from .bash_profile, so perhaps execute permissions aren't needed in that case.

Oct 8, 2010 11:47 AM in response to jeremycellis

jeremycellis wrote:
So I don't think I actually have a php 5.2.x binary. Is it possible to actually downgrade the php 5.3.x CLI install?


You don't want to change the system version. You can certainly download the PHP source, compile it, and install it into /usr/local and it should run fine. Even better, since you only need this for the command line client, you don't have to worry about having a matching Apache. Just make sure that your full 5.2 PHP completely matches your .so version in terms of build settings and libraries.

I wish macs came with apt-get or a similar package manager because I think this would be easier if so.


That is by design. Apple doesn't want to have to deal with a moving target OS when updating. There is no "Linux operating system" - singular. Each individual Linux machine is a unique OS.

If you want there are a number of 3rd party package managers for MacOS X. I think they are useful only in some very specific circumstances. If you jump to them without knowing all of the side effects, you could get burned. If you do the required research and have good knowledge of MacOS X and how the 3rd party package manager works, you can use it effectively. If you don't pay attention, you could wind up unable to build or run even the simplest open-source projects.

Change php-cli version in Terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.