A friend of mine runs a business selling a Windows application for a niche market. Of course he has a web site with lots of information and a way to download a trial of his software and then pay and register it. Since he's a technical person, likes writing code, likes to keep overhead low, and his needs are fairly simple, he wrote the registration program himself. He's most fluent in Delphi so it was natural to write the registration program in Delphi--an old, but very functional Delphi 2007.
So naturally he needed a Windows server and after a little research, decided it wouldn't be that hard to host it himself out of his house. With a static IP address and stable power source, he's had this setup for quite some time with very little trouble.
Well, since he already has a static address and server running, why not host his own web site as well? That's running under Linux. No problem, just add a second server and redirect the ports. (I actually don't know which came first, the web server or the registration server.)
With the business running well and support calls low, he and his wife want to do some traveling. An extended weekend isn't any problem. A week away with someone looking after the place is doable. But what if a server goes down? Will anyone else be able to get it back up? What is the cost of potentially losing a customer because they can't find the web site or register the software?
These questions have been eating at him for a while and he finally decided to move them to a remotely hosted server. But since neither his web site nor his registration program are that heavily used, it would be a waste of resources and money to rent two servers--he should combine them into one. The web site needs to stay on Linux. The registration program, even though it's in Delphi, could be re-written to work under Linux using Free Pascal. And using Lazarus as the IDE, the environment would be familiar. Finally, the Firebird database has no problem moving across platforms.
After looking at several options for remotely hosted virtual servers, it was clear the new Linux server would be running CentOS. Moving the web site over was not going to be difficult, but setting up the database and development environment would take some research. Not being very familiar with commands on Linux, he asked if I could help. Together, we got a virtual machine running CentOS and started the process of figuring out everything needed to get things going.
The first thing installed was the Firebird database engine and TurboBird, a Linux-based database tool that allows manipulation and querying of Firebird databases. We soon ran into problems and so downloaded Lazarus and the source for TurboBird to compile it thinking it may be something specific to our install. This is where the fun began!
I don't remember all the problems we had, but there were missing links to libraries, indications of insufficient permissions, and other error messages, leaving us scratching our heads and wondering if we had bitten off more than we could chew. I told him I'd go into hiding for a couple of days and figure out what was wrong.
What I found is that we were using a 64-bit version of Linux and trying to get a 32-bit version of Firebird and TurboBird working. I should've known to check this near the beginning of the process as I've run into this type of problem in the past trying to get Windows applications to talk to Oracle databases using the wrong driver, but this is a different OS with different software producing different errors--it totally escaped me.
There were other little odd things here and there that needed tidying up. For example, the version of Firebird he is using with his application is a couple of versions behind the current one and it requires an older version of a standard C++ library that is not included by default on the latest CentOS. The service manager, xinetd, needed to be installed and started. And a link to the specific Firebird library needed to be made. These would not be issues on Windows platforms, so it was easy to get tripped up multiple times.
But the thing I love about Linux is that you can run a command line to accomplish just about anything. When I emerged from hiding after a couple of days, I had a bash script that uninstalled the wrong versions of the software, downloaded and installed the right versions, installed git, and downloaded the project I had started. All he had to do was type in a couple of passwords, load the project into the Lazarus IDE, and compile it.
When it was all done, it was very satisfying to run the script and watch the magic happen!
In case anyone is interested in the script I wrote, here are some excerpts.
First of all, it needed to be run as a regular user, not as root. So there was a check for that right at the top:
if [ $EUID -eq 0 ]
echo 'Do NOT run this script as root.
I wanted to make sure the repositories for yum were up to date:
sudo yum -y -q update
yum_priorities_installed=$(rpm -q -a | grep yum-priorities | wc -l)
if [ $yum_priorities_installed -eq 0 ]
sudo yum -y -q install yum-priorities
echo 'yum is up to date'
This next section installs an older version of C++ libraries:
compat_clib_installed=$(rpm -q -a | grep compat-libstdc++ | grep x86_64 | wc -l)
if [ $compat_clib_installed -eq 0 ]
sudo yum -y -q install compat-libstdc++-33.x86_64
I needed xinetd to start the Firebird service:
inet_installed=$(rpm -q -a | grep inetd | wc -l)
if [ $inet_installed -eq 0 ]
sudo yum -y -q install xinetd
sudo service xinetd start
This uninstalled Firebird 32-bit, then downloaded and installed a specific version of Firebird 64-bit and created a link to one of the library files:
fb_installed=$(rpm -q -a | grep Firebird | wc -l)
if [ $fb_installed -eq 1 ]
# is this the 64-bit version of Firebird?
fb64_installed=$(rpm -q -a | grep Firebird | grep amd64 | wc -l)
if [ $fb64_installed -eq 1 ]
echo 'Firebird 64-bit is installed.'
# nope, it's 32-bit; get rid of it!
echo 'Uninstalling Firebird 32-bit'
fb32=$(rpm -q -a | grep Firebird)
sudo rpm -e $fb32
if [ $fb_installed -eq 0 ] || [ $fb64_installed -eq 0 ]
echo 'downloading and installing Firebird 2.1.7 64-bit'
wget -O $HOME/Downloads/FirebirdCS-126.96.36.19953-0.amd64.rpm http://sourceforge.net/projects/firebird/files/firebird-linux-amd64/2.1.7-Release/FirebirdCS-188.8.131.5253-0.amd64.rpm
sudo rpm -i $HOME/Downloads/FirebirdCS-184.108.40.20653-0.amd64.rpm
sudo service xinetd restart
# check to make sure a needed link to a library is created
if [ ! -f /usr/lib64/libfbclient.so.2.1 ]
sudo ln -s /opt/firebird/lib/libfbclient.so.2.1.7 /usr/lib64/libfbclient.so.2.1
Next, the pre-built executable for TurboBird was downloaded and unzipped:
if [ ! -f $HOME/Downloads/TurboBirdLinux64.zip ]
wget -O $HOME/Downloads/TurboBirdLinux64.zip http://code-sd.com/turbobird/TurboBirdLinux64.zip
unzip $HOME/Downloads/TurboBirdLinux64.zip -d $HOME/Desktop/TurboBirdLinux64
And Lazarus was installed as well:
laz32_installed=$(rpm -q -a | grep lazarus | grep i686 | wc -l)
if [ $laz32_installed -eq 1 ]
echo 'Uninstalling Lazarus 32-bit'
sudo rpm -e `rpm -q -a | grep lazarus`
if [ ! -f $HOME/Downloads/lazarus-1.4.0-x86_64.rpm ]
wget -O $HOME/Downloads/lazarus-1.4.0-x86_64.rpm http://downloads.sourceforge.net/project/lazarus/Lazarus%20Linux%20x86_64%20RPM/Lazarus%201.4/lazarus-1.4.0-0.x86_64.rpm
laz64_installed=$(rpm -q -a | grep lazarus | grep x86_64 | wc -l)
if [ $laz64_installed -eq 0 ]
echo 'Installing Lazarus 64-bit'
sudo rpm -i $HOME/Downloads/lazarus-1.4.0-x86_64.rpm
echo 'Lazarus 64-bit already installed'