If you just installed Mautic in 2020, you might have noticed the Maxmind IP lookup doesn’t seem to work anymore. That’s because Maxmind has changed the method to obtain the latest updated databases from them.
The difference is simple, now you need to provide your credentials, but it completely changes the process to update your IP database.
In this post you’ll find 5 simple steps to fix the Maxmind Geolite2 and GeoIP issue in under 10 minutes, so you can make your Mautic installation compliant with the new process and automate obtaining the Geolite2 database for your Mautic installation.
NOTE: This entire blog is dedicated to Mautic and other FOSS Marketing software, however, this particular post should work perfectly fine for any Linux based server using the MaxMind GeoLite2 or GeoIP databases as the provided instructions don’t use any of the Mautic code at all.
This guide will work best with Ubuntu and most Debian derivatives, but non-Ubuntu users might need to adapt here and there.
This issue is not going to bring your server down or cause any big problems, however, it affects every single Mautic installation out there, so it really is a good idea to fix it ASAP.
If you are using the data provided by Maxmind GeoLite2 on your campaigns, for example to filter by country or city, or if you use it in your reports, then it is imperative that you follow this process immediately so your campaigns keep working flawlessly and your reports are kept accurate.
If on the other hand, you have been running your Mautic installation for a while, you probably haven’t noticed any problems, that’s because you already have the database on your server, so everything seems to be running fine, however, your database is already old and will get older over time unless you update it again.
This probably isn’t a great deal of a problem, as the IP database doesn’t change that much or that quickly, but you certainly want it updated, cause over time the changes will start cumulating and you would be getting the wrong countries and cities for your contacts.
I saw this method first on the Mautic forums, so Kudos and a big thank you to @atulcj for providing this solution on the forums.
Now I’m gonna give you a more detailed, step by step, process to do this so anyone can do it in just a few minutes.
Here are the steps I used that worked like a charm:
- Create an account on Maxmind.
- Download the configuration file from the Maxmind Website.
- Install GeoLite2 on your server.
- Run the geoipupdate script once manually to make sure everything is working fine.
- Add the new command to your cron jobs and remove the old command.
Let’s get down to it:
Step 1: Create an account on Maxmind
The first step is to go to the signup page on the Maxmind website and create a new account for GeoLite2.
Right after you fill the form, you will receive an email from MaxMind with a bunch of links.
Your attention will probably go straight to this line:
1. Access your MaxMind account.
Do not click this link yet. First, you need to click on the link for creating a new password!
You might want to save the key for your account somewhere safe.
After you fill in your password, you will be presented with a msg: ” Your password has been updated. ” and with a link to login, now you can go ahead and log in using that link that was just presented to you…
Once logged in you will see a large blue menu to the left, scroll down if needed and click on the menu item titled “My License Key”
Step 2: Generate a new License Key and Download the configuration file
You will be presented with the Key Generation form, fill it in as follows:
#1 Add any name you wish for your key.
#2 Select to generate a key for 3.1.1 or later.
After confirming you will be shown your key, take good note of this key as it will be shown to you only once.
And finally, click on the “Download Config” button.
You will be prompted to download the file GeoIP.conf, save that file for later reference, we will need it to configure our server in a minute.
Step 3: Install GeoIP 2 on your server
You should now SSH to your server, we will install the “geoipupdate” software from MaxMind.
Let’s start by gaining sudo privileges for the rest of the session:
Now add the MaxMind Repository to our server:
You should update your server to make sure you have the latest packages installed
And finally, you can install the geoipupdate script.
apt install geoipupdate
Before you can run the geoipupdate script, you’ll have to edit the configuration file residing on the server and add our own credentials.
You have two ways of doing this:
a) Open the file called GeoIP.cong which is already on your server and copy the contents from the GeoIP.conf file you downloaded to your PC to your server.
This command will launch a text editor. If the file is empty, just copy and paste the contents of GeoIP.conf inside the text editor and press ctrl+x to save the file and exit the tex editor.
If there is some content in the file delete everything first and then paste the contents from the file you just downloaded from the Maxmind website.
b) Just copy the file from your computer to your server using FTP or SFTP, just make sure you store this file inside the /etc directory
For NON Ubuntu users ONLY: The directory where your config file is stored MIGHT be different in your case.
You can run the following command and it will tell you (among many other things) where your configuration file is stored:
Most ptobably it will be at /usr/local/etc/GeoIP.conf
Step 4: Run the geoipupdate script manually
We are finally ready to update our MaxMind GeoLite database!
First we need to make sure the directory ip_data exists or create it if not.
If that command succeeds, you can now execute the geoipupdate script below.
If the cd command fails, create the directory first with:
NOTE: If you already had a previously existing database (for example if you are patching an existing Mautic instance instead of installing a new one) you might get an error, if so, delete the old files and try again.
You need to make this file both usable by the geopipuodate script and also readable by Mautic.
chmod -R 777 /var/www/html/app/cache/ip_data
We are now ready to run the geoipupdate script:
sudo -u daemon geoipupdate -f /etc/GeoIP.conf -d /var/www/html/app/cache/ip_data -v
Because we added the -v option at the end, the script execution will respond with some data about the process and the results.
If you get any error msg, please add a comment below and I’ll help you troubleshoot.
Your database is now updated and Mautic can read it…
Step 5: Automate the database update using a cron job.
In order to automate this process in the future, we can use a cron job to run the command we just issued manually on a regular basis.
This will launch your text editor so you can edit the contents of your crontab. If this is the first time you do so, it will prompt you to choose which text editor you want to use (Nano being the simplest to use).
Look for an existing line with the old command to update the database, it should look something like this:
11 3 * * * php /var/www/html/app/console mautic:iplookup:download
Remove that line or comment it out. This is important because if you use the old line it will delete your GeoLite2 database.
Now add the new line:
11 3 * * * sudo -u daemon geoipupdate -f /etc/GeoIP.conf -d /var/www/html/app/cache/ip_data
And that’s it, your database should be automatically updated from now on…
If you kept the exact timings I used for the cron, the database will be updated every day at 3:11 AM.
If you want the changes to be applied Immediately, you can delete the Mautic Cache directory or trigger the update from the CLI with:
sudo -u www-data php /var/www/html/app/console cache:clear
OH! and make sure NOT to click the “Update database” button on the Mautic UI, if you do you will delete the database.
That’s it folks, happy country and city filtering and enjoy your updated databases!
Do you think the Mautic UI should be fixed so anyone can do this from the UI or maybe the entire section should be removed from the UI and let the System Administrator configure it?
Please share your opinion in the comments below!
If you have any question, remark, observation, positive criticism, negative criticism (the most valuable to me) Please comment below!
Hi, thank you for reading this article, hope you found it useful.
My name is Yosu Cadilla, I’ve been both a Marketer since 1996 and a Systems Administrator since 2000, switching back and forth and mixing both trades. Since discovering Mautic, I’ve been specializing in large Mautic deployments as well as Mautic for agencies. Nowadays all my clients are Mautic related.
If you are planning on deploying Mautic on a large scale, or if you are undecided about Mautic being a good fit for your organization… let’s have a chat! email@example.com