Next Previous Contents

4. Setting up

Now that you have the 3 php files and the .csv database file, it's time to do the setup.

You need to either create a new directory on your system or use an existing one. The directory must be accessible to your web server just like any other file that is used on your website. I personally prefer a new directory just to help prevent clutter and to keep organized. So, from a command line prompt, I cd to a location somewhere on my system that is part of the web site and do:

mkdir country

Whatever suits you is fine, the programs themselves don't care where the directory is or what you name it. Just be sure to put all of the files included in this package and the .csv database file in the same directory. Note: If you are only going to use the "iptocountry.php" program, you can do the installation from a web-based admin utility such as CPanel or VDeck, etc. You can also install the entire package from a web-based admin utility as well, however, the part where you will configure the kernel's iptables functionality will have to be done from a command line prompt. If you're doing this on a computer where you have direct physical contact, then you will have no problem at all with the installation since you have full control over your computer.

4.1 Check permissions

You proably already know about this stuff, but some people still have trouble with it. This example is how I had to do it on my system. After creating the directory I wanted to use I assigned the correct permissions to it so that the Apache web server could have access to it and be able to write files within the directory. This example assumes the directory is called 'country'. From a command line prompt, 'cd' to the parent directory where 'country' resides. Since I just created the new directory, I'm already where I need to be and issue the following command:

chmod 775 country

On some systems, 755 might work and some might be OK with 744. But 775 should always work, provided the directory is also 'owned' by the web server or belongs to a group that is assigned to it. Just to make sure things will work, I always assign the directory with the web server as the owner and the group. On my Debian system, the Apache server is known as "www-data". So, I do the following:

chown www-data.www-data country

Now, the web server has full read and write access to the 'country' directory. If your web server uses a different name than 'www-data', just change the above command accordingly.

Maybe on your system, your own username will work. You'll find out later when it comes time to create some files.

4.2 Copy the files

Next, use whatever method you normally use for copying files. Copy all of the files included with this package plus the .csv database file into your 'country' directory.

4.3 Initial testing

At this point, only one of the three php files will work, countryiptsetup.php. Don't even try to run countryiptables.php or iptocountry.php yet.

From a web browser, type in the path in the url address bar to point to your country directory and the countryiptsetup.php program. Here's an example:

Naturally, you will substitute "" with the real name of the web site you are using along with the actual path to the countryiptsetup.php file.

A page will display in your browser that says at the top:

"Generate Database Files for countryiptables.php and iptocountry.php"

If the page appears with no error messages, then your combination of web server and php functionality is working at this point. You should see a web page with some text and a single button that can be clicked on. If any error messages were displayed from either your browser, your web server, or php building a page with error messages, then something is wrong and needs to be fixed.

The most likely problem at this point is php isn't working for you. However, if you've downloaded this package with the intentions of using it, I have to assume you already have a functional php system running. If not, check the internet for help on getting it working for you. Getting php working is not the subject of this documentation.

If you received no apparent errors, move on...

Next Previous Contents