Self-hosting
Run Leantime in a subfolder
- Self-hosted only
We recommend running Leantime on its own domain or subdomain (for example leantime.yourcompany.com). You can also run it in a subfolder of an existing website (for example yourcompany.com/leantime).
Install Leantime as in the package installation, with one change: put it in a folder outside your website’s document root. If your website’s document root is /var/www/html, use /var/www/leantime, not /var/www/html/leantime. Then only Leantime’s public/ folder can be reached from the web, and config/ (your .env with passwords) and userfiles/ (uploaded files) stay private.
The examples below use /var/www/leantime and the subfolder /leantime. Replace both with yours.
Apache
Section titled “Apache”You need Apache 2.4 with mod_rewrite (sudo a2enmod rewrite).
-
In your existing website’s virtual host, map
/leantimeto Leantime’spublic/folder:Alias /leantime /var/www/leantime/public<Directory /var/www/leantime/public>Options +FollowSymLinksAllowOverride AllRequire all granted</Directory>AllowOverride Alllets Leantime’s ownpublic/.htaccesssend requests toindex.php. You don’t need to change that file, so Leantime updates don’t undo your setup. -
In
config/.env, setLEAN_APP_URLto the full address, including the subfolder:LEAN_APP_URL = 'https://yourcompany.com/leantime' -
Check the configuration and reload Apache:
Terminal window sudo apachectl configtestsudo systemctl reload apache2
-
Add these three blocks inside the
serverblock of your existing website. Use the PHP-FPM socket of your PHP version, as in the Nginx steps:# Leantime in /leantimelocation = /leantime {return 301 /leantime/$is_args$args;}location ^~ /leantime/ {alias /var/www/leantime/public/;index index.php;try_files $uri $uri/ @leantime;location ~ /\.ht {deny all;}location ~ \.php$ {try_files $uri @leantime;include fastcgi_params;fastcgi_param SCRIPT_FILENAME $request_filename;fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; # match your PHP version (8.2 or later)}}location @leantime {rewrite ^/leantime/(.*)$ /leantime/index.php last;}- The trailing slashes in
/leantime/andpublic/keep your website’s own pages that start with the same letters, like/leantime.phpor/leantime-news, out of Leantime. The first block sends/leantimeto/leantime/. ^~stops your website’s own regex blocks, such aslocation ~ \.php$, from handling Leantime’s files. That also skips your site’s own.htrule, so the block repeats it to keep.htaccessprivate.try_files $uri @leantimein the PHP block sends.phpaddresses that don’t exist, like olddownload.phpattachment links, to Leantime, which still handles them.SCRIPT_FILENAME $request_filenamegives PHP-FPM the real path ofindex.phpunderalias. With$fastcgi_script_name, PHP-FPM gets/leantime/index.phpand can’t find the file.
- The trailing slashes in
-
Set
LEAN_APP_URLinconfig/.envas in the Apache steps. -
Check the configuration and reload Nginx:
Terminal window sudo nginx -tsudo systemctl reload nginx
Leantime is already inside the document root
Section titled “Leantime is already inside the document root”If Leantime’s folder has to stay inside your website’s document root, its other folders can be reached from the web too. Block web access to everything outside public/, especially config/ and userfiles/, and turn off directory listings. Moving the folder out of the document root is safer.
Was this page helpful?
Thanks, glad it helped.
Thanks for telling us. What was missing?
