Set up a cheap Ubuntu server for web development, file serving
and as a platform for hosting Freeciv network multiplayer games over
your home internet connection.
First Step: Find a computer to use as your server. Well, I suppose
most of you will have an old PC in your closet collecting dust, and that'll
probably serve fine, as long as it has a decent processor and a reasonable
amount of RAM.
My first attempt at this, I used an old Dell Inspiron 8100
laptop, which was a bit too slow at 1ghz and 512mb RAM when processing Freeciv turns. It also
had a bad ethernet card and the USB ports were not 2.0 compliant, making the idea of
serving files and games with such a wimpy speed over a wifi connection pretty iffy. So eventually
I turned to a Frankenstein tower that was made up of various spare parts. Frankie
had a bit more ooph - at 1.6ghz and 1gb RAM, Turns processed much snappier and
I could finally attach my USB drives and serve files over a USB 2.0 connection.
Frankie had a problem, though. He'd run fine for a few days and then suddenly develop
a bad habit of spontaneously rebooting over and over for no apparent reason. Sometimes on boot,
he'd not even pass POST and he'd just sit there and beep at me while constantly power cycling.
Needless to say, this put a crimp in my definition of "server", because one expects a server
to be a little more reliable than that. I was faced with either going back to the slow-ass Dell,
somehow figuring out why Frankie was so tempramental and fixing that, or buying another computer
entirely. Sheesh. The whole point of this exercise was to get it done *cheaply*, so my options
were looking pretty thin.
Ebay to the rescue! I started poking around the normal cheap computer sites like NewEgg and Tiger Direct
searching under the "Desktop PC's under $200" categories, and found the pickings fairly thin, but there
were a lot of "out of stock" pages for lease-return refurbished
IBM small form-factor ThinkCentres with
processor speeds between 2.6ghz and 3.2ghz. A quick check on Ebay indicated that there were palletfulls of
these guys being sold for around $120 each with 512mb of RAM and 40gb drives in them. They take DDR1 RAM, so
the 1gb stick I had in Frankie should work with them. Further checking revealed a seller unloading them for
$59 (shipping included!), sans drives, and I was sold. With 8 USB 2.0 ports in it, small form factor and power
consumption and a processor twice as fast as Frankie, it matched all of my requirements.
Second Step: Ubuntu Server or Desktop version? Having attempted this install a few times on
my broken-ass hardware, I had some experience with both versions because I'd tried both and not noticed
much of a speed difference between the two. For my final install on the ThinkCentre, I chose the Desktop version,
just because it's easier to maintain and work with. If you're not super comfortable with the command line only,
then you should pick the Desktop version also. This HowTo assumes that you're using the Desktop version.
Now we get down to the nitty-gritty of installing the software you need and setting it up to do what you want:
(More coming soon...)
- Install Ubuntu Desktop on your spare computer (I used 9.04 RC Jaunty Jackalope).
- Install Apache2/PHP5/MySQL5 using Synaptic Package Manager
- System > Administration > Synaptic Package Manager
- Use the search tool to find the packages for "apache2", "php" and "mysql" and select all dependencies.
make sure you get the GDlib package for PHP, then install the packages.
- Make sure to set up a root password for MySQL when it asks - don't leave it blank.
- Your base webroot will be in /var/www
- Check http://localhost to verify installation. It'll be a page that just says "It works!"
- Install PHPMyAdmin
- sudo apt-get install phpmyadmin
- select Apache2 installation in dialog box.
- Check http://localhost/phpmyadmin to verify installation.
Log in with username "root" and the password you set up previously.
- Set up Apache to serve user's public_html directories [ source ]
- Create a directory called "public_html" in your home directory (/home/your_username/public_html)
- cd /etc/apache2/mods-enabled
- sudo ln -s ../mods-available/userdir.conf userdir.conf
- sudo ln -s ../mods-available/userdir.load userdir.load
- sudo /etc/init.d/apache2 restart
- Now check http://localhost/~your_username to verify that it works. You'll see a simple empty directory listing.
- Set up Ubuntu for static local IP address. [ source ]
- This step may be optional. If your router always assigns your server the same IP from the pool like
mine does (assigning IP to the same NAT address all the time), then you can skip this step.
- "address" is the local IP address you want your server to be. I chose 192.168.2.51
"netmask" is almost always 255.255.255.0
"network" is the base IP of your local network. For mine it's 192.168.2.0
"broadcast" i dunno, but 192.168.2.255 worked for me.
"gateway" is the router's local IP address. Mine is 192.168.2.1
- Set up an account at no-ip.com and install the no-ip client. [ source ]
- Once you've created your account at no-ip.com, log into it.
- set up a port 80 redirect for your web server domain name (i used port 5550)
- set up an A NAME record for your server.
- To install the no-ip client on your Ubuntu server: sudo apt-get install no-ip
- fill in the info asked and select the domains you set up previously.
- Many ISPs and Cable Internet Providers block port 80 and port 8080 to inbound connections.
Luckily, No-IP.com allows you to do a port 80 redirect.
You'll need to change the Apache config to handle the connections to the non-standard port for
web traffic. Alter the apache config to cause Apache to listen to the alternate port.
- sudo pico /etc/apache2/ports.conf
- Add a line "Listen 5550" beneath "Listen 80" and save file.
- sudo pico /etc/apache2/sites-enabled/000-default
- Change "<VirtualHost *:80>" to "<VirtualHost *>" and save file. This will cause Apache to
throw a warning when it starts, but it seems to work fine.
- sudo /etc/init.d/apache2 reload
- Set up your router to direct traffic to your server.
- Point your web browser to your router's web interface.
Please refer to www.portforward.com for
more details on how to do this on your router.
- set up one for the webservice:
Inbound Port: 5550
Private IP: 192.168.2.51
Private Port: 5550
- then set up one for the FreeCiv service:
Inbound Port: 5556
Private IP: 192.168.2.51
Private Port: 5556
- Save your changes and restart your router if needed.
- At this point, you can check to make sure the outside world can now get to your webserver
by checking the urls you set up at no-ip.com - at the web url you should get the standard
Apache "It works!" page.
The FreeCiv url won't work yet because we haven't installed FreeCiv. Let's do that now.
- Create a user called "freeciv", and set up a public_html directory and MySQL database for that user.
- System > Administration > Users and Groups
- Click the "unlock" button and enter your sudo password.
- Click "Add User" button.
- Username and Real Name can both be "freeciv".
- Set and confirm password and click "ok" to add the user.
- Log into your PHPMyAdmin interface at http://localhost/phpmyadmin and create a user called "freeciv".
Select the option that also creates a database with that name and gives the user permissions for it.
- Create a directory called "public_html" in freeciv's home directory. (/home/freeciv/public_html)
- sudo chmod -R 0777 /home/freeciv/public_html
- Install FreeCiv with MySQL Authentication [ source ]
- Open a terminal window in your home directory.
- sudo apt-get install build-essential checkinstall libmysqlclient15-dev mysql-server mysql-admin
- sudo apt-get build-dep freeciv
- wget http://prdownloads.sourceforge.net/freeciv/freeciv-2.1.9.tar.bz2?download
- tar -xvf freeciv-2.1.9.tar.bz2
- cd freeciv-2.1.9
- Now we need to apply a few patches to the Freeciv code to fix some logging issues. [ source ]
- Download this patch, that fixes Bug #13402.
- Download this patch, that grants Wish #13403.
- Download this patch, that fixes Bug #13419.
- put these diff files in your Freeciv source directory.
- patch -p1 < ./ScorelogSpaceship_13402-2.diff
- patch -p1 < ./LogScore_13403.diff
- patch -p1 < ./StartTurnScorelog_13419-S2_1.diff
- Now that we've applied the patches, let's configure and compile!
- ./configure --enable-auth=yes
- if you get "configure: error: could not guess which client to compile",
try installing the "libgtk2.0-dev" package via the Synaptic Package Manager.
- sudo checkinstall -y
- bash scripts/setup_auth_server.sh
- Use "freeciv" as the username and the password you chose for the "freeciv" MySQL user.
- Allow the script to save the password to the config file.
- Now we can test the setup by starting the FreeCiv server: civserver -N -a fc_auth.conf
- Test your setup by launching the FreeCiv client on another computer and connecting to your server
using the URL you set up at no-ip.com, port 5556. If it connects and you can start a game,
- Install GifSicle for the creation of animated gifs.
- sudo apt-get install gifsicle
- sudo apt-get install netpbm
Thanks go to Book and Cazfi, for changes to the Freeciv logging and filenaming code, which helped make this project possible.
Additional Tweaks and Tips:
LongTurn Rulesets: The LongTurn variant of online Freeciv generally uses a timeout period of 24 hours,
plus some additional ruleset changes that help speed up gameplay. You'll need to set up a LongTurn ruleset
directory and a server rules file. If you'd like some examples to start with, you can try ours, which can be downloaded
by selecting one of the more recent games listed to the right.
Suppose you accidentally set a blank string for the savegame filename prefix in your server starting script?
You wouldn't be the only one, because I did it too. It's harder to fix than you think using "rename"
or other bulk file remaing tools, mainly because of the "-" at the beginning of the resulting filenames. It
sets a flag in "mv" and "cp" and it needs to be escaped. Here's a nice shell scriptlet that I found does the
for file in \-*gz; do mv -- "$file" "newprefix`echo $file`"; done