JaggyGauran

Freelance developer, and designer

My Native-ish, PHP, Apache and MySQL Mountain Lion Setup

I've come to know and love my Linux setup from days before, God, I sound old. Anyways, inheriting my brother's Macbook, I've kinda grown soft with it, but still miss the Linux setup.

After trying XAMPP, MAMP and MAMP PRO, I've decided to go native.

MySQL

Just download the DMG file from here.

Don't forget to install everything! I forgot to install the startup package and kept wondering why my MySQL doesn't startup every time I boot up. (Yeah, I know)

PHP 5.4

I installed PHP5.4 from http://php-osx.liip.ch/

What's good about this, is they have their own ini file which is much better than the default. It's located here: /usr/local/php5/php.d/99-liip-developer.ini

Update /usr/local/php5/php.d/99-liip-developer.ini to change your timezone accordingly. Also, to fix up some things, execute this in your terminal.

echo 'export PATH=/usr/local/php5/bin:$PATH' >> ~/.profile
source ~/.profile

What this does is override the default PHP command, hence the $PATH on the latter part, so that you're using PHP5.4. You can check it out by running php -v.

Apache

Here's where it get's tricky. First, open up your /etc/apache2/httpd.conf.

Uncomment the line:

#LoadModule php5_module libexec/apache2/libphp5.so

This enables PHP to be parsed when well, doing your thing.

Virtual Hosts

The native apache has it's own setup for handling virtual hosts /etc/apache2/extra/httpd-vhosts. Though, it kinda irritates me 'cause it's all bulked up in a single file. Which is kind of hard to maintain.

I really prefer implementing Ubuntu's style wherein virtual hosts are handled with different files. Here's how we do it.

Open up /etc/apache2/httpd.conf. Go to line 478 and insert this:

NameVirtualHost *:80
Include /private/etc/apache2/vhosts/*.conf

What NameVirtualHost *:80 lets you have multiple ServerNames at once. Without that, your apache will only read your first host.

The next line includes all your .conf files and reads them. Create the folder and store all your hosts there. sudo mkdir /private/etc/apache2/vhosts

Here's what mine looks like:

$ ls
template   site1.conf   site2.conf   site3.conf

So, here you go, an organized setup for your virtual hosts. Here's the template of my vhost configuration.

<VirtualHost *:80>
    ServerName site_name

    DocumentRoot /path/to/app/webroot
    <Directory /path/to/app/webroot>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog "/private/var/log/apache2/site_name-error.log"

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog "/private/var/log/apache2/site_name-access.log" combined
</VirtualHost>

Don't forget to restart the server!

$ sudo apachectl restart

Well, there you go and hope I helped.

Ways Down the Road

Now, I started using the PHP built in server.

$ php -s localhost:3000