Thursday, November 7, 2013

XAMPP HTTPD Virtual Hosts Configuration


-----
1) INTRODUCTION
2) EDIT HOSTS file
3) CREATE WEB ROOT DIRECTORY
4) EDIT httpd-vhosts.conf
5) RESTART WINDOWS

1) INTRODUCTION

1.2) The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user. (refer http://httpd.apache.org/docs/2.2/vhosts/)

2) EDIT HOSTS file

2.1) Before a Virtual Host is configured in Apache environment, its address (IP No. and Domain Name) must be registered to the host computer first. This is accomplished by editing a Hosts file.
2.2) By definition, the hosts file is a computer file used by an operating system to map hostnames to IP addresses. The hosts file is a plain text file, and is conventionally named hosts. (http://en.wikipedia.org/wiki/Hosts_(file))
In windows, the file can be found at %SystemRoot%\system32\drivers\etc\hosts
In Linux, the file can be found at /etc/hosts
2.3) Using notepad++ open the hosts file and edit as follows:
(add the name “testproject.local”)

3) CREATE WEB ROOT DIRECTORY

3.1) Web root directory for testproject.local can be located at anywhere in the computer storage.
3.2) For example, C:\projects\testproject.local\htdocs 
3.3) Create a simple content for index.php for testing purpose as shown above.

4) EDIT httpd-vhosts.conf

4.1) At line no. 19, remove the # symbol to enable NameVirtualHost directive.
4.2) Add new codes to the bottom of the existing codes.
Notice that there are two VirtualHosts defined; one for the localhost and the other one for testproject.local.
<VirtualHost *>
    ServerAdmin admin@localhost.com
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>
<VirtualHost *>
    ServerAdmin admin@localhost.com
    DocumentRoot "C:/projects/testproject.local/htdocs"
    ServerName testproject.local
         <Directory "C:/projects/testproject.local/htdocs">
                        AllowOverride all
                        Order allow,deny
                        Allow from all
                        Require all granted
         </Directory>        
</VirtualHost>

5) RESTART WINDOWS

5.1) Windows must be restarted for the new virtual host address to be recognized.
5.2) After running the Apache Server, check in the Web Browser that the following output is displayed.

XAMPP HTTPD INCLUDE AND ALIAS DIRECTIVE


-----

1) Introduction
2) HTTPD Include Directive
3) HTTPD Alias Directive

1) Introduction

1.2) It is recommended that you use Notepad++ as default text editor for faster and efficient text search and edit.

2) HTTPD Include Directive

2.1) A left-click on Config button for Apache will bring about Apache Context Menu.
2.2) Notice that there are three httpd-related files. How are they related?
Click on the first httpd.conf file to view it in Notepad++
2.3) If you search for “httpd-xampp” you will be brought to line no. 452
2.4) If you search for “httpd-ssl” you will be brought to line no. 486
2.5) Now, we see that the httpd.conf is linked to other httpd-related files via the keyword “Include” followed by the corresponding physical file path.
2.6) Take note that the httpd-related files are stored in the “{apache_home}/conf/extra/” folder.
2.7) Another interesting file to look for is httpd-vhosts.conf.
The include statement to this file can be found on line no. 473 of httpd.conf file.

3) HTTPD Alias Directive

 3.1) Open the httpd-xampp.conf file and go to line no.99 to get the following part:
3.2) The Alias directives are used to map between URLs and filesystem paths.
This allows for content which is not directly under the document root to be served as a part of web document tree. (refer http://httpd.apache.org/docs/2.2/mod/mod_alias.html)

XAMPP FOR WINDOWS SETUP


-----
Contents

1) PREPARATION        
2) SETUP        
3) START APACHE        
4) START MYSQL        
5) START OTHER SERVERS (IF NEEDED)        

1) PREPARATION

2) SETUP

