osx - How to enable the php 5.4.x version on Mountain Lion
2014-03
I have installed the latest php version on my mountain lion system using these instructions (http://mac.tutsplus.com/tutorials/server/upgrading-the-native-php-installation-on-os-x-mountain-lion/). I even put /usr/local/bin first in my path variable, so when I run php -v at the command line I get php v5.4.x The problem is that when I run a simple script (with the phpinfo() function inside) the page tells me that I am running the old 5.3.x php version that comes pre-installed with mac os mountain lion. I even tried to restart apache, but the problem remains. Any ideas on this one? Thank you.
That tutorial you followed is a bit dangerous. It seems it tells you to replace the default X11 with a new one, which is a really bad unnecessary idea.
Where did you change your local variable? If you used .profile or .bash_profile it is only valid for your user. To affect all users you need to change /etc/paths. But I don't think it has anything to do with the PATH var.
Regarding your question, this means Apache is not loading the correct PHP module. (libphp5.so)
Check the creation date of /usr/libexec/apache2/libphp5.so
If it predates your build time, then it was not replaced.
First turn off Apache (either in Settings or by running
sudo apachectl stop
in the console).Then rename
/usr/libexec/apache2/libphp5.so
-->sudo mv /usr/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.so.bak
Then go to the source dir and run
make install
. (if you have deleted the directory, the makefile or ranmake clean
you will need to start the compilation process again)Then check if
libphp5.so
exists at/usr/libexec/apache2/
. If it does not exist, then your compilation parameters are wrong. If it does, go to step 5.Rename the new
/usr/libexec/apache2/libphp5.so
to libphp5.4.8.so (or the version you're installing).Backup httpd.conf -->
sudo cp /usr/libexec/apache2/httpd.conf /usr/libexec/apache2/httpd.conf.bak
Edit httpd.conf -->
sudo nano /usr/libexec/apache2/httpd.conf
and changeLoadModule php5_module libexec/apache2/libphp5.so
toLoadModule php5_module libexec/apache2/libphp5.4.8.so
Put the old libphp5.so back. -->
sudo mv /usr/libexec/apache2/libphp5.so.bak /usr/libexec/apache2/libphp5.so
Restart apache (in settings or with
sudo apachectl start
)
Let me know if it worked for you
I downloaded Macports and run a command I get online, which would install php 5.4. It took a while, but seemed to work successfully. I then copied the php.ini.development and renamed it php.ini like suggested my Mac Ports, however when I type php -v in terminal I still see 5.3
What steps have I missed, what do I need to do to get it to use the php 5.4 :S
Macports should updated your $PATH automatically. You can verify this by typing the following in your terminal window
~> which php
/opt/local/bin/php
If the path returned from which php
is /usr/bin/php
you'll need to updated your terminal session, by resetting system path
~> source ~/.profile
Try the which php
again. If /usr/bin/php
is still returned, add the following line to ~/.profile
file
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
to invoke your macports php 5.4 install from the command line, use php54, e.g.:
php54 -v