Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowfalsalahudeen/5d9cd742903bb78cf864d27dd6ddb170 to your computer and use it in GitHub Desktop.
Save nowfalsalahudeen/5d9cd742903bb78cf864d27dd6ddb170 to your computer and use it in GitHub Desktop.
How to install Thumbor
# First, install all of the things
sudo su
apt-get update
apt-get install nginx
/etc/init.d/nginx start
apt-get install python-dev
apt-get install python-pip
apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libgtk2.0-dev python-numpy python-pycurl libwebp-dev python-opencv libjpeg-progs
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
pip install pillow
pip install thumbor
pip install git+https://github.com/Supervisor/supervisor
mkdir /home/logs
# Install JPEG Archive
sudo apt-get install build-essential autoconf pkg-config nasm libtool
git clone https://github.com/mozilla/mozjpeg.git
cd mozjpeg
autoreconf -fiv
./configure --with-jpeg8
make
sudo make install
sudo ln -s /opt/mozjpeg/lib64/ /opt/mozjpeg/lib
cd ..
git clone https://github.com/danielgtaylor/jpeg-archive.git
cd jpeg-archive
make
sudo make install
# https://pngquant.org/install.html
cd ..
git clone --recursive https://github.com/kornelski/pngquant.git
cd pngquant
make
sudo make install
cd ..
rm -rf pngquant
git clone https://github.com/kohler/gifsicle.git
cd gifsicle
./bootstrap.sh
./configure
make
make install
cd ../
rm -rf gifsicle/
# Install imageMagick as prerequisite for imgmin
sudo wget -nH -nd ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
sudo gzip -dc ImageMagick.tar.gz | sudo tar xvf -
cd ImageMagick-7.0.7-36/
sudo ./configure
sudo make -j2
sudo make install
sudo ldconfig /usr/local/lib
make check # need to confirm all your imageMagick tests pass
# Brutal hack to get imgmin installed (powers the C_INCLUDE_PATH hack below)
sudo apt-get install libmagickcore-dev libmagickwand-dev
mkdir /usr/local/include/magick
cp /usr/local/include/ImageMagick-7/MagickCore/magick-baseconfig.h /usr/local/include/magick
# Imgmin (prerequisite if you want to use Auto plugin https://github.com/thumbor/thumbor-plugins/wiki/Auto)
sudo apt-get install -y autoconf libmagickwand-dev pngnq pngcrush pngquant
git clone https://github.com/rflynn/imgmin.git
cd imgmin
autoreconf -fi
./configure
sudo C_INCLUDE_PATH=/usr/include/ImageMagick-6/ PKG_CONFIG_PATH=/opt/ImageMagick/lib/pkgconfig/ make
sudo make install
# Install thumbor-plugins
pip install https://github.com/thumbor/thumbor-plugins/archive/master.zip
# If you want svg support. Confirm it is working by opening python console and "import cairosvg"
apt-get install python-cairosvg
# Find you thumbor.conf "find / . -name thumbor.conf" and copy to /etc/thumbor.conf
# Then configure thumbor at /etc/thumbor.conf
# if terminal is unreadable put "set background=dark" in .vimrc
DETECTORS = [
'thumbor.detectors.face_detector',
'thumbor.detectors.feature_detector'
]
FILTERS = [
'thumbor.filters.quality',
'thumbor.filters.no_upscale',
'thumbor.filters.blur',
'thumbor.filters.strip_icc',
'thumbor.filters.max_bytes',
'thumbor.filters.format'
]
OPTIMIZERS = [
'thumbor_plugins.optimizers.pngquant',
'thumbor_plugins.optimizers.mozjpeg'
]
USE_GIFSICLE_ENGINE = True
PNGQUANT_PATH = '/usr/local/bin/pngquant'
GIFSICLE_PATH = '/usr/local/bin/gifsicle'
JPEGRECOMPRESS_PATH = '/usr/local/bin/jpeg-recompress'
MAX_AGE = 360 * 60 * 24 * 365
AUTO_WEBP = True
# Don't forget to uncomment these or else your webp will be big
QUALITY = 85
WEBP_QUALITY = 80
SECURITY_KEY = 'putsomethinghere'
ALLOW_UNSAFE_URL = False
STORAGE_EXPIRATION_SECONDS = 60 * 60 * 24 * 365
RESULT_STORAGE_EXPIRATION_SECONDS = 60 * 60 * 24 * 365
# Then configure supervisor at /etc/supervisord.conf
[supervisord]
[program:thumbor]
command=thumbor --conf="/etc/thumbor.conf" --port=800%(process_num)s
process_name=thumbor800%(process_num)s
numprocs=4
autostart=true
autorestart=true
startretries=3
stopsignal=TERM
stdout_logfile=/home/logs/thumbor800%(process_num)s.stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stderr_logfile=/home/logs/thumbor800%(process_num)s.stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
$ supervisord -c /etc/supervisord.conf
# confirm thumbor is up
# ps -ef | grep thumbor
# Then configure nginx at /etc/nginx/sites-available/thumbor
upstream thumbor {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
server {
listen 80;
server_name localhost;
location / {
add_header Access-Control-Allow-Origin *;
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;
}
}
# Then move the thumbor site to sites-enabled
$ ln -s /etc/nginx/sites-available/thumbor /etc/nginx/sites-enabled/thumbor
# Finally, start nginx
$ service nginx start
# confirm
# ps -ef | grep nginx
# hit domain and you should see "Welcome to nginx!"
# if nginx fails do "journalctl -xn | less" so you can see wrap. If you see error about server_names_hash_bucket_size
# double the size in nginx.conf
# Test thumbor is working
# hit <domain>/healthcheck and you should see WORKING!
# If you ever need to debug, stop supervisor and start thumbor manually
# /usr/local/bin/thumbor -p 8000 -c /etc/thumbor.conf -l debug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment