3

Since Mac OS 10.8 had an old PHP version I had to install a never version of PHP. So I just compile PHP 5.4.13. Then I do a php -v on the terminal and it shows me that the new php version is running. But When I do a phpinfo from the browser it shows me the old PHP version which is PHP 5.3.x. This is even after creating a soft link to the new php build, /opt/local/lib/php(old one) -> /usr/bin/php(new one)

Any ideas how to fix this issue?

Thanu
  • 2,481
  • 8
  • 34
  • 53
  • Have you tried [MAMP](http://www.mamp.info/en/index.html)? I think this is the fastest solution to have an updated PHP version on OS X. – juan.obando Apr 04 '13 at 02:03
  • Yes I have MAMP, but i need to add different extensions to PHP, but I couldn't find a way to do it using MAMP – Thanu Apr 05 '13 at 04:15
  • Which extension do you need? What you can do is download the source code, compile it and add it to the PHP.ini file. That's what I usually do with PHP extensions on OS X (I don't use MAMP, I use the default PHP version that OS X provides). – juan.obando Apr 05 '13 at 14:42

3 Answers3

3

I just ran into the same issue, wanting to try Laravel which requires mcrypt.

In a nutshell, I had been using the built-in PHP 5.3.26 that came with Mountain Lion, then some months later after I'd gotten more familiar with homebrew, I used it to install a newer version of PHP.

brew update
brew upgrade
brew install php53 php53-mcrypt ...

I put

<?php phpinfo(); 

into ~/Sites/info.php then went to localhost/info.php to see my Apache+PHP config. On the page, I saw this, under Loaded Configuration File:

/private/etc/php.ini 

Then in Termninal, I ran this:

php -i | grep ini

which showed this output

Loaded Configuration File => /usr/local/etc/php/5.3/php.ini

Plus even more configs loaded as well ...

Additional .ini files parsed => /usr/local/etc/php/5.3/conf.d/ext-mcrypt.ini,
/usr/local/etc/php/5.3/conf.d/ext-xdebug.ini,
/usr/local/etc/php/5.3/conf.d/redis.ini

The problem I had was that mcrypt was loading in the php cli version, but my Laravel test page wouldn't load giving an mcrypt extension not found error [1]

I used a diffmerge tool [2] to compare the original Apple php.ini in /private/etc/ to the one homebrew installed in /usr/local/etc/php/5.3/ and found there to be significant differences! So check carefully before trying this:

What I did next was to backup

sudo mv /private/etc/php.ini /private/etc/php.ini.apple

Then symlink the php.ini to homebrew's instead

ln -s /usr/local/etc/php/5.3/php.ini /private/etc/php.ini 

Finally after reloading Apache

sudo apachectl restart

And mcrypt loaded, and now they're using a single config.

If you have another app on your localhost that breaks with the new config, just remove the symlink, and change it to the .apple version and restart Apache to revert back.

  1. Laravel requires the Mcrypt PHP extension
  2. https://sourcegear.com/diffmerge/
phpguru
  • 2,351
  • 2
  • 23
  • 33
1

This might be a good reference:

how do i install php 5.4 on Mac OS X Lion?

There are some detailed instructions on upgrading PHP to 5.4, and also notes on how MacPorts can make it pretty painless.

Community
  • 1
  • 1
jszobody
  • 28,495
  • 6
  • 61
  • 72
0

I'm running OS X 10.9. I updated PHP to v5.5.8 and found that Apache was correctly running the new version but the terminal was still running the old one. After hunting around for a solution for a while, I eventually thought, "I'll give it a restart."

Bingo! Terminal and Apache are running the same version of PHP.

Rob Tyler
  • 31
  • 2