Thursday, May 9, 2013

How to build a virtual web server and enable access from external network (Windows 8, CentOS 6, VMware Workstation)


I am faced with a task where I have to build a development webserver on a notebook, spesifically a Lenovo ThinkPad Twist (Intel Core i7, 8GB RAM, Windows 8 64-bit).
I would not use werbserver package such as XAMPP werbserver, PHPTriad, etc, to avoid incompatibility issues at the time of deployment later.
It means, I must build a pure web server environment, and for that I would use CentOS operating system.

Since the ThinkPad Twist already came with an original Windows 8, so I'm not going to use a dual-boot approach. The only way is to install CentOS virtual guest host on Windows 8 with VMware Workstation.

Concern that must be achieved are:
  • Host OS is Windows 8 64-bit 
  • Guest OS is Linux CentOS 6.4 Final 
  • Apache web server running on Guest OS
  • MySQL database server running on Guest OS 
  • The web server on Guest OS must be accessible from the Host OS 
  • The web server on Guest OS must also be accessible from the external network, for colaborative development needs. (Allows access to SSH, HTTP, and MySQL to Guest webserver) 

 I will explain how to make it, step by step:

Devices :  

  1. Lenovo ThinkPad Twist (Intel Core i7, 8GB RAM, Windows 8 64-bit) as the host, also installed VMWare Workstation 9.0 with 64-bit CentOS 6.4 as a guest OS that will act as a webserver. Let assume the IP address for this notebook is 10.2.2.213 
  2. Lenovo ThinkPad X100e (AMD Athlon Neo MV-40, 2GB of RAM, Windows 7 64-bit), act as the client computer that needs access to webserver. The IP address is 10.2.2.214

Installation: 

I'm not going to explain how to install CentOS guest OS, I assume you've understand how to install a guest OS in VMWare Workstation. Maybe, if there is some free time, I will write it in a separate article.

Once the OS has been installed in VMWare Centos, it is advisable to install VMWare Tools.
Next step, is to install the necessary packages:

Apache2 Webserver:
yum install httpd
chkconfig - levels 235 httpd on
/etc/init.d/httpd start

MySQL database server:
yum install mysql-server mysql
chkconfig - levels 235 mysqld on
/etc/init.d/mysqld start

PHP5:
yum install php
/etc/init.d/httpd restart

MySQL Support in PHP5:
yum install php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc
/etc/init.d/httpd restart

Enable SSH daemon:
chkconfig - levels 235 sshd on
service sshd start

Let's make sure everything is going well:
[root@localhost ~]# service httpd status; service mysqld status; service sshd status
httpd (pid 2490) is running ...
mysqld (pid 2355) is running ...
openssh-daemon (pid 3760) is running ...

Then, try to direct your browser to http://localhost

Apache2 Test Page


NAT Settings: 

OK, next we will configure the NAT (Network Address Translation) in VMWare Workstation.
First, give a static IP on the guest OS. In this case, I give the IP address with 192.168.222.128. Please write down the IP somewhere, we will need it later.



On VMware, choose Edit > Virtual Network Editor menu. In the dialog that appears, select VMnet8 adapter with external NAT connection, then press the NAT Settings button.



On NAT Settings, we will do some port forwarding. The principle, if there is a request to port XXX on the host OS, it will be forwarded (forwarding) to YYY ports in the guest OS.

We will forward some ports  as follows:
Host IP Port Guest IP Port
127.0.0.1 8888 192.168.222.128 80
127.0.0.1 3333 192.168.222.128 3306
127.0.0.1 2222 192.168.222.128 22



The final result will be like this:



Now back to the host OS (Windows 8), I open the browser, navigate to http://127.0.0.1:8888, and hooplaa... it works !
 
So how to access the webserver from external network? Simple, just point your browser to the IP address of the host computer and adding the port number that we've specified above. For example htpp://10.2.2.213:8888

For SSH access, use the 10.2.2.213 IP address on port 2222
For accessing MySQL Databases remotely, use 10.2.2.213 IP address on port 3333


OK guys, i hope this article will helps :-)
drop me ur comment

No comments:

Post a Comment

Leave your comments with attitude please. This blog does DOFOLLOW :-)