LAMP Development on Mac OS with XAMPP
If you are still doing a majority of your web development on a remote server, it’s time to save yourself some major time by doing it locally. This article is based around an awesome application called XAMPP. XAMPP is a stand alone package which contains a full PHP, Apache, and MySQL installation that is preconfigured and ready to use on a Mac or Windows based machine. XAMPP stands for Cross X platform, Apache, MySQL, PHP, and Perl. It is available for Linux, Windows, Solaris and Mac OS.
This article is going to cover how to setup and configure XAMPP on your Mac, and how I prefer to do things in my development enviornment. One thing that should be mentioned is that Mac OS comes with PHP and Apache built in (you can turn it on and off through your sharing preferences panel) already. While this is very usable, I frequently ran into permissions problems and issues with things such as modrewrite. I also found it very difficult to install and configure some of the frequently used PHP modules like GD.
That being said, I found XAMPP much easier to use and much faster to roll out. It contains other nice things like PEAR, Perl, ProFTPD, SQLite, phpMyAdmin and much much more. I basically found it to be nearly identical to your typical Linux hosting environment. XAMPP also has the advantage of different versions being available which contain different PHP releases.
Installing XAMPP
XAMPP is available on SourceForge and is maintained by Apache Friends. The installation is very simple and straight forward, and there are multiple versions available. At the time of writing this, the latest version is 1.7.2a, which contains PHP 5.3. Many of the web servers I regularly deal with are still using the PHP 5.2 branch, so I mainly use the 1.0.1 version.
Once it is downloaded and install, it will be placed in the following location:
/Applications/XAMPP

Launching XAMPP
Once it is installed, you can open up your Applications folder on your Macintosh HD where you will see an icon for XAMPP Control Panel. Clicking on this icon will bring up a small box with options for starting Apache, MySQL, and FTP. Press Start next to the services that you want to run (I never actually use the FTP option yet), and a password dialog box will appear.
If you have any issues starting these services up, make sure that you have turned off FTP and WWW sharing through the sharing preferences panel.
Accessing XAMPP
Once XAMPP is all started up, you now have a fully functioning XAMP stack running on your machine. By default, you can navigate to the following URL:
http://localhost/
This will bring up the XAMPP landing page where you can choose your language of choice. From there it will bring up another page as shown below.

From there, you will notice a menu on the left hand side. I really recommend taking a look at each menu, especially the documentation and security pages. Clicking on any of the demo links will basically prove to you that the different components are functioning as you would expect them to.
One of the most important things you will notice on here is the Tools area. phpMyAdmin is already installed and ready to use. This will save the hassle of having to install it later on. (on a side note: I have tried using MySQL administrator tools, but have failed miserably so far)
Configuring your Projects Folder
Now that you have verified that XAMPP is running, I will explain to you how I configure my system. Again, this is all personal preference and this is what I have found works best for me so far. That being said, the steps below may be overkill for some casual developers.
First, I keep all of my projects in the Sites folder that lives in my Mac OS user account. All of the sites get their own folder inside of that.
The path for the Sites on my machine is:
/Users/Adam/Sites/
Configuring Hosts
The next part is a matter of preference, but I prefer to work on many sites on their own host header. Although technically either of the choices below will work for me, I find it cleaner to separate out myprojects.
I prefer:
http://projectname/
To:
http://localhost/projectname/
To accomplish this, you need to edit your “hosts”. Your hosts file contains hardcoded DNS entries that will override whatever nameserver your machine is setup to use. This comes in quite handy. To edit hosts, enter into your terminal and type in the following:
sudo nano /etc/hosts/
In the below example, you can see that I have three different hosts setup: “installs”, “activityfinder” and “xampp”. The first two are projects, and the third entry for xampp (I prefer to have XAMPP setup like I do my other projects).

To add your own project in, create a new line like the one below:
127.0.0.1 projectname
Configuring httpd.conf
Now that you have your Sites, hosts file and XAMPP installed, it is time todo a little bit more configuration to XAMPP. Before you do this, make sure to stop Apache using the control panel.
Open up the following file:
/Applications/XAMPP/etc/httpd.conf
This is the main configuration for Apache. Once in there, add the following two lines to the bottom of the configuration:
NameVirtualHost *:80Include etc/projects/*.conf
The first line tells Apache that it can use virtual hosts. The second tells Apache to scan the projects folder and include any files named *.conf as more Apache configuration.
Configuring Individual Projects
Your almost done! The next step is to create a new folder inside of the XAMPP etc folder.
This folder will then be:
/Applications/XAMPP/etc/projects/
Once that folder is created, you need to add a config file to it. You can use the lines below as a template for your own projects. You will want to change the ServerName line to be named whatever your project is called, and whatever is setup in your hosts file (in my case - “projectname” was my project name. Obviously make sure to change the DocumentRoot and Directory directives to use your own sites folder (in my case - “Adam”).
<VirtualHost *:80>ServerName projectnameDocumentRoot "/Users/Adam/Sites/projectname"<Directory "/Users/Adam/Sites/projectname">Order allow,denyAllow from all</Directory></VirtualHost>
That is it - go ahead and restart Apache! Once it’s restarted, you should be able to access your project by doing the following:
http://projectname/
Bringing it Together
The steps below are basically how the process works once completed. If you are having problems, I recommend trying each step below, and then double checking to make sure everything works.
- When you access http://projectname/, your system does a lookup on the address called “projectname”. This is what your hosts file. If your address isn’t in your hosts file, you will see an “address not found” error or something similar. Also make sure Apache is running!
- Assuming Apache is running, its going to look for a ServerName called “projectname” in it’s configuration. This configuration should have been loaded up through the “projectname.conf” file in your /Applications/XAMPP/etc/projects/ folder. Again, make sure the ServerName line in your configuration file matches your hosts entry.
- Apache will then look at the DocumentRoot line in your configuration file and will then serve up the files from within there.
As an example:
http://projectname/test.php
Uses the file:
/Users/Adam/Sites/projectname/test.php
Conclusion
You should now be able to setup sites locally on your machine easily and quickly. The environment you created and configured should behave nearly identical to most online hosts. The advantage is that you no longer need to upload files or be connected to the web to do work. It also works great for a multi-developer system.. an article on that still to come.
I need to setup comments on here, but feel free to hit me up at my contact information!

0 Response to "LAMP Development on Mac OS with XAMPP"
Leave a Comment »