CodeIgniter + XAMPP (0.7.1) + OS X Setup Guide

Posted on Jan 27 2008 09:08pm by Luke Davison

Having a decent development environment is important for any developer, and getting CodeIgniter and XAMPP setup on OS X (or any platform) is a snap! Sure, OS X ships with Apache, but I really like the stand-alone style of XAMPP. Plus, since XAMPP is cross platform, I can easily move my environment between platforms and minimize the need to re-configure anything.

First a little background though. The XAMPP project is a wonderful bundle created by the Apache Friends. It includes Apache, MySQL, PHP and Perl. For PHP, it includes both PHP4 and PHP5, and also ships with PHPMyAdmin for administering the MySQL server. Basically, it lives in a single directory and doesn't need to be "installed". For Windows users this is a huge plus (refer to XAMPPLite).

The CodeIgniter (CI) project is intended to be a very lightweight, highly extendable MVC frakework for PHP4 and PHP5. Sure, there are other frameworks out there such as CakePHP, but I prefer CI due to it's incredible documentation and because I feel it is more lightweight.

Go ahead and download CodeIgniter and XAMPP for OS X if you do not already have them. I prefer to checkout CodeIgniter from the SVN; you can read instructions on doing that here. Once you have both of the packages, start by installing XAMPP. For OS X users, I opted for XAMPP MacOS X (tar) 0.7.1. To get this going, run the following command:

$ sudo tar xfvz xampp-macosx-0.7.1.tar.gz -C /

This will extract the tarball into /Applications/xampp/. Following the CI SVN article on Derek Allard's site, I checked out CI #844 into /Users/ldavison/sandbox/ci_844/ using svnX. As you can see, I have put my CI source into a directory that is non-public to my XAMPP installation. In fact, this is one of the most parts of the setup in my opinion; making sure CI is outside the web servers DocumentRoot. Of course, a lot of the CI source has this in the top of the files:

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

However, I still feel it's better if the files aren't in a public directory to begin with avoiding any direct access to the source.
The next thing is to copy the index.php file into the DocumentRoot, in fact it's the only file in the CI code that needs to be publicly accessible.

$ sudo cp /Users/ldavison/sandbox/ci_844/index.php /Applications/xampp/htdocs/. $ sudo vim /Applications/xampp/htdocs/index.php

In the index.php file, edit the path to the system folder, in this case:

$system_folder = "system";

becomes:

$system_folder = "/Users/ldavison/sandbox/ci_844/system";

In order to get XAMPP to use mod_rewrite and read the configuration from a .htaccess file, the /Applicatons/xampp/etc/httpd.conf file needs to be updated. Look for the section:

<Directory "/Applications/xampp/xamppfiles/htdocs">

In here there will be a line that reads:

AllowOverride AuthConfig

Change that to read:

AllowOverride AuthConfig FileInfo

Restart the servers in XAMPP, by running:

$ sudo /Applications/xampp/xamppfiles/mampp restart

Alternatively, you could find out the PID of the apache process owned by root and kill -HUP it. That will force Apache to reload it's config:

$ ps aux | grep httpd
nobody   51504   0.0  0.1   103016   1220   ??  S

     3:38AM   0:00.00 /Applications/xampp/xamppfiles/bin/httpd -k start -DSSL -DPHP5
nobody   51503   0.0  0.1   103016   1220   ??  S

     3:38AM   0:00.00 /Applications/xampp/xamppfiles/bin/httpd -k start -DSSL -DPHP5
nobody   51502   0.0  0.1   103016   1220   ??  S

     3:38AM   0:00.00 /Applications/xampp/xamppfiles/bin/httpd -k start -DSSL -DPHP5
nobody   51501   0.0  0.1   100384   1252   ??  S

     3:38AM   0:00.00 /Applications/xampp/xamppfiles/bin/httpd -k start -DSSL -DPHP5
root     51454   0.0  0.4   103016   7596   ??  Ss

    3:38AM   0:00.24 /Applications/xampp/xamppfiles/bin/httpd -k start -DSSL -DPHP5
nobody   51506   0.0  0.1   103016   1220   ??  S

     3:38AM   0:00.00 /Applications/xampp/xamppfiles/bin/httpd -k start -DSSL -DPHP5
nobody   51505   0.0  0.1   103016   1220   ??  S

     3:38AM   0:00.00 /Applications/xampp/xamppfiles/bin/httpd -k start -DSSL -DPHP5

 

$ sudo kill -HUP 51454

That should kill all the child processes (owned by nobody) and re-spawn them with the updated httpd.conf file. If the web server is not running, double check that the configuration added was correct. You can look at the error_log to see why Apache failed to start with the updated configuration by running:

$ tail /Applications/xampp/logs/error_log

Once the httpd.conf file has been updated properly and Apache successfully reloaded, add the below to /Applications/xampp/htdocs/.htaccess. That will tell Apache what the rewrite rules are for mod_rewrite in the htdocs directory, which will remove index.php from your URI. For instance, http://localhost/index.php/controller/action will become http://localhost/controller/action.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>

    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

 

Alternatively, you can add the above to the <Directory "/Applications/xampp/xamppfiles/htdocs"> section, but for development (why we're using XAMPP to begin with) I prefer using .htaccess so I don't have to restart Apache to alter certain configurations. You might want to re-think this in a production environment, of course checking with your system administrators is always best.

At this point, everything should be working properly and you should have a fresh new development environment setup! So, get after it, write some code! Free free to hit me up with any questions or comments.

 

Comments

Rakcson said:
Continuing best web hosting improvements led to the furnace and bellows and provided the ability to smelt and forge native metals (naturally occurring in relatively pure form).[33] Gold, copper, silver, and lead, were such early metals. The register domain advantages of copper tools over stone, bone, and wooden tools were quickly apparent to early humans, and native copper was probably used from near the beginning of dedicated server Neolithic times (about 8000 BC).[34] Native copper does not naturally occur in large amounts, but copper ores are quite common and some of them produce metal easily when burned in wood or charcoal fires. Eventually, the working of metals led to the discovery of alloys such as bronze and brass (about 4000 BC). The first uses of iron alloys such as steel dates to wireless internet around 1400 BC.