osx - Fail to load php module macports
2014-03
I'm trying to install php
module via macports
. I have them installed, so I run
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" mod_php54.so
Then I'll ensure myself, it's loaded, I see in httpd.conf
:
LoadModule php5_module modules/mod_php54.so
Then I can see php54.so
file exists in modules
directory.
Then I restart the apache with below command:
sudo /opt/local/apache2/bin/apachectl -k restart
But when I send query to load modules with apachectl -M
command, I can't see any php5
entry. Also, .php
files aren't interpreted now, I can only see the sources.
What was my mistake?
I wrote comprehensive instructions here, but the main thing is that you need to make further edits to httpd.conf to tell it how to interpret .php
files and to use index.php
.
The key lines are
AddHandler application/x-httpd-php .php
and
DirectoryIndex index.html index.php
There's a lot more at the referenced link, along with long-winded explanations of every step.
I just upgraded my MBP to Snow Leopard (OS X 10.6), which took PHP to 5.3
This is great, except I use my MBP as my development machine and I use a lot of PHP libs and frameworks (namely CakePHP 1.2) which are not compatible at the moment with PHP 5.3. CakePHP in particular does not have a stable version for PHP 5.3 so its not a matter of upgrading the framework (and the production servers are under PHP 5.2 anyway.)
Is there a way to install PHP 5.2.9 alongside PHP 5.3 and then using httpd.conf or .htaccess tell Apache which version of PHP to use for a particular directory?
Alternatively is there a way to do this with MacPorts?
Thanks!
Mark Story has written a great article on how to achieve this. He is a CakePHP core developer, and uses this setup for work and cakephp development.
http://mark-story.com/posts/view/maintaining-two-versions-of-php-with-macports
I suggest downloading the PHP distribution you would like as source, and then set ./configure
parameter options (see ./configure --help
) so the software is installed either in a unique location or with the version number appended to the name. This way when you run make install
the PHP 5.3 install is not overwritten. Finally setup a separate suffix mapping in Apache which routes to version you'd like, or override the default PHP mapping for the VirtualHost
or Directory
stanza where your scripts are located.
I am maintaining some build scripts as part of the Homebrew project that will let you do just that (at least the installation part) very easily. I blogged about it - http://boztek.net/blog/2009/10/07/install-lamp-stack-source-mac-os-x-106-snow-leopard-using-homebrew
Here is another suggestion: http://cuadradevelopment.com/blog/26/multiple-php-versions-with-apache-using-fastcgi-on-os-x