Thursday, March 22, 2012

Change documentRoot crom /htdocs/ to D:/

It simple thing actually.. But again, this is for my reference. Im kinda easy to forget thing. I strongly believe im gonna need this again someday. So better i wrote it down before i forgot.

Normal xampp/phptriad/lamp installation, all your system folder will located inside htdocs folder. For example you have a web based application stored in folder "didik". you place in htdocs, then later u can run the application thru http://localhost/didik.

In some certain case u might want to put it out site from htdocs. Example: you dont want to use this url http://localhost/didik, which is having didik at the end. you want it appear only http://localhost. or just direct call using IP - http://172.16.1.100. You can do this either 2 ways:-

1. change directly the documentRoot to new path
    amend this file: C:\xampp\apache\conf\httpd.conf
        #old setting                                                    
        #DocumentRoot "C:/xampp/htdocs"               
        #new setting                                                   
        DocumentRoot "D:/didik/"                               


and

        #<Directory "C:/xampp/htdocs">                    
        <Directory "D:/didik/">                     


2. create a virtual host.
    a) amend this file: C:\xampp\apache\conf\extra\httpd-vhosts.conf. simply add below code
        exactly at the last line.
        NameVirtualHost *
        <VirtualHost *>
                DocumentRoot "D:\didik"
                ServerName localhost
        </VirtualHost>
        <VirtualHost *>
                DocumentRoot "D:\semangat"
                ServerName semangat
                <Directory "D:\semangat">
                        Order allow,deny
                        Allow from all
                </Directory>
        </VirtualHost>
        <VirtualHost *>
                DocumentRoot "D:\berjaya"
                ServerName berjaya
                <Directory "D:\berjaya">
                        Order allow,deny
                        Allow from all
                </Directory>
        </VirtualHost>

     b) amend this file: C:\WINDOWS\system32\drivers\etc\hosts. simply add below code
         exactly at the last line.

127.0.0.1       didik                                                                            
127.0.0.1       semangat                                                                       
127.0.0.1       berjaya                                                                        

     c) what happen now actually, now u have this 3 url

http://didik                                                                               
http://semangat                                                                       
http://berjaya                                                                        

     d)  but this url only work in ur pc. to allow other pc use the link, they must edit the host file same as ur, just changing 127.0.0.1 to ur ip address. if you dont want everytime new user edit their host file, i can suggest u this way. read here


** It is advisable to not change the documentRoot.

Creating multiple services (xampp/iis/apache/tomcat) in one machine

yes you can have multiple installation of any services. the issue will only be the port. So the question is how to differentiated or create different port for each services.

For my case i want to install 2 Xampp into my machine. Basically we can see 2 xampp folder in C: after run installation from xampp.exe.

Just remain the first installation of Xampp as the default. (port 80 and 443).

For second installation of Xampp, change to these file:-
1. C:\xampp_2\apache\conf\httpd.conf - set as below

Listen 0.0.0.0:8080                                                                                                                                         
#Listen [::]:80                                                                                                                                                 
#Listen 80                                                                                                                                                       

ServerName localhost:8080

2.  C:\xampp_2\apache\conf\extra\httpd-ssl.conf

Listen 0.0.0.0:543
#Listen [::]:443
#Listen 443

ServerName localhost:543                                                                                                                              


Now you can restart both your apache and mysql to see the changes. Having multiple services at one time.. :D
http://localhost/
http://localhost:8080/