XAMPP in Windows

Like all developers, you need a localhost environment to develop in. My personal favorite is XAMPP for Windows. In the following entries I will go through the steps in setting up recommended features.

1) Enabling mod_rewrite

Below I will quickly and easily show you how to enable Apache's mod_rewrite in XAMPP Windows. If you are unclear on what mod_rewrite is, it basically takes a long query string url and shortens it to be SEO and user friendly. Now if you are also a CakePHP user, having mod_rewrite enabled is the best course of action. But it seems that mod_rewrite is not enabled with the initial install of XAMPP. Do not worry, it's extremely easy to enable the module, and here's how it's done.

I'm assuming you have installed the xampp directory into the root or C:/ drive. The first thing to do is to open the configuration file located at C:/xampp/apache/conf/httpd.conf. Locate the text below and remove the # from the beginning of it (# acts as a comment and negates the module from loading).

#LoadModule rewrite_module modules/mod_rewrite.so

The final step is to find all instances of AllowOverride None and replace them with AllowOverride All. Now to get mod_rewrite working, you will need to restart your Apache server. You can simply do this by clicking "Stop/Start" next to the Apache module of your XAMPP Control Panel.

2) Enabling InnoDB

I recently convinced my friend to start learning CakePHP and to install XAMPP for windows. Everything was going smoothly up until he needed to have the database engine InnoDB enabled. Here's a very quick tutorial on how to enable InnoDB on Windows XAMPP (might also work with other local servers).

I'm assuming you have installed the XAMPP directory into the root or C:/ drive. The first thing to do is to open the my.cnf located at C:/xampp/mysql/bin/my.cnf (Notice Your my.cnf file may have an icon that looks like a computer/phone and has a type called SpeedDial. Do not worry, this is the correct file. To open the file, first start Notepad and then locate the my.cnf file and open it). Locate the text below and add # to the beginning of it (# acts as a comment and disables the command).

#skip-innodb

The next and final step is to remove # from any line the begins with innodb_. Your file should now look something like the following. Once you have done this, save the file and InnoDB should be useable in your local server.

#skip-innodb
innodb_data_home_dir = "C:/xampp/mysql/"
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = "C:/xampp/mysql/"
innodb_log_arch_dir = "C:/xampp/mysql/"
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

3) Setting up vHosts

If you have ever used a local server, you would immediately realize that you can only develop one site at a time using the given root. You could however setup multiple folders for different websites within your local servers root, but the problem with that is they would all share the same root, big problem! To fix this you would have to set up virtual hosts, or vhosts for short. A vhost is a small server side trick (using Apache) that allows for multiple domains (websites) under the same root or IP address.

To get this working in XAMPP, we will need to edit our hosts file and the httpd-vhosts.conf file within your XAMPP setup. But before we begin, lets set up a quick example of what we will be trying to achieve. We will want to setup two websites within the htdocs folder, we will create 2 folders with the first one "site1" and the second "site2" (you can name these whatever you wish).

The first thing we need to do is open the Windows hosts with Notepad, which can be located at C:/WINDOWS/system32/drivers/etc. If you are using Windows Vista, you will need to right click on Notepad and click "Run as Administrator" to be able to open the hosts file. Once you have opened the hosts file, add the following 2 lines to the file and save it.

127.0.0.1		site1
127.0.0.1		site2

Secondly we will need to open the vhosts file located at C:/xampp/apache/conf/extra/httpd-vhosts.conf and add the following code. Copy and paste this code for each additional vhost you wish to setup.

# Uncomment the following
NameVirtualHost *:80 

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot C:/xampp/htdocs/site1
	ServerName site1

	<Directory "C:/xampp/htdocs/site1">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot C:/xampp/htdocs/site2
	ServerName site2

	<Directory "C:/xampp/htdocs/site2">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

Once you have completed both these tasks you must restart Apache. Once restarted, you can go to http://site1/ and all files and folders within "site1" should be displayed. You may do this for as many websites as you wish, just make sure to complete both tasks!