Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install Lychee with Nginx on Ubuntu 24.04

How to Install Lychee with Nginx on Ubuntu 24.04

Setting up Lychee on Ubuntu 24.04 with Nginx allows you to host your own beautiful, lightweight photo management system on your server. This guide walks you through the entire process, from installing prerequisites to configuring your web server, ensuring your Lychee installation is secure, efficient, and ready to use. Before starting, make sure you have a fresh Ubuntu 24.04 server with root or sudo privileges and a domain name pointing to your server’s IP address. A basic understanding of Linux command-line operations will be helpful, but the steps are straightforward enough for beginners to follow.

What You’ll Need

  • Ubuntu 24.04 server with root or sudo privileges
  • Domain name pointing to your server’s IP (optional but recommended)
  • Basic knowledge of Linux terminal commands
  • Access to SSH (via terminal or SSH client)
  • SSL certificate (optional but recommended for HTTPS)

Step-by-Step

  1. Update your system packages:
    sudo apt update && sudo apt upgrade -y

    This ensures all your packages are up-to-date, reducing compatibility issues later.

  2. Install necessary dependencies:
    sudo apt install nginx php-fpm php-mysql php-xml php-mbstring php-curl php-zip php-gd php-bcmath unzip mysql-server -y

    These include the web server, PHP extensions, and database server needed by Lychee.

  3. Secure MySQL installation:
    sudo mysql_secure_installation

    Follow the prompts to set root password and remove anonymous users for security.

  4. Create a MySQL database and user for Lychee:
    sudo mysql -u root -p
    CREATE DATABASE lychee;
    CREATE USER 'lycheeuser'@'localhost' IDENTIFIED BY 'your_secure_password';
    GRANT ALL PRIVILEGES ON lychee.* TO 'lycheeuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

    Replace ‘your_secure_password’ with a strong password.

  5. Download the latest Lychee release:
    wget https://github.com/LycheeOrg/Lychee/releases/latest/download/Lychee.zip

    Extract it to your web directory:

    sudo unzip Lychee.zip -d /var/www/lychee
  6. Set permissions:
    sudo chown -R www-data:www-data /var/www/lychee
    sudo chmod -R 755 /var/www/lychee
  7. Configure PHP settings (if needed):
    sudo nano /etc/php/8.2/fpm/php.ini

    Ensure that the following settings are enabled or set appropriately:

    • memory_limit = 256M
    • upload_max_filesize = 50M
    • post_max_size = 50M

    Save and exit, then restart PHP-FPM:

    sudo systemctl restart php8.2-fpm
  8. Configure Nginx server block:
    sudo nano /etc/nginx/sites-available/lychee

    Insert the following configuration, replacing ‘yourdomain.com’ with your actual domain:

    server {
        listen 80;
        server_name yourdomain.com;
    
        root /var/www/lychee;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

    Save and enable the site:

    sudo ln -s /etc/nginx/sites-available/lychee /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl reload nginx
  9. Secure your site with HTTPS (optional but recommended):
    sudo apt install certbot python3-certbot-nginx -y
    sudo certbot --nginx -d yourdomain.com

    Follow the prompts to obtain and install your SSL certificate. Certbot will automatically update your Nginx configuration.

  10. Complete Lychee setup:
    – Visit http://yourdomain.com in your browser.
    – Follow the on-screen instructions to complete the Lychee setup, entering your database details.
    – Remove or secure the setup files as instructed.
  11. Test your installation:
    – Ensure the webpage loads correctly.
    – Upload a test photo to confirm functionality.
    – Verify HTTPS is working if you set up SSL.

Common Mistakes

  • Not updating system packages before starting, leading to compatibility issues.
  • Incorrect database credentials or permissions, causing connection errors.
  • Forgetting to restart PHP-FPM or Nginx after configuration changes.
  • Failing to set correct file permissions, resulting in inaccessible files or security risks.
  • Not securing the site with SSL, leaving data vulnerable during transfer.
  • Using an incorrect PHP version path in Nginx configuration, causing PHP scripts not to execute.

Tips

  • Always keep your system and packages updated for security and compatibility.
  • Use strong, unique passwords for your database and server accounts.
  • Back up your database regularly to prevent data loss.
  • Configure automatic renewal for SSL certificates with Certbot to maintain HTTPS.
  • Secure your server by disabling unnecessary services and using a firewall.
  • Enable caching or CDN if you expect high traffic to improve performance.

Troubleshooting

  • Website not loading or showing errors: Check Nginx error logs at /var/log/nginx/error.log. Ensure your server block is correctly configured and enabled.
  • PHP scripts not executing: Verify PHP-FPM is running with sudo systemctl status php8.2-fpm. Check the socket path in your Nginx config matches the PHP version installed.
  • Database connection errors: Double-check your database credentials in the Lychee setup and ensure the database user has the right privileges.
  • SSL certificate issues: Run sudo certbot renew to test automatic renewal. Check Certbot logs for errors.
  • Permissions problems: Ensure /var/www/lychee and its contents are owned by www-data and have correct permissions.

Frequently Asked Questions

Can I install Lychee without a domain?
Yes, you can access Lychee via your server’s IP address, but using a domain and HTTPS is recommended for security.
Is Lychee secure to run on my server?
When properly configured with HTTPS, permissions, and regular updates, Lychee is secure. Always follow best security practices.
Can I upgrade Lychee later?
Yes, simply download the newer release, replace the files, and run the setup again if needed.
How do I add users or share albums?
Lychee supports user management and album sharing features within its interface after installation.
What if I encounter errors during installation?
Check the logs, verify each step, and ensure all dependencies are correctly installed and configured.

Following this guide will help you successfully set up Lychee with Nginx on Ubuntu 24.04, giving you a self-hosted, secure, and efficient photo management system. Regular maintenance and updates will keep your installation running smoothly for years to come.

Related

How to Install Lychee with Nginx on Ubuntu 24.04
Scroll to top