In today’s digital landscape, efficient image processing and optimization are crucial for delivering engaging web experiences. Thumbor, an open-source image manipulation service, empowers developers to resize, crop, and enhance images dynamically. This article will provide you with a comprehensive step-by-step guide on how to install and config Thumbor on a Debian 10 system. By the end of this guide, you’ll have a fully operational Thumbor instance ready to optimize and transform images for your web applications.
This post explains how to install Thumbor on your own server. Once installed, you can use Thumbor as an API to transform your images, we will install on AWS EC2 server and integrate it with AWS S3 to deliver the images as quickly as possible and save the transformations.
Table of Contents
Importance of Image Optimization
In today’s visually-oriented online landscape, website performance hinges significantly on effective image optimization. Optimized images load swiftly, leading to enhanced user experiences and elevated search engine rankings. Enter Thumbor, an influential image manipulation service that simplifies the image transformation process. Thumbor guarantees that images are rendered in formats and sizes best suited for each specific use case, ultimately bolstering the overall user experience.
Prerequisites
Before we dive into the installation process, there is prerequisite you need to ensure are in place:
- Debian : Make sure you have a clean installation of Debian 10 or 11. To set this up, follow our guide Initial Setup Debian 11 Server: Secure and Efficient. You can deploy this on a physical machine or a virtual environment like VMware or VirtualBox.
- Access to Terminal: Familiarity with the command-line interface is essential, as the installation process involves executing commands.
- Python and Pip: Thumbor is built using Python. Make sure Python and Pip (Python package installer) are installed on your system.
First of all, we are going to launch an VM with Debian 10 64-bit (x86), I used 4 core 4GB but you can choose the one that best suits your needs.
Install Thumbor and Config on Debian 10
Let’s proceed with installing Thumbor on your Debian 10 system:
Step 1: System Update
Before diving into the installation process, it’s essential to ensure your Debian 11 system is up-to-date. Open a terminal and run the following commands:
samm@thumbor:~$ sudo apt-get update
samm@thumbor:~$ sudo apt-get upgrade
Step 2: Install Thumbor Dependencies
Thumbor relies on several external libraries. Install them using the following commands:
- Now we need to install pip, the package manager for Python. Later you’ll install Thumbor with pip.
samm@thumbor:~$ sudo apt-get install -y python-pip
- SSL Packages
samm@thumbor:~$ sudo apt-get install -y libcurl4-openssl-dev libssl-dev
- Computer Vision Packages
samm@thumbor:~$ sudo apt-get install -y python-opencv libopencv-dev
- Image Format Packages
samm@thumbor:~$ sudo apt-get install -y libjpeg-dev libpng-dev libwebp-dev webp
Step 3: Install Thumbor on Debian 10
Now, install Thumbor using pip, the Python package manager:
samm@thumbor:~$ sudo pip install thumbor
Collecting thumbor
Downloading https://files.pythonhosted.org/packages/fb/16/3b0546ff743f11db7b0717feefeee8c772fb8b6e2eb3c9fd89054375f519/thumbor-6.7.5.tar.gz (27.3MB)
100% |████████████████████████████████| 27.3MB 26kB/s
Collecting Pillow<7,>=4.3.0 (from thumbor)
Downloading https://files.pythonhosted.org/packages/12/ad/61f8dfba88c4e56196bf6d056cdbba64dc9c5dfdfbc97d02e6472feed913/Pillow-6.2.2-cp27-cp27mu-manylinux1_x86_64.whl (2.1MB)
100% |████████████████████████████████| 2.1MB 389kB/s
Requirement already satisfied: argparse in /usr/lib/python2.7 (from thumbor) (1.2.1)
Collecting derpconf>=0.2.0 (from thumbor)
Downloading https://files.pythonhosted.org/packages/6f/34/9277afa018c59861c5c1e6455a27866ab6475f4820b09cea22a02c15e4fa/derpconf-0.8.3.tar.gz
Collecting futures (from thumbor)
Downloading https://files.pythonhosted.org/packages/d8/a6/f46ae3f1da0cd4361c344888f59ec2f5785e69c872e175a748ef6071cdb5/futures-3.3.0-py2-none-any.whl
Collecting libthumbor>=1.3.2 (from thumbor)
Downloading https://files.pythonhosted.org/packages/99/db/28a9bc9088de0971b0a20cd041f3e65fe03e7e303d627de2077a9b7151ee/libthumbor-1.3.2.tar.gz
Collecting pycurl<7.44.0,>=7.19.0 (from thumbor)
Downloading https://files.pythonhosted.org/packages/ef/05/4b773f74f830a90a326b06f9b24e65506302ab049e825a3c0b60b1a6e26a/pycurl-7.43.0.5.tar.gz (216kB)
100% |████████████████████████████████| 225kB 1.9MB/s
Collecting pytz (from thumbor)
Downloading https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl (510kB)
100% |████████████████████████████████| 512kB 983kB/s
Requirement already satisfied: six in /usr/lib/python2.7/dist-packages (from thumbor) (1.12.0)
Collecting statsd>=3.0.1 (from thumbor)
Downloading https://files.pythonhosted.org/packages/47/33/c824f799128dfcfce2142f18d9bc6c55c46a939f6e4250639134222d99eb/statsd-3.3.0-py2.py3-none-any.whl
Collecting tornado<6.0.0,>=4.1.0 (from thumbor)
Downloading https://files.pythonhosted.org/packages/e6/78/6e7b5af12c12bdf38ca9bfe863fcaf53dc10430a312d0324e76c1e5ca426/tornado-5.1.1.tar.gz (516kB)
100% |████████████████████████████████| 522kB 965kB/s
Collecting webcolors (from thumbor)
Downloading https://files.pythonhosted.org/packages/8b/ff/c21df7e08e68a1a84b947992c07dfed9cfe7219d068cb7728358d065c877/webcolors-1.10-py2.py3-none-any.whl
Collecting backports_abc>=0.4 (from tornado<6.0.0,>=4.1.0->thumbor)
Downloading https://files.pythonhosted.org/packages/7d/56/6f3ac1b816d0cd8994e83d0c4e55bc64567532f7dc543378bd87f81cebc7/backports_abc-0.5-py2.py3-none-any.whl
Collecting singledispatch (from tornado<6.0.0,>=4.1.0->thumbor)
Downloading https://files.pythonhosted.org/packages/3f/09/2a17c6505a8373229cb3de6161e3af74ff90afcf4516719aa6cf32fad151/singledispatch-3.7.0-py2.py3-none-any.whl
Building wheels for collected packages: thumbor, derpconf, libthumbor, pycurl, tornado
Running setup.py bdist_wheel for thumbor ... done
Stored in directory: /root/.cache/pip/wheels/2d/c6/73/93e9df15a21666ae551b31b735ff675c34a638da52de0d0b03
Running setup.py bdist_wheel for derpconf ... done
Stored in directory: /root/.cache/pip/wheels/f3/61/69/bb52524c85d2082e9633b65cd02f1dde469c5a4a925689bd71
Running setup.py bdist_wheel for libthumbor ... done
Stored in directory: /root/.cache/pip/wheels/08/af/cd/747e7902b920de6dc8800fa609f46af09c4f105396bd874977
Running setup.py bdist_wheel for pycurl ... done
Stored in directory: /root/.cache/pip/wheels/98/a3/19/9439c79b88a742f508af0c4e410ae3f685db2e13d3374e798e
Running setup.py bdist_wheel for tornado ... done
Stored in directory: /root/.cache/pip/wheels/6d/e1/ce/f4ee2fa420cc6b940123c64992b81047816d0a9fad6b879325
Successfully built thumbor derpconf libthumbor pycurl tornado
Installing collected packages: Pillow, derpconf, futures, libthumbor, pycurl, pytz, statsd, backports-abc, singledispatch, tornado, webcolors, thumbor
Successfully installed Pillow-6.2.2 backports-abc-0.5 derpconf-0.8.3 futures-3.3.0 libthumbor-1.3.2 pycurl-7.43.0.5 pytz-2021.1 singledispatch-3.7.0 statsd-3.3.0 thumbor-6.7.5 tornado-5.1.1 webcolors-1.10
To see if Thumbor installed correctly this should work:
samm@thumbor:~$ thumbor --help
usage: thumbor [-h] [--version] [-p PORT] [-i IP] [-f FD] [-c CONF]
[-k KEYFILE] [-l LOG_LEVEL] [-a APP] [-d]
[--use-environment USE_ENVIRONMENT]
thumbor server
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-p PORT, --port PORT The port to run this thumbor instance at [default:
8888].
-i IP, --ip IP The host address to run this thumbor instance at
[default: 0.0.0.0].
-f FD, --fd FD The file descriptor number or path to unix socket to
listen for connections on (--port and --ip will be
ignored if this is set)[default: None].
-c CONF, --conf CONF The path of the configuration file to use for this
thumbor instance [default: None].
-k KEYFILE, --keyfile KEYFILE
The path of the configuration file to use for this
thumbor instance [default: None].
-l LOG_LEVEL, --log-level LOG_LEVEL
The log level to be used. Possible values are: debug,
info, warning, error, critical or notset. [default:
warning].
-a APP, --app APP A custom app to use for this thumbor server in case
you subclassed ThumborServiceApp [default:
thumbor.app.ThumborServiceApp].
-d, --debug Debug mode [default: False].
--use-environment USE_ENVIRONMENT
Use environment variables for config
Now, let’s initiate Thumbor’s debug server to facilitate request handling and testing.
Test :
http://172.32.1.50:8888/unsafe/500×500/thumb.sahijab.com/media/frontend/images/2021/08/25/61260d60ce7d7-sammlinux.jpg
Step 4: Config Thumbor to Run in Background
samm@thumbor:~$ cd /lib/systemd/system
samm@thumbor:/lib/systemd/system$ sudo touch thumbor.service
samm@thumbor:/lib/systemd/system$ sudo nano thumbor.service
[Unit]
Description=Thumbor
Documentation=https://thumbor.readthedocs.io/en/latest/
After=network.target
[Service]
ExecStart=/usr/local/bin/thumbor
Restart=on-failure
[Install]
WantedBy=multi-user.target
samm@thumbor:~$ sudo systemctl enable thumbor.service
Created symlink /etc/systemd/system/multi-user.target.wants/thumbor.service → /lib/systemd/system/thumbor.service.
samm@thumbor:~$ sudo systemctl start thumbor.service
samm@thumbor:~$ sudo systemctl status thumbor.service
● thumbor.service - Thumbor
Loaded: loaded (/lib/systemd/system/thumbor.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-08-26 11:26:42 PDT; 13s ago
Docs: https://thumbor.readthedocs.io/en/latest/
Main PID: 13125 (thumbor)
Tasks: 1 (limit: 4700)
Memory: 25.6M
CGroup: /system.slice/thumbor.service
└─13125 /usr/bin/python /usr/local/bin/thumbor
Agu 26 11:26:42 thumbor systemd[1]: Started Thumbor.
Step 5: Config Thumbor to S3
Create the S3 buckets, the next step involves uploading an image to the source S3 bucket solely for testing purposes. Once this is done, return to the server terminal. Here, we will execute the following command to generate a new “thumbor.conf” file:
samm@thumbor:~$ thumbor-config > ./thumbor.conf
Now, the installation of Boto3 for managing AWS authentication and the AWS S3 Plugin requires your attention. Simply execute the following commands to proceed:
samm@thumbor:~$ pip install boto3
Once boto3 is installed we need to configure our AWS S3 connection to do this are going to create a file for boto3 configuration:
samm@thumbor:~$ mkdir .aws && touch .aws/config && touch .aws/credentials
samm@thumbor:~$ vi .aws/config
[default]
region=ap-southeast-1
samm@thumbor:~$ vi .aws/credentials
[default]
aws_access_key_id = xxxxxxx
aws_secret_access_key = xxxxxxxxxxxx
Then we have to install Thumbor AWS (https://github.com/thumbor-community/aws)
samm@thumbor:~$ pip install tc_aws
Open your thumbor.conf file created earlier, there are a lot of options but for now, we are going to focus only on the TC_AWS section (This section doesn’t exist in the default config and you’ll need to add it somewhere).
samm@thumbor:~$ vi thumbor.conf
############################## TC_AWS ##########################################
TC_AWS_REGION = 'ap-southeast-1' # AWS Region
TC_AWS_ENDPOINT = None # Custom S3 endpoint URL (for GCP, Minio, etc.)
TC_AWS_STORAGE_BUCKET = 'thumb.sammlinux.com' # S3 bucket for Storage
TC_AWS_STORAGE_ROOT_PATH = 's3://thumb.sammlinux.com/media/frontend/images/' # S3 path prefix for Storage bucket
TC_AWS_LOADER_BUCKET = 'thumb.sammlinux.com' #S3 bucket for loader
TC_AWS_LOADER_ROOT_PATH = 's3://thumb.sammlinux.com/media/frontend/images/' # S3 path prefix for Loader bucket
TC_AWS_RESULT_STORAGE_BUCKET = 'thumbor-samm' # S3 bucket for result Storage
TC_AWS_RESULT_STORAGE_ROOT_PATH = 's3://thumbor-samm/sammlinux/' # S3 path prefix for Result storage bucket
# put data into S3 using the Server Side Encryption functionality to
# encrypt data at rest in S3
# https://aws.amazon.com/about-aws/whats-new/2011/10/04/amazon-s3-announces-server-side-encryption-support/
TC_AWS_STORAGE_SSE = False
# put data into S3 with Reduced Redundancy
# https://aws.amazon.com/about-aws/whats-new/2010/05/19/announcing-amazon-s3-reduced-redundancy-storage/
TC_AWS_STORAGE_RRS = False
# Enable HTTP Loader as well?
# This would allow you to load watermarks in over your images dynamically through a URI
# E.g.
# http://your-thumbor.com/unsafe/filters:watermark(http://example.com/watermark.png,0,0,50)/s3_bucket/photo.jpg
TC_AWS_ENABLE_HTTP_LOADER = False
TC_AWS_ALLOWED_BUCKETS = False # List of the allowed bucket to be requested
TC_AWS_STORE_METADATA = False # Store result with metadata (for instance content-type)
################################################################################
Now we have to uncomment and edit these lines on the thumbor.conf file:
samm@thumbor:~$ vi thumbor.conf
## Defaults to: 'thumbor.loaders.http_loader'
LOADER = 'tc_aws.loaders.s3_loader'
## Defaults to: 'thumbor.storages.file_storage'
STORAGE = 'thumbor.storages.no_storage'
## Defaults to: None
RESULT_STORAGE = 'tc_aws.result_storages.s3_storage'
And finally, we have to set as RESULT_STORAGE_STORES_UNSAFE = True option to save thumbor results in our results bucket.
Now we have to uncomment and edit these lines on the thumbor.conf file:
samm@thumbor:~$ vi thumbor.conf
################################ Result Storage ################################
## Indicates whether unsafe requests should also be stored in the Result Storage
## Defaults to: False
RESULT_STORAGE_STORES_UNSAFE = True
Then we need to restart the Thumbor service so that it takes the new settings, write the next command on your server command line:
samm@thumbor:~$ sudo systemctl restart thumbor.service
samm@thumbor:~$ sudo ufw allow 8888/tcp
Rule added
Rule added (v6)
Test :
http://172.32.1.50:8888/unsafe/500×500/thumb.sammlinux.com/media/frontend/images/2023/08/25/61260d60ce7d7-sammlinux.jpg
Step 6: Install Nginx to Reserve Proxy Thumbor
samm@thumbor:~$ sudo apt install nginx
samm@thumbor:~$ sudo ufw allow 'Nginx HTTP'
Rule added
Rule added (v6)
samm@thumbor:~$ sudo ufw allow 'Nginx HTTPS'
Rule added
Rule added (v6)
samm@thumbor:~$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-08-26 12:32:01 PDT; 3min 24s ago
Docs: man:nginx(8)
Main PID: 13741 (nginx)
Tasks: 5 (limit: 4700)
Memory: 5.6M
CGroup: /system.slice/nginx.service
├─13741 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─13742 nginx: worker process
├─13743 nginx: worker process
├─13744 nginx: worker process
└─13745 nginx: worker process
Agu 26 12:32:01 thumbor systemd[1]: Starting A high performance web server and a reverse proxy server...
Agu 26 12:32:01 thumbor systemd[1]: Started A high performance web server and a reverse proxy server.
samm@thumbor:~$ sudo systemctl enable nginx
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx
samm@thumbor:~$ sudo vi /etc/nginx/conf.d/app-thumbor.conf
upstream thumbor {
server 127.0.0.1:8888;
}
server {
listen 80;
server_name thumbor.sammlinux.com;
client_max_body_size 20M;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://thumbor;
proxy_redirect off;
}
}
samm@thumbor:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
samm@thumbor:~$ sudo systemctl restart nginx
Test now with access this link :
https://thumbor.sammlinux.com/unsafe/200×500/https://s3.ap-southeast-1.amazonaws.com/thumb.sammlinux.com/media/frontend/images/2023/08/26/6126dd4ce9c19-sammlinux.jpg
Conclusion
In conclusion, efficient image processing and optimization play a pivotal role in modern web development. With Thumbor, you gain a versatile tool to dynamically manipulate images according to your application’s requirements. This guide has taken you through the installation and configuration process on Debian 10, equipping you with the ability to enhance web experiences through optimized images. By successfully installing and configuring Thumbor, you’re well-prepared to elevate your websites with visually appealing, fast-loading images that captivate users and boost your online presence.
Also Read Our Other Guides :
- How To Install Java Using OpenJDK 17 on Ubuntu 22.04
- How To Install Apache Solr 9.1 on Debian 11
- How To Install Redis on Debian 11 Server
- How To Install RTMP Server with Nginx on CentOS 7
- How To Create AWS CloudFront: A Step-by-Step Guide
Hopefully, now you have learned how to Install and Config Thumbor on Debian 10.