If you ever needed to write program that sends email, most likely you’ll need a SMTP server. Here’s how you can configure one on a Windows box using hMailServer.
After downloading and installing, you need to add a new domain to hMailServer. In my case I will not be using hMailServer to accept incoming email, hence I did not put the company’s email domain. Doing so will cause email to your colleague to be routed locally and likely fails.
So go ahead add a new domain, and just give it the local machine name (eg: devbox01.local). You have to pick a name that resembles an actual domain (with a dot and suffix), otherwise hMailServer will rejects it.
Once you’ve setup the domain, create a new account email@example.com
Set a password, and that’s it you’re done. You can now use the SMTP server for outbound email
- Username: firstname.lastname@example.org
- Password: whatever password you put in
- SMTP host: devbox01
- SMTP port: 25
Now what’s left to do is configuring firewall. If you program runs on the same box you might not need to do anything. However it’s good to check that no outside traffic from internet can connect to port 25 so no-one can abuse your SMTP server.
And as a last word of warning, do not assume all mails will be delivered
. This SMTP setup is very basic. Depending on the content you send, SPF
, reverse DNS entry, spam filtering of receipient, and gazillion other things, your email might not go through
Just resolved an interesting problem today, one of our code breaks because the response header set by the web server did not include Content-Length.
Spent quite a while investigating and turns out this is due to gzip compression. As seen below Content-Encoding is gzip and I think this causes Content-Length to be omitted.
Gzip compression can be disabled on apache via .htaccess config. In my case I disabled all compression to swf file by adding following configuration
SetEnv no-gzip 1
Simplest way to test if a port is open on firewall is through telnet, but problem with that is what if you don’t have anything listening? What if you’re preparing infrastructure for a new app-server deployment — telnet won’t work unless there’s something listening on the server.
With netcat you can create a simple listener that echoes whatever character passed to it. Netcat should be available on standard UNIX system via nc command.
If you want to test if port 1234 has been allowed through on firewall:
- On the server, run nc -l -p 1234. Netcat will wait incoming connection to port 1234.
- On the client, simply do telnet 22.214.171.124 1234 (assuming the server ip is 126.96.36.199)
If the server is on Windows, there’s even a Windows version of Netcat available.
We are building a second web server with a hope of installing a load balancer soon. We came into a problem where we have to synchronize the file contents between multiple servers. The solution we’re opting is to install and mount a shared network folder (NFS) visible from both web servers. The shared folder lives on its own server (aka file system server).
It is assumed:
- The file system server host (Master) is 188.8.131.52
- The client is 184.108.40.206
- The folder to be shared on master is /var/www/vhosts
- The folder will be mounted to /mnt/nfs/var/www/vhosts on client
Creating a NFS Share on the File System Server
Perform these steps on the file system server (aka “Master”):
- Install nfs-utils and nfs-utils-lib package using yum:
yum install nfs-utils nfs-utils-lib
yum list installed to check if the packages are already installed
- Turn on nfs service so it automatically starts on boot
chkconfig nfs on
chkconfig --list to check status of all services
- Start rpcbind and nfs service
service rpcbind start
service nfs start
- Edit /etc/exports file and add following line at the end
See here for explanation of the options
- Run following command to apply the changes
Mounting it on the Client
Following steps will mount the network folder permanently (folder will automatically re-mount on server reboot). Perform this on the client server:
- Similar to server, ensure nfs-utils and nfs-utils-lib are installed
yum install nfs-utils nfs-utils-lib
- Create the directory that will hold the mount (mount point)
mkdir -p /mnt/nfs/var/www/vhosts
- Edit /etc/fstab file and append following line
220.127.116.11:/var/www/vhosts /mnt/nfs/var/www/vhosts nfs defaults 0 0
mount /mnt/nfs/var/www/vhosts to apply the mounting. Check if the mounting is successful using
OS User on Master and Client
To ensure file system operations are consistent, consider propagating same OS user setup between the master and client. Note that although same username exists on both master and client they don’t necessarily have the same UID.
- Checking uid and group of user jim:
$ id jim
uid=506(jim) gid=505(xyzco) groups=505(xyzco)
(jim has uid 506 and belongs to group xyzco)
- Adding a new user jim with uid 506
useradd -u 506 jim
- Adding jim to the group xyzco
usermod -G xyzco jim
- Setting / resetting password for jim
I’ve noticed this behavior for a while, and did some searching over the internet. I found this post from hamachi forum about how to prevent hamachi going offline when RDP session is logged out’
So as a workaround you can log off your RDP without closing the session creating a shourtcut in your desktop directed to “%windir%\System32\tscon.exe RDP-Tcp#0 /dest:console” and run as administrator. This will log you off and leave the session open. Just saying.
So far this solution seem to work for me, need to figure out what will happen when another user logs in into the PC.
Came accross VirtualBox, a free & excellent virtual machine software. I decided to take it for a spin creating a Ubuntu virtual machine LAMP stack on it..
Here We Go
- Download and install VirtualBox
- Download latest Ubuntu iso installation file
- From VirtualBox create a new Virtual Machine. Select type: Linux and version: Ubuntu. On the next step you will be prompted with dvd drive containing the installaion disk, but instead just select the iso downloaded on step 2
- Go through the Ubuntu installation steps
- It’s also very helpful to install ssh server so you can ssh into your VM later on: sudo apt-get install openssh-server
Voila! You have ubuntu running on your Windows PC
Host and Guest
In virtualization realm, host indicates your physical PC (Windows 7 in my case), and guest is the virtual machine (Ubuntu). Most of virtual machine software documentation uses host and guest terminology heavily so make sure you’re familiar with it
This is where things get tricky. Virtual machine comes with virtual network adapters, and you have to do few configuration to setup connectivity between your virtual and physical adapters.
By default VirtualBox allows the guest machine to connect to the internet through NAT, so you can download data, browse internet etc. However if you want to run servers from the guest, it won’t be discoverable by the host or other PC in the host’s network immediately.
One approach to make them discoverable is by setting up port forwarding. You get here by going to networking section on the machine’s setting on Virtual Box
Note that setting port forwarding requires the port is actually free on your host machine. Hence I find it very useful to add an IP to your host’s network interface specifically for the VM so you don’t have port conflicts. In this example I added the IP 192.168.16.201 on my interface:
So there’s the “L – Linux” done. Now for the Apache, Mysql and Php, it can simply be done by using Ubuntu’s apt-get package manager:
- Open a terminal / SSH session to your Ubuntu machine
- Elevate into root using sudo su root
- apt-get install apache2
- apt-get install php5
- apt-get install mysql-server mysql-client
Few helpful notes:
- Default doc root is /var/www
- To start / stop apache: sudo service apache2 stop / sudo service apache2 start
- To start / stop mysql: sudo service mysql stop / sudo service mysql start
Any apache httpd installation comes with ab tool on the bin folder. This handy tool can be used to perform benchmark testing:
ab -n 10 -c 2 http://www.mycoolwebsite.com/
The output you get is quite self-describing:
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.vantagefx.com (be patient).....done
Server Software: Apache
Server Hostname: www.mycoolwebsite.com
Server Port: 80
Document Path: /
Document Length: 29320 bytes
Concurrency Level: 2
Time taken for tests: 4.524 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 297360 bytes
HTML transferred: 293200 bytes
Requests per second: 2.21 [#/sec] (mean)
Time per request: 904.890 [ms] (mean)
Time per request: 452.445 [ms] (mean, across all concurrent requests)
Transfer rate: 64.18 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.3 0 4
Processing: 806 887 90.4 852 1063
Waiting: 804 885 90.4 850 1061
Total: 806 887 91.3 852 1067
Percentage of the requests served within a certain time (ms)
100% 1067 (longest request)
If you want to test https (SSL) page, make sure you have a version of Apache httpd with ssl support, and use abs instead.