Install latest SQLite version on shared hosting server

eeintech   Database   June 18, 2020


cpanel django jailshell passenger python sqlite

On your shared hosting plan, you might have noticed that the versions of the different SQL database options are pretty old. For instance, if you have tried to install Django and ran it using the default SQLite database, you may have gotten this error:

$ python manage.py migrate
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

And indeed, checking the SQLite version, you'll find out it is very outdated (SQLite 3.7.17 was released on 2013-05-20):

$ sqlite3 --version
3.7.17


The solution is to install a newer version of SQLite, except that on a shared server, you do not have root access (for obvious reason) and any traditional install methods won't work. So you may have been wondering: how to install a newer version of SQLite without root access rights?

Well, it's actually much simpler than it sounds!

Let's jump right in:

1/ Download the latest SQLite version and extract it (you can check the SQLite download page for the latest version and update the commands with the actual version number):

$ cd ~
$ wget https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz
$ tar xvfz sqlite-autoconf-3310100.tar.gz

2/ Configure and install the new version of SQLite in the .local folder (the last command may take a while to run):

$ cd sqlite-autoconf-3310100
$ ./configure --prefix=$HOME/.local
$ make && make install

3/ Tell the server where to look for the new SQLite version:

$ echo "alias sqlite3="$HOME/.local/bin/sqlite3"" >> ~/.bashrc
$ echo "export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
$ source ~/.bashrc

4/ The previous step remapped the sqlite3 shell command to point to the new installation so let's verify it:

$ sqlite3 --version
3.31.1

5/ In step 3, we've also declared where to look for the SQLite libraries when imported in Python, so let's verify Python is loading the right SQLite version (make sure the python command points to a Python3 version):

$ python -c 'import sqlite3; print(sqlite3.sqlite_version)'
3.31.1

If it's still showing the old version, make sure to check that the LD_LIBRARY_PATH environment variable in your .bashrc file points to the SQLite library folder (in this case .local/lib).

You can now enjoy the benefits of the latest SQLite version, in the case where your Python (or other languages) application runs only locally on the server. However, if you plan on running it using a production server like Passenger, keep on reading.

Production setup

Depending on your hosting service, you may have to link the LD_LIBRARY_PATH environmental variable to the server you are using in production (or add it directly in your .htaccess file). For instance on shared hosting plans using cPanel, the Phusion Passenger server runs your Node.js, Ruby or Python applications so it needs to be aware of the new value of the LD_LIBRARY_PATH environmental variable. In cPanel, it is is a very simple setup:

  • navigate to the application settings (to create or edit Python environments for Passenger, type python in the search bar and hit enter)
  • create or edit a Python environment, go to the bottom of the settings, and add the variable:
  • click the "Save" button on the top-right corner
  • in the case the Passenger server was already running, restart it (click "Restart" button).

And that's all there is, the Passenger server is now aware of the LD_LIBRARY_PATH environmental variable and knows how to import the latest SQLite version, enjoy!