How do I specify which install of Apache I want my Mac to use?

All my problems stemmed from trying to get mcrypt for PHP installed. Last night I gave in and followed a tutorial of how to do a totally fresh apache2 and php5.3.3 install. I did this using macports

Sadly, that didn't enable mcrypt for me last night, although I was pretty pleased that I got 5.3.3 running :)

The problem is that I have woken up this morning to find that my php version is back down to 5.3.1 which can only mean that OS X has reverted to my original Apache and PHP.

How to I tell OS X to use the software I installed via macports?

(And then I will ask a new question of how to enable mcrypt)

n.b. I can get the macports install to load by stopping the current web sharing in system prefs then this in terminal

 sudo /opt/local/apache2/bin/apachectl -k restart
4

5 Answers

It's not so much your version of Apache/PHP have been reverted - it's just the wrong version is loaded.

If you have Mac OS X's Web Sharing enabled it will auto enable the version of Apache and PHP Apple provides using the LaunchDaemon org.apache.httpd.plist in /System/Library/LaunchDaemons (this will override MacPorts version). You'll want to disable this by either turning off Web Sharing in the Sharing Preference Pane or by running sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist.

When you installed Apache for MacPorts it installed a LaunchDaemon into /Library/LaunchDaemons which if enabled will start up the MacPorts version of Apache automatically. To enable it run sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist and you're off to the races.

If you're running apachectl to restart - make sure you've selected the right version. You may need to alter your $PATH to have /opt/local/apache2/bin before /usr/sbin

As for what version of PHP is being used; on the command line this will depend on your $PATH while for Apache it's entirely in your configuration of where the libphp5 module is. (/etc/apache2/ for the built in version, /opt/local/apache2/conf for the version MacPorts installed)

Apple.SE

As Ayaz suggested, you need to edit the plist. The proper path should be /System/Library/LaunchDaemons/org.apache.httpd.plist.

To make sure that you run the proper apachectl, modify the PATH environment variable in your shell startup script (e.g. ~/.bash_profile, ~/.zshrc or whatever) so that /opt/local/apache2/bin comes before /usr/sbin. In bash the syntax to prepend the macports apache dir is:

export PATH=/usr/local/apache2/bin:$PATH
2

Another fix is to symlink apachectl to /usr/sbin/apachectl

$ su -
# mv /usr/sbin/apachectl /usr/sbin/apachectl.mac_version
# ln -s /opt/local/apache2/bin/apachectl /usr/sbin/apachectl

To fix your Apache problem, you can take a look at /Library/LaunchDaemons/org.apache.httpd.plist and edit it to taste.

2

Hmm... You're aware of the Personal Web Sharing you can activate in System Preferences -> Sharing. Are you trying to make that checkbox activate your custom build of Apache instead of the bundled one?

I don't know if this is possible, but I wouldn't recommend it. It's a better idea to just de-activate the basic build and use your custom one separately.

You've already got step 1, which is to turn off the default server in System Preferences. To cause the custom build to load at boot, investigate the /Library/LaunchDaemons/org.apache.httpd.plist file that you mentioned. See $man launchctl for more info about working with these files, and also this handy piece of software called Lingon.

With those tools (and maybe $ps -ax|grep httpd) you should be able to ensure that the running Apache build is the custom MacPorts install.

Ooh, that makes me think of something else: apachectl isn't the server, it's just a utility you use to control the server, which is httpd. Maybe the MacPorts apachectl is starting the bundled httpd? Or perhaps the MacPorts httpd is using the bundled PHP...

Personally, my approach to this would just be to alter the installed apache build by upgrading PHP as required, but hopefully you can use some of this to continue troubleshooting.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like