Ditching XAMPP on OS X – Part 2 – MySQL

When trying to upgrade php in XAMPP, I ran into the problem faced when you use an all in one solution for your LAMPP development, i.e.. you’re stuck with whatever versions have been compiled in. So instead, I decided to take advantage of the built in Apache thats ships with the MacBook Pro. Now, we’re going to set up MySQL. Head over to their website and download the 64 bit package. Mount the disk image and run the installer. There’s also a preference pane installer, which handily starts and stops mysqld for you.

Okay, so open a terminal, and first off we’ll get a sequel dump of all your current databases from XAMPP:

cd /Applications/XAMPP/xamppfiles/bin
./mysqldump -u root -p --all-databases > /Users/delboy1978uk/Desktop/all_dbs.sql

You can now import that to your new MySQL server. It’s nice to be able to call mysql from any folder, so we’ll symlink it:

sudo ln -s /usr/local/mysql/mysql /usr/bin/mysql

You can now run mysql like so:

mysql -u root

Sudo nano /etc/php.ini, PDO is enabled by default on mac, but we need to set where the MySQL socket is:


Restart Apache, and we’re good to go!

sudo apachectl restart

Ditching XAMPP on OS X – Part 1 – Apache & PHP

No sooner did I say that I was happy with XAMPP, when suddenly it was useless and no good to me. Yes it was nice and easy to install, but heres the catch – all that goodness turns rotten when you want to upgrade a part of it.

If you’ve been reading along then you’ll know that I was in the process of preparing to install Doctrine, however, it wants at the very least, PHP 5.2, and lo and behold, along came sod and his law. XAMPP runs 5.1!

I tried swapping out the libphp5.so file with the one from the Mac’s built in Apache (5.3.10) to no avail, although someone on the internet claimed it was possible.

This left me with the choice. What now? Mamp? Zend Server Community Edition? Built in Mac Apache? The correct choice of course is the shipped with Mac Apache, as the other two are once again complete PHP stack solutions, like XAMPP, and we don’t want caught out like that again! Time to get serious and install and configure all of our server components ourselves.

It’s actually remarkably easy to move your Apache and PHP across from XAMPP. I’m guessing your htdocs are kept in the Mac’s ‘Site’ folder, like they should be. If not go into your xampp htdocs and move them across.

Next you copy your virtual host entries and put them in /etc/apache2/extra/http-vhosts.conf

Then we edit /etc/apache2/httpd.conf, uncommenting the php library module by deleting the # at the start of the line:

#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module libexec/apache2/libphp5.so

In the <Directory “/Library/WebServer/Documents”>, we enable the use of .htaccess by having:

AllowOverride All

A little gotcha which had me stumped was that the .htaccess files in my sites still weren’t being used. It turns out you have a specific file for that:

sudo nano /private/etc/apache2/users/delboy1978uk.conf
<Directory "/Users/delboy1978uk/Sites/">
 Options Indexes MultiViews
 Options +Indexes +FollowSymLinks +ExecCGI
 AllowOverride All
 Order allow,deny
 Allow from all

And thats Apache sorted! We can start, stop, and restart Apache with the following commands (You can also tick a button in Apple > Preferences > Sharing > Web Sharing):

apachectl start
apachectl restart
apachectl stop

Having done that if you phpinfo(), you’ll see that there is no php.ini file! (which freaked me out a little), so I had to make one.

cd /etc

There I discovered that we have php.ini.default, so I made a copy and then edited it:

cp php.ini.default php.ini
nano php.ini

In there I set the following:

error_reporting  =  E_ALL | E_STRICT
display_errors = On
html_errors = On
include_path = ".:/usr/lib/php:/usr/lib/php/Zend:/usr/lib/php/ZendX

Lastly need the zend libraries in their new home:

sudo cp -R /Application/XAMPP/xamppfiles/library/Zend /usr/lib/php/Zend
sudo cp -R /Application/XAMPP/xamppfiles/library/ZendX /usr/lib/php/ZendX

Part 2 and we’ll kill XAMPP once and for all, leaving us with a system which will be far more powerful and customisable, and then maybe I can get on with what I was trying to do, i.e.. program!

Installing PEAR on XAMPP for Mac OS X Lion

I’m preparing to install Doctrine in order to take care of Object Relational Management within my Zend Framework projects. I use XAMPP from Apache Friends, it’s nice and simple to get up and running on pretty much every platform.

If like me you use linux quite a lot, you’ll be used to some of the commands at your disposal. OS X comes with a number of these, but it annoys me when ones I frequently use are missing. One such command is wget. Now I know we can use curl -O to the same effect, so first up I edited ~/.bash_profile and added:

alias wget='curl -O'

Now when I type wget, it will run curl, so that’s one less pain in the ass. Anyway, I’m digressing.

wget http://pear.php.net/go-pear.phar

The next thing is, Mac comes with a php installed. if you type which php, it points to /usr/bin/php. We’re going to rename it, and soft link the xampp binary instead:

mv /usr/bin/php /usr/bin/php_orig
ln -s /Application/XAMPP/xamppfiles/bin/php /usr/bin/php

A quick

php --info

should tell you from pathnames etc that you are now running from your XAMPP binary. Now we can use that php command and say:

php -d detect_unicode=0 go-pear.phar

Last thing we do is create a soft link to your /usr/bin folder

ln -s /Applications/XAMPP/xamppfiles/bin/pear /usr/bin/pear

And thats us! we are now running the XAMPP php from the command line and pear is installed and configured ready to rock! Typing in pear should show you a bunch of options!

Tune in for more! Next Stop – Doctrine!