Support #860

Install Lychee on FreeBSD

Added by Daniel Curtis almost 4 years ago. Updated almost 4 years ago.

Web Server
Target version:
Start date:
Due date:
% Done:


Estimated time:
1.00 h
Spent time:


This is a guide on setting up Lychee with Nginx on FreeBSD 10.

Prepare the Environment

  • Before installation of the components, make sure everything is up to date using the following command:
    pkg update -f && pkg upgrade
  • Install a couple dependencies:
    pkg install git ImageMagick-nox11
  • Create the lychee user:
    pw user add -n lychee -s /sbin/nologin -c "Lychee" 

Install Nginx

  • Install Nginx
    pkg install nginx
  • Start and enable nginx at boot:
    echo 'nginx_enable="YES"' >> /etc/rc.conf
    service nginx start
  • Create a configuration directory to make managing individual server blocks easier
    mkdir /usr/local/etc/nginx/conf.d
  • Edit the main nginx config file:
    vi /usr/local/etc/nginx/nginx.conf
    • And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
      load_module /usr/local/libexec/nginx/;
      load_module /usr/local/libexec/nginx/;
      worker_processes  1;
      error_log  /var/log/nginx-error.log;
      events {
          worker_connections  1024;
      http {
          include       mime.types;
          default_type  application/octet-stream;
          sendfile        on;
          keepalive_timeout  65;
          # Load config files from the /etc/nginx/conf.d directory
          include /usr/local/etc/nginx/conf.d/*.conf;

Install MySQL Server

  • Start by installing the mariadb100-server and mariadb100-client packages:
    pkg install mariadb100-{server,client}
  • Copy a base MySQL configuration to use:
    cp /usr/local/share/mysql/my-small.cnf /var/db/mysql/my.cnf
  • Enable and start mysql at boot:
    echo 'mysql_enable="YES"' >> /etc/rc.conf
    service mysql-server start
  • Prepare the database for use by running the secure installation:
    • NOTE: Choose a strong root password and answer yes to all questions.

Create Databases and Users

  • Login to MySQL and create appropriate databases and users.
    mysql -u root -p
    • and run the following SQL queries to create the lycheedb database and lycheeuser user:
      CREATE USER 'lycheeuser'@'localhost' IDENTIFIED BY 'SuperSecretPassword';
      GRANT ALL PRIVILEGES ON lycheedb.* TO 'lycheeuser'@'localhost';

Install PHP

  • Install PHP 5.6 and a few extensions:
    pkg install php56 php56-{mbstring,session,exif,gd,mysqli,json,zip}
  • Configure the default PHP settings
    cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
  • Edit the php config file:
    vi /usr/local/etc/php.ini
    • And make sure the following values are set:
      max_execution_time = 200
      post_max_size = 100M
      upload_max_filesize = 100M
      memory_limit = 256M
  • Create a directory for the php-fpm configs:
    mkdir /usr/local/etc/php-fpm.d
  • Edit the php-fpm config file:
    vi /usr/local/etc/php-fpm.conf
    • Make the following changes:
  • Enable PHP-FPM at boot:
    echo 'php_fpm_enable="YES"' >> /etc/rc.conf
  • Restart nginx:
    service nginx restart

Install Lychee

  • Download Lychee from GitHub:
    cd /usr/local/www
    git clone
  • Create an server block config file:
    vi /usr/local/etc/nginx/conf.d/
    • Add the following:
      upstream lychee-handler {
        server unix:/var/run/;
      server {
        listen 80;
        root /usr/local/www/Lychee/;
        index index.html index.php;
        # Set size for max uploaded content
        client_max_body_size 0;
        client_header_timeout 30m;
        client_body_timeout 30m;
        location = /robots.txt {
          allow all;
          log_not_found off;
          access_log off;
        location ~ ^/(?:CHANGELOG\.md|config||.git){
          deny all;
        location / {
          try_files $uri $uri/ =404;
        location ~ \.php(?:$|/) {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_pass lychee-handler;
          fastcgi_intercept_errors on;
  • Create the lychee php-fpm pool config file:
    vi /usr/local/etc/php-fpm.d/
    • And add the following:
      user = lychee
      group = www
      listen = /var/run/
      listen.owner = lychee = www
      pm = dynamic
      pm.max_children = 5
      pm.start_servers = 2
      pm.min_spare_servers = 1
      pm.max_spare_servers = 3
  • Change the ownership of the lychee directory:
    chown -R lychee:www /usr/local/www/Lychee
  • Restart nginx and start php-fpm:
    service nginx restart
    service php-fpm start



#1 Updated by Daniel Curtis almost 4 years ago

  • % Done changed from 0 to 90
  • Start date changed from 10/22/2016 to 10/23/2016
  • Status changed from New to In Progress
  • Description updated (diff)

#2 Updated by Daniel Curtis almost 4 years ago

  • % Done changed from 90 to 100
  • Status changed from In Progress to Resolved

#3 Updated by Daniel Curtis almost 4 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF