Lychee Image Hosting - Deploy with Docker

Lychee is an opensource image hosting platform written in PHP. It goes hand-in-hand with Ghost, because bloggers need to put images in their posts, but Ghost does not have native in-line image hosting support.

There is a live demo that will allow you to experience its slick and intuitive interface, by making use of:

  • drag-drop to upload files from your computer.
    • This won't happen in the online demo.
  • click-and-drag to make selections
  • right click menus.

One could use a third party image hosting platform, such as Picassa, but I find that it's best not to build houses on other people's land, and it appears Picassa does not support Linux.

Prerequisites

  • A debian based docker host

Install

First we need to update and fetch all the necessary files.

sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get install git -y
git clone https://github.com/electerious/Lychee.git

mkdir data uploads
mkdir uploads/big
mkdir uploads/import
mkdir uploads/thumb

chmod 777 -R data
chmod 777 -R uploads

Configure A Database

Lychee needs a database for the data to remain persistent. If you already have a database, then use that, otherwise, use the script below to automatically install and configure MySQL on your Debian server for Lychee to use.

# Change these if you desire
# You will need to use them again later.
DB_ROOT_PASS=`openssl rand -base64 32`
DB_SUBUSER_PASS=`openssl rand -base64 32`
DB_NAME="lychee"
DB_USER="lychee"

sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $DB_ROOT_PASS"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DB_ROOT_PASS"
sudo apt-get install mysql-server -y

mysql -u root -p$DB_ROOT_PASS -e \
"CREATE DATABASE $DB_NAME"
mysql -u root -p$DB_ROOT_PASS -e \
"GRANT ALL on $DB_NAME.* to `$DB_USER`@`%` identified by '$DB_SUBUSER_PASS'"

clear
echo "Your database root password is:" 
echo "$DB_ROOT_PASS"
echo ""
echo "Lychee's database details are:"
echo "User: $DB_USER"
echo "Pass: $DB_SUBUSER_PASS"

Make sure to write the user details down as you will need to enter them into the web interface later.

I would recommend using MariaDB instead of MySQL but make sure you are using the equivalent of version 5.5 instead of 5.6 if you have less than 1GB of RAM.

We also need to configure the server to allow outside requests for docker. Do this by executing the following script with sudo privileges.

FILEPATH="/etc/mysql/my.cnf"
SEARCH="bind-address\t\t= 127.0.0.1"
REPLACE='#bind-address = 127.0.0.1'
sed -i "s;$SEARCH;$REPLACE;g" $FILEPATH

# Restart mysql for the changes to take effect
service mysql restart

Optional - Manually Create Connection Config File

You don't have to perform this step, but it prevents you having to manually remember and enter your database details into the website when you first login.

Execute the following commands. Feel free to swap $MY_IP for $HOSTNAME if you know that your hostname is configured correctly with DNS.

# Grab our server's IP
MY_IP=`ifconfig eth0 | \
sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`

# create the config directory
mkdir $HOME/data

# Create the config
echo "" | sudo tee $HOME/data/config.php

Create Startup Script

Create a BASH script at $HOME/start.container.sh that wil deploy lychee.

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

sleep 10

docker kill lychee
docker rm lychee

docker pull kdelfour/lychee-docker

docker run \
-d \
-p 80:80 \
-v $DIR/uploads/:/uploads/ \
-v $DIR/data/:/data/ \
--name lychee \
--restart=always \
kdelfour/lychee-docker

Login

Navigate in your browser to your server's hostname or IP.

If you didn't perform the optional configuration step, you will be greeted with a Configuration menu to manually input your database details, which you now need to fill in.

The first time you sign in, you will be asked to create a username and password for the administrator user. Make sure to remember these details!

Thats it, enjoy your new image hosting server!

Author

Programster

Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites. More info.