Run a Debian Wheezy web server in VMWare Player (including subdomains)
There are more ways to have a local web server running on your own laptop or PC. Many of these servers have the limitation that they are running on your own laptop's localhost (127.0.0.1). I needed a webserver that I could take with me to my customers, but like I would had brought the server also with me.
VmWare Player
A solution that works well for me is the VmWare Player, that works like a kind of VmWare Server in a box. It is free to use (not commercial) and the installation is almost identical to the way virtual machines are installed with VmWare ESX servers.
You can download the VmWare player from this location: link.
After the download just install the software and start it. The creation of virtual machines is easy and you can do the installation following my articles, Install Debian Wheezy on VMware (1) and Install Debian Wheezy on VMware (2).
Objectives
I don't pretend to be a Linux expert and the objective is to have VMware Player installed with Debian virtual machine running a webserver that can be accessed from our Windows laptop or PC.
I have spent too much time on having a DNS server configured in Debian, but as Windows addict I am heavily spoilt with Microsoft Windows Server, where the DNS configuration is a piece of cake. So the server will be found over the good old hosts file of Windows.
Internal use only!
This web server is for local use on a laptop or PC. It is NOT for use as a web server to the internet. So many security features I haven't installed or configured as I am the only one using this server as a development server.
Installing the web server on Wheezy
There is not much to say to this, because you already have your Apache web server installed with the installation of Debian. If you haven't selected the web server option at installation time then follow this link for instruction how to install the web server in Debian.
Changing the network interface to static IP address
The web server is now only bound to IP Address 127.0.0.1 (localhost). It is important that we make the web server visible in our Windows environment, so we have change the interface information. We can do that by modifying file /etc/network/interfaces. Open this file with your editor and modify the content to the following (use your own IP addresses instead).
# The primary network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
#Static IP Address
address 192.168.101.101
netmask 255.255.255.0
gateway 192.168.101.2
To set the DNS server address, you have to edit the /etc/resolv.conf file, with root priviledges:
domain localdomain
search localdomain
nameserver 192.168.101.2
Ensure /etc/hosts file properly resolves local hostfile. Also add here (like in the Windows hosts file, the DNS names to your domains and subdomains. Otherwise you can't access them in IceWeasel on any other browser on Debian.
127.0.0.1 localhost
192.168.101.101 desktop.local
192.168.101.101 movieworld.desktop.local
If you want your server to listen to another port than 80 follow this link for more information.
Creating virtual domains for subdomains
If the root of your web server can be reached from a web browser by f.e. desktop.local, maybe you want to have a subdomain like movieworld.desktop.local. The benefit of subdomains is that a subdirectory within your /var/www directory is with a subdomain always a root directory. That can be very useful to avoid problems that can occur with files not found if you would use f.e. desktop.local/movieworld and the final release of your site or app would be installed in the root of your internet web server space.
To create a subdomain we have to create virtual hosts in Apache. Within Debian you have the following 2 directories that contain the sites within our web server.
- /etc/apache2/sites-available
- /etc/apache2/sites-enabled
In the sites-available directory are the files that describe every domain or subdomain on our web server. In the sites-enabled directory are the links (shortcuts) to the domains that are really to be found and activated once the Apache server starts.
To not have to go through all the theory you just copy the 000-default file in the sites-available directory and give it a logical name that corresponds with your (sub)domain name. Open this file with an editor like Gedit and modify it to your demand. We follow the example as stated above for subdomain movieworld.desktop.local
ServerName movieworld.desktop.local
DocumentRoot /var/www/movieworld
Options FollowSymLinks
AllowOverride None
Options Indexes FollowSymLinks MultiView
AllowOverride all
Order allow,deny
Allow from all
ErrorLog ${APACHE\_LOG\_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE\_LOG\_DIR}/access.log combined
Save the file and make a link copy to the file (shortcut). Move the link to the directory sites-enabled. Make sure that the directory /var/www/movieworld or wherever you want to point the DocumentRoot to, exists.
Now you have to restart the Apache web server.
sudo service apache2 restart
Modifying the hosts file in Windows
We are simply using the quick and dirty way to add the local VMware server domains to our local hosts file of our PC. If you have not done this before follow this small instruction.
- Locate the file hosts on your PC in the directory: c:windowssystem32driversetc.
- Make sure you have write access to this file. The best way to access the file is by doing this over a DOS prompt box that you start with administrator rights.
- If you can't edit the file, type the command below followed by Enter.
attrib hosts -R
When editing the file, make sure that you add your VMware domain and its subdomains to this file. Let's say that your server is called desktop.local and you have a subdomain called movieworld.desktop.local. Then these entries should be added to the hosts file. Assumption is that your web server has IP address: 192.168.101.102.
192.168.101.102 desktop.local
192.168.101.102 movieworld.desktop.local
Additional installs and configuration
Make htaccess work on the rewrites
By default the Apache mod_rewrite is installed but not enabled. Follow this link to read how you can enable it: link.
Setup the ftp server
Local USB web server installations have the great benefit that the root of the web server is somewhere on the local disc. With VMware player it is as you run a real (intranet) web server instance which has to be accessed with ftp.
Open port 21 for ftp access
If port 21 is not open for ftp access follow this link on how to fix that.
PHP GD Lib
On most commercial hosting packages the PHP GD lib is installed for manipulation of images. So it is good that you install this too.
sudo apt-get install php5-gd
You can also install this with the Synaptics Package Manager in Debian.
MySQL Workbench
You can always install PHPMyAdmin, but I recommend you install MySQL Workbench instead, for you are not restricted by any provider not to use it. You can install it with the Synaptics Package Manager.
On the Windows side you could give HeidiSQL a try. A free MySQL database manager. You can download the software with this link.
To access the MySQL server from outside the Debian server (like with HeidiSQL), you have change the /etc/mysql/my.cnf. Find:
bind-address = 127.0.0.1
Change this in:
#bind-address = 127.0.0.1
Webmin system administration
Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more. And it's free
It has a Debian package that can be installed with the GDebi Package Installer.
Further reading
Further reading: Debian 7 Wheezy Dedicated Web Server Setup Step by Step