Tag Archives: osx

XAMPP on Mac OSX with Virtual Hosts

XAMPP is an all-in-one LAMP development solution for multiple platforms. I use Linux on my main computer and OSX for my laptop.

I’ve selected XAMPP to provide the LAMP environment on my Mac. It is free, in on-going development and works well.

Because I have several projects in development at once, I need to be able to quickly update my Mac with the current state of a project and then develop and test. Subversion is part of that equation and Komodo IDE is too. Setting up LAMP on Linux is a snap, but installing everything on the Mac, even with MacPorts would be tedious. There are a few pre-packaged solutions, including XAMPP, MAMP and Zend Server. I chose XAMPP after a little research and it has worked well for me.

The Apache virtual server does not come enabled by default, so a little setup is needed.

Folder for virtual websites

Create the folder “www” in your home directory, this example is in Terminal:

cd ~
mkdir www

This is the folder where you will place each of the virtual site directories. You could just as well put this somewhere else, but a “www” directory here makes sense to me.

httpd.conf

Add the following to /Applications/XAMPP/etc/httpd.conf


	Options Indexes FollowSymLinks ExecCGI Includes
	AllowOverride All
	Order allow,deny
	Allow from all

In the above you will need to substitute your username for “yourusername”. This simply sets some Apache settings for the folder where your virtual sites will be.

In this same file find:

# Virtual hosts
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

…and un-rem out the Include line. This enables virtual hosting. Yay!

http-vhosts.conf

For each website, add a code block to /Applications/XAMPP/etc/extra/http-vhosts.conf


    DocumentRoot "/Users/yourusername/www/www.yourwebsitename.dev/public"
    ServerName yourwebsitename.dev
    ServerAlias www.yourwebsitename.dev
    ErrorLog "/Users/yourusername/www/www.yourwebsitename.dev/logs/error_log"
    CustomLog "/Users/yourusername/www/www.yourwebsitename.dev/logs/combined.log" common

In the above, just follow the same pattern I’ve shown for this example site. Don’t vary from this unless you want to do some research and testing. You can see I place a “public” folder insite the top directory for a particular virtual site – put your web documents to serve here.

hosts file

Edit your /etc/hosts file to add “www.yourwebsitename.dev” (your version of this) to a line starting with “127.0.0.1” like this:

127.0.0.1     www.yourwebsitename.dev

Restart Apache

Using the XAMPP control stop and re-start Apache.

Done.

XAMMP erroneous error message

While setting up a test system for a new MVC PHP web project, I ran into a hiccup when I restarted Apache under XAMPP on my Mac (OSX).

Googling this error turns out not to be very helpful. It is shown as an error, but no solutions.

This is a hard-to-track-down XAMPP error because the error issued has nothing to do with the problem.

Here is the text from the error dialog, so Google et al can find it: “/Applications/XAMPP/xamppfiles/bin/apachectl: line 70: ulimit: open files: cannot modify limit: Invalid argument”.

I had simply created a typo in the CustomLog line in the httpd-vhosts.conf file.

This was in the httpd-vhosts.conf file in the code block sort like this:


    ServerName projectname.dev
    ServerAlias www.projectname.dev
    DocumentRoot "/Users/andrewault/www/my.projectname.com/public"
    ErrorLog "/Users/andrewault/www/my.projectname.com/logs/error.log"
    CustomLog "/Users/andrewault/www/my.projectname.com/logs/combined.log" common

The directory part of the CustomLog line was wrong, causing the error.