Install XAMPP server, configure Apache to activate sub domains

XAMPP control panel

XAMPP is a multi-platform Apache distribution that provides you a Web server, which is pre-configured with PHP, Perl, database, FTP and mail servers. You can install it using the XAMPP installer for Windows. If you are using Linux or Mac or any other operating system, download the appropriate package and follow the instructions on XAMPP site for installation.

Now, start XAMPP control panel and start Apache and MySQL. Open http://localhost in your Web browser to access phpMyAdmin, FileZilla FTP, Mercury Mail and Webalizer statistics page.

Creating sub domains in Apache Web server: If you want to use addresses such as http://localhost/blog (sub domain) to point to a folder, say D:/MyServer/blog, you need to create an "alias" that will redirect the web address to the designated folder on the local computer.

First, locate "httpd.conf" file in the Apache folder in Xampp directory. If the xampp directory is located on C:\ drive (default location), you can find the configuration file in C:\xampp\apache\conf. Open httpd.conf with a text editor such as Notepad or Notepad++. Now, find the following in the file:

<IfModule alias_module>

We will add our alias below this tag but above the tag ends. The following format is used to add an alias:

Alias URL-path file-path/directory-path

We also need to add options directive for granting specific permissions to the particular directory. By default, it grants all rights to the directory. You can get details about various options available for configuring access to directories in Apache documentation.

For creating the alias "/blog", we will have to make our httpd.conf look like this. You can copy and paste it to your http.conf file. Modify the comment line to reflect your notes. Change the alias to your desired one and also the address of the folder. Do not put a "/" after your alias as this will make the alias effective only with a terminating "/".

<ifmodule alias_module>

#Adding an alias BLOG on 18 March 09 (Comment)
Alias /blog D:/MyServer/blog
<Directory D:/MyServer/blog>
AllowOverride All
Order allow,deny
Allow from all
</directory>

Creating sub domains in Apache
Now, if we want to add another alias, say, http://localhost/images (or http://your-server-address/images) that points to D:/images, your httpd.conf file should look like this.

<ifmodule alias_module>

#Adding an alias BLOG on 18 March 09
Alias /blog D:/MyServer/blog
<Directory D:/MyServer/blog>
AllowOverride All
Order allow,deny
Allow from all
</directory>

#Adding an alias IMAGES on 18 March 09
Alias /images D:/images
<Directory D:/images>
AllowOverride All
Order allow,deny
Allow from all
</directory>

Changing the root folder of your server: In a XAMPP installation, by default, http://localhost (or http://your-server-address) points to "C:/xampp/htdocs" folder. If you want http://localhost to point to some other folder, you can do this by replacing "C:/xampp/htdocs" with the address of your own folder. Let's make "MyServer" folder on D:/ drive to be the root folder of our server. Before we move ahead, let me make it clear that this tutorial assumes that your XAMPP is installed on C:/ drive. If it's not, adapt the instructions according to your settings.

Find the default entry for "DocumentRoot" in httpd.conf file that exists in "C:/xampp/apache/conf".

DocumentRoot "C:/xampp/htdocs"

Changing root folder in Apache
Change the address of the root folder to the new one. In our example, it will be D:/MyServer. Thus, the entry will look like:

DocumentRoot "D:/MyServer"

Now find the following:

<Directory "C:/xampp/htdocs">

Changing root folder in Apache
Change the address of the directory to our new root directory's address.

<Directory "D:/MyServer">

Restart (stop and then start) your Apache server to reflect the changed root directory. Now you can start saving all your web pages, blogs, etc., in this folder.

Fixing broken links after moving root folder: Since the default root folder (C:/xampp/htdocs) provided easy access to phpMyAdmin, FileZilla Server, Mercury Mail and Webalizer, it would be nice if you create an alias, say, admin for C:/xampp/htdocs folder. Follow the procedure explained above. But even now if you point your browser to this alias, say, http://localhost/admin, it will redirect you to the default location which no longer exists.

To fix this, open the index.php file in the htdocs folder in a text editor such as Notepad or Notepad++. Now find the following:

header('Location: '.$uri.'/xampp/');

Fix link broken due to moving root folder in Xampp
Replace it with the following:

header('Location: '.$uri.'/admin/xampp/');

Now when you point to http://localhost/admin, it will take you to the default page that gives you easy access to several important control pages.

Adding your own favicon to the server: When a page is requested, the XAMPP server looks for a favicon icon (favicon.ico) in the root folder, which, by default, is "C:/xampp/htdocs" . We need to replace the favicon.ico in the root folder with our own.

Create the favicon using any image or from scratch and save it as a Microsoft Windows Icon (.ico) format. Open source image editor GIMP allows you to save icons in .ico format. Replace the favicon icon in the "XAMPP/htdocs" folder with your own. Now, clear the cache by deleting private data in your browser and go to http://localhost. You will find your favicon.

Additional resources:
Easy guide to installing a Web server on Ubuntu

Labels:  ,

Author: Nyutech

Date: Tuesday, March 17, 2009

0 comments | Leave a comment

0 Responses to "Install XAMPP server, configure Apache to activate sub domains"

Post a Comment