2.1) Run an unzip software such as 7-zip portable (downloadable from http://sourceforge.net/projects/portableapps/files/7-Zip%20Portable/7-ZipPortable_9.20_Rev_3.paf.exe/download )
2.2) Browse into the zip file until you see “xampp” folder.
2.3) click Extract and set target path as c:\
2.4) Outcome:
2.5) Browse the content of C:\xampp to find xampp-control.exe
2.6) Run xampp-control.exe
The message “Control Panel Ready” indicates that there should be no problem running the XAMPP suite.

3) START APACHE

3.1) Click the button Start for the Apache Service.
3.2) Unblock Firewall protection against Apache service.
3.3) Outcome:
3.4) Test Apache Server.

4) START MYSQL

4.1) Click the button Start for the MySQL Service.
4.2) Unblock Firewall protection against MySQL service.
4.3) Outcome:
4.4) Test.
Typing http://localhost/phpmyadmin/ will bring you to phpmyadmin page.

5) START OTHER SERVERS (IF NEEDED)

5.1) Use FileZilla for FTP Server.
5.2) Use Mercury for Email Server.
5.3) Use Tomcat for Java Server.

Tuesday, November 5, 2013

WampServer + Apache mod_rewrite: Friendly URL (subpage style)


-----


1) PREPARATION
2) SETUP PROJECT
3) TEST WEBSITE
4) DOWNLOAD
5) REFERENCES

1) PREPARATION

2) SETUP PROJECT

2.1) Prepare the following file/folder structure to test mod_rewrite
{wamp_home}/www/test_rewrite_friendly/
                                       .htaccess
                                       index.php
                                       user.php
2.2) Edit codes as follows:

3) TEST WEBSITE

4) DOWNLOAD

Project Source Code (completed):

5) REFERENCES

WampServer + Apache mod_rewrite: Simple Test



1) PREPARATION
2) ENABLE mod_rewrite
3) TEST mod_rewrite
4) ENABLING Apache mod_rewrite USING GUI MENU.
5) DOWNLOAD
6) REFERENCE

1) PREPARATION

1.1) Download and install WampServer (follow this tutorial, http://php-steps.blogspot.com/2013/11/wampserver-download-setup-installation.html )

2) ENABLE mod_rewrite

2.1) Once your WampServer is up and running, go to URL http://localhost
2.2) Scroll down to find the link to phpinfo().
Click on the link.
2.3) In the phpinfo() page, under  Configuration-apache2handler section, look for the row named Loaded Modules. It should contain the word “mod_rewrite”. You can also use the Find function (as shown below) to search for the exact matching word.
In the example below, “mod_rewrite” doesn’t exist. Go to the next step to enable the module.
2.4) Open the file {wamp home}\bin\apache\Apache2.2.11\conf\httpd.conf and search for the text “rewrite”.
It is recommended that you use Notepad++ so that you can easily find the line number, e.g. line 116
2.5) Uncomment the line (by deleting the symbol #) as follows:
2.6) Save, restart the server and check phpinfo() again as follows:
The word “mod_rewrite” should now appear in the Loaded Modules row.

3) TEST mod_rewrite

3.1) Prepare the following file/folder structure to test mod_rewrite
{wamp_home}/www/test_rewrite/
                                       .htaccess
                                       index.html
                                       page1.html
3.2) Type the contents as follows:
3.3) Browse the url http://localhost/test_rewrite:
3.4) To double-check the rewrite effect, comment the line no.116 back…
…and browse the url http://localhost/test_rewrite :
…if you delete the file .htaccess and browse the url http://localhost/test_rewrite again:

4) ENABLING Apache mod_rewrite USING GUI MENU.

4.1) Click on the WampServer icon at the tray, click Apache/Apache Modules/rewrite_module.
4.2) The WampServer will restart automatically.
4.3) Make sure that the file .htaccess is placed into test_rewrite folder.
4.4) Browse the url http://localhost/test_rewrite:

5) DOWNLOAD

6) REFERENCE

Labels