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.

No comments: