Installation in a subFolder

I installed cockpit in a subfolder on example.com/static
in /var/www/sites//example.com/ I have a simlink which goes to /var/www/sites/static/

I override the defines in the defines.php and get this
COCKPIT_DIR : /var/www/sites/static
COCKPIT_ADMIN: 0
COCKPIT_DOCS_ROOT: /var/www/sites/static
COCKPIT_ENV_ROOT : /var/www/sites/static
COCKPIT_BASE_URL : ./static
COCKPIT_API_REQUEST : 0
COCKPIT_BASE_ROUTE : /static
COCKPIT_SITE_DIR :/var/www/sites/static
COCKPIT_CONFIG_DIR : /var/www/sites/static/config
COCKPIT_PUBLIC_STORAGE_FOLDER : /var/www/sites/static/storage
COCKPIT_ADMIN_CP: 0
COCKPIT_CONFIG_PATH : /var/www/sites/static/config/config.yaml
COCKPIT_STORAGE_FOLDER :/var/www/sites/static/storage

The install goes well and says it’s completed, but I can see the links to the assets are already giving a 404.
Then in the login page, All the links to the assets are like this
https://example.com/storage/tmp/assets/1056f89eef2a03d1ca3f6c78ad8c49e4.js?ver=0.9.2
I’m missing the /static subfolder and get the { error } on the login page

I’m not 100% shure about your setup, but I think, you have to set site_url to https://example.com/static in your config file.

The function assets() uses the function pathToUrl(), that uses site_url, which is guessed by Lime. Symlinks can break these auto guessing mechanisms.

Thank you for your answer, this does not fix the issue though.
From what I saw, a script asset (for example) is built this way in App.php (l.814) :

$ispath = \strpos($src, ':') !== false && !\preg_match('#^(|http\:|https\:)//#', $src);
$list[] = '<script src="'.($ispath ? $this->pathToUrl($src):$src).($version ? "?ver= 
{$version}":"").'" type="'.$type.'" '.$load.'></script>';

While the function pathToUrl (l.517)

    $url = false;

    if ($file = $this->path($path)) {

        $file = \str_replace(DIRECTORY_SEPARATOR, '/', $file);
        $root = \str_replace(DIRECTORY_SEPARATOR, '/', $this['docs_root']);

        $url = '/'.\ltrim(\str_replace($root, '', $file), '/');
        $url = \implode('/', \array_map('rawurlencode', explode('/', $url)));

        if ($full) {
            $url = \rtrim($this->registry['site_url'], '/').$url;
        }
    }

    return $url;

As the url for the assets (script or style) are not ‘full’ :

<script src="/storage/tmp/assets/1056f89eef2a03d1ca3f6c78ad8c49e4.js?ver=0.9.2" type="text/javascript"></script>

If I change in config.php :

'docs_root'=> './static/',	

This will give

<script src="/var/www/sites/static/storage/tmp/assets/1056f89eef2a03d1ca3f6c78ad8c49e4.js?ver=0.9.2" type="text/javascript"></script>

Instead I do this :

//set pathToUrl second parameter to TRUE allow us to have the full URL
// This works for the style, but not for the scripts, maybe a cache issue
$list[] = '<link href="'.($ispath ? $this->pathToUrl($src, true):$src).($version ? "?ver={$version}":"").'" type="'.$type.'" rel="'.$rel.'">';

With this config.php

'site_url' => 'https://example.com/static'

I get this config :

COCKPIT_DIR : /var/www/sites/static
COCKPIT_ADMIN: 0
COCKPIT_DOCS_ROOT: /var/www/sites/
COCKPIT_ENV_ROOT : /var/www/sites/static
COCKPIT_BASE_URL : ./static
COCKPIT_API_REQUEST : 0
COCKPIT_BASE_ROUTE : /static
COCKPIT_SITE_DIR :/var/www/sites/static
COCKPIT_CONFIG_DIR : /var/www/sites/static/config
COCKPIT_PUBLIC_STORAGE_FOLDER : /var/www/sites/static/storage
COCKPIT_ADMIN_CP: 0
COCKPIT_CONFIG_PATH : /var/www/sites/static/config/config.php
COCKPIT_STORAGE_FOLDER :/var/www/sites/static/storage

I tried this in defines.php :

define('COCKPIT_DIR', '/var/www/sites/example.com/static');
define('COCKPIT_DOCS_ROOT', '/var/www/sites/example.com');

adding the define with the ‘real path’ makes it work, but I still have some issues on the path of the JS scripts :dizzy_face:

https://example.com/var/www/sites/static/modules/Collections/assets/link-collectionitem.js?ver=1568358540

BTW, this post title should be : Installation in a subFolder with a symlink

You shouldn’t modify App.php directly. It could cause other issues in hidden places and it will be overwritten with the next update.

But for a better understanding - the assets function splits into two functions: style() and script(). If you want to modify it that way, you have to adjust that line, too:

It’s hard to find the right way without the same setup… Some more hints:

Maybe this collection of paths, constants and function dependencies helps a bit.

I had a case, where I didn’t want to change the constants, but only a few registry entries and a filestorage url. In this case, I use Cockpit as backend at example.com/cockpit and use the same folder as a library in my frontend. The problem feels similar, but I didnt’t use any symlinks. So, maybe it helps for inspiration:

You could change it :wink: