Set Up Linux Photo Management with Lychee
In this article
Yes, you can set up a self-hosted photo management system on Linux using Lychee — a free, open-source web app that organizes, tags, and shares your photos. This guide walks you through installing Lychee on Ubuntu (or Debian-based) Linux with Nginx, PHP, and MySQL/MariaDB. You'll end up with a private photo library accessible from any browser on your network, with optional public sharing.
What You'll Need
- A Linux server or PC running Ubuntu 20.04 or newer (or Debian 10+).
- Root or sudo access to install packages.
- A domain name or IP address pointing to your server (optional but recommended).
- At least 2 GB of RAM and 10 GB free disk space (more if you have many photos).
- Basic familiarity with the command line.
Step-by-Step
- Update your system
Open a terminal and run:sudo apt update && sudo apt upgrade -y - Install required packages
Lychee needs Nginx, PHP, and MySQL. Run:
The exact PHP extensions may vary by version; if you see a missing one later, install it withsudo apt install nginx mysql-server php-fpm php-mysql php-xml php-mbstring php-curl php-zip php-gd php-bcmath -ysudo apt install php-<extension>. - Secure MySQL and create a database
Runsudo mysql_secure_installationand follow the prompts (set a root password, remove anonymous users, etc.). Then log into MySQL:
Create a database and user (replacesudo mysql -u root -plychee_userandstrong_password):CREATE DATABASE lychee; CREATE USER 'lychee_user'@'localhost' IDENTIFIED BY 'strong_password'; GRANT ALL PRIVILEGES ON lychee.* TO 'lychee_user'@'localhost'; FLUSH PRIVILEGES; EXIT; - Download Lychee
Go to the official Lychee GitHub releases page and grab the latest version (e.g.,lychee-v5.0.0.zip). Then:
Ifcd /var/www sudo wget https://github.com/LycheeOrg/Lychee/releases/download/v5.0.0/lychee-v5.0.0.zip sudo unzip lychee-v5.0.0.zip -d lychee sudo chown -R www-data:www-data /var/www/lycheeunzipis not installed, runsudo apt install unzipfirst. - Configure Nginx
Create a new Nginx site configuration:
Paste the following (adjustsudo nano /etc/nginx/sites-available/lycheeserver_nameto your domain or IP):
The PHP socket path may differ (e.g.,server { listen 80; server_name example.com; root /var/www/lychee/public; index index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; } location ~ /\.ht { deny all; } }php8.2-fpm.sock). Check withls /var/run/php/. Enable the site and restart Nginx:sudo ln -s /etc/nginx/sites-available/lychee /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx - Run the Lychee installer
Open your browser and go tohttp://your-server-ip. You'll see the Lychee setup page. Fill in:- Database host:
localhost - Database port:
3306 - Database name:
lychee - Username:
lychee_user - Password: the one you set
- Database host:
- Set up storage and permissions
Lychee stores photos in/var/www/lychee/storage. Ensure the web server can write there:sudo chown -R www-data:www-data /var/www/lychee/storage sudo chmod -R 755 /var/www/lychee/storage - Enable HTTPS (recommended)
Install Certbot for free SSL:
Follow the prompts. This gives you a secure connection.sudo apt install certbot python3-certbot-nginx -y sudo certbot --nginx -d example.com
Common Mistakes
- Wrong PHP socket path — If you see “502 Bad Gateway,” the fastcgi_pass path is wrong. Fix it in the Nginx config.
- Missing PHP extensions — Lychee may complain about missing modules. Install them with
sudo apt install php-<extension>and restart PHP-FPM. - File permission errors — If uploads fail, check that the storage folder is owned by
www-data. - Using the wrong database credentials — Double-check the username and password; MySQL is case-sensitive.
- Forgetting to enable the Nginx site — If you get the default Nginx page, you didn't symlink the config or restart Nginx.
Tips
- Back up your
/var/www/lycheefolder and the MySQL database regularly. Use a cron job to dump the database. - Use a dedicated subdomain like
photos.example.comto keep things clean. - Enable two-factor authentication in Lychee settings for extra security.
- If you have a large photo library, consider using an external storage drive and mounting it to
/var/www/lychee/storage. - Keep Lychee updated by checking the GitHub releases page and following the upgrade instructions.
Troubleshooting
- Check Nginx error logs — Run
sudo tail -f /var/log/nginx/error.logto see what's failing. - Verify PHP-FPM is running —
sudo systemctl status php8.1-fpm(adjust version). If not, start it withsudo systemctl start php8.1-fpm. - Test the database connection — From the command line, run
mysql -u lychee_user -pto ensure credentials work. - If the installer hangs — Check the browser console for errors and ensure all PHP extensions are installed.
- If you get a 403 error — Check file permissions:
sudo chmod -R 755 /var/www/lycheeand ensure the root path in Nginx points to/public. - If photos don't upload — Check the PHP upload_max_filesize and post_max_size in
/etc/php/8.1/fpm/php.ini. Increase them (e.g., to 100M) and restart PHP-FPM.
Frequently Asked Questions
Can I use SQLite instead of MySQL?
Yes, Lychee supports SQLite, but MySQL/MariaDB is recommended for larger libraries and better performance. If you use SQLite, skip the database creation step and choose SQLite during installation.
How do I update Lychee to a new version?
Back up your data, then download the new release, extract it over the old files (keeping the .env file and storage folder), and run any upgrade scripts mentioned in the release notes. Usually, you just refresh the browser.
Can I access Lychee from outside my home network?
Yes, but you should use HTTPS and consider a VPN or reverse proxy for security. Exposing it directly to the internet without protection is risky.
Does Lychee support face recognition?
No, Lychee does not have built-in face recognition. It focuses on albums, tags, and metadata. For face recognition, consider other tools like PhotoPrism.
Can I import photos from my phone?
Yes, you can upload through the web interface, or use the Lychee mobile app (if available) or third-party tools that sync to the Lychee API.
What if I forget my admin password?
You can reset it by running a command in the Lychee directory using php artisan lychee:reset-admin, which will create a new admin user.