How to install libraries for yourself if your host won’t

If you are working on building your own browsergame, you may not want to shell out the cash for an actual hosting package straight away – preferring instead to work with free hosting until your game is a little closer to completion.

However, one of the downsides to using a free hosting service is that typically there isn’t a support team – or if there is, they are unwilling or unable to install extra modules for you as neccessary. In that sort of situation, you are left installing things like Smarty or HTML::Template on your own.

Thankfully, this is actually a fairly simple process. First, you need to download the code for whichever library you would like to install. Then, you need to upload the library’s source code to a location on your language’s path. The path varies from system to system – this will tell you what it is:

PHP:

<?php
 phpinfo();
?>

Perl:

1
2
3
4
5
6
7
8
#!/usr/bin/perl -w
 
use CGI qw(:cgi);
my $q = new CGI;
print $q->header();
foreach my $dir(@INC) {
	print "$dir<br />";
}

Save whichever piece of code is applicable to you into a file on your server, and then navigate to it – the PHP file will display as much information about your environment as it can, and the Perl script will display the contents of @INC(which is Perl’s include path). In the PHP case, you need to find the variable ‘include_path’ – it’s value will tell you which directories are searched for library code when a PHP file is executed. In Perl’s case, each of the directories listed in @INC is a location that will be searched.

If you do not have access to any of the locations on your path, you can easily modify your path to include locations you do have access to – using PHP’s set_include_path, and Perl’s lib module. Here’s how you’d modify your path in either language:

PHP:

<?php
	set_include_path('/your/home/directory/lib');
	# your code goes here!
?>

Perl:

#!/usr/bin/perl -w
 
use lib '/your/home/directory/lib';
# your code goes here!

If you aren’t sure where your home directory is, you can easily figure that out too:

PHP:

<?php
echo $_SERVER['DOCUMENT_ROOT'];
?>

Perl:

#!/usr/bin/perl -w
 
use CGI qw(:cgi);
my $q = new CGI;
print $q->header();
print $ENV{DOCUMENT_ROOT};

The DOCUMENT_ROOT environment variable will give you the absolute path to the location where all of the files visible to the internet from your hosting account live. You can use that value to determine exactly where you should put your files – although I recommend putting them in a /lib directory directly underneath your DOCUMENT_ROOT.

It should be noted here that you could dynamically modify your path(because DOCUMENT_ROOT is an environment variable, after all) – however, this is not recommended. That’s because if you are dynamically modifying your DOCUMENT_ROOT and it changes for whatever reason, all of your includes are now broken – so most people make it easier for themselves by simply hard-coding the path to their extra libraries.

This method for adding modules and packages yourself doesn’t have to only be used for Smarty or HTML::Template, also – you can use it to install any extra libraries that you need.

Wish there was more?

I'm considering writing an ebook - click here.

.

Luke is the primary editor of Building Browsergames, and has written a large portion of the articles that you read here. He generally has no idea what to say when asked to write about himself in the third person.

Tags: , , , ,

Thursday, November 20th, 2008 code
blog comments powered by Disqus

About

Building Browsergames is a blog about browsergames(also known as PBBG's). It's geared towards the beginner to intermediate developer who has an interest in building their own browsergame.

Sponsors

Got Something to Say?

Send an e-mail to luke@buildingbrowsergames.com, or get in touch through Twitter at http://twitter.com/bbrowsergames