# Installation in a subFolder

**URL:** <https://discourse.getcockpit.com/t/installation-in-a-subfolder/1005>\
**Category:** Support\
**Created:** [September 10, 2019, 9:47am UTC](https://discourse.getcockpit.com/t/installation-in-a-subfolder/1005 "2019-09-10T09:47:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![moabi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/moabi/32/417_2.png) [@moabi](https://discourse.getcockpit.com/u/moabi)\
**Post date:** [September 10, 2019, 9:47am UTC](https://discourse.getcockpit.com/t/installation-in-a-subfolder/1005/1 "2019-09-10T09:47:46Z")

</div>

I installed cockpit in a subfolder on [example.com/static](http://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](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

 ![example-com-static](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/1X/c8a615ce2c16e92b1f64a8f58d7e6d95d8eb8096.png)

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [September 11, 2019, 7:08am UTC](https://discourse.getcockpit.com/t/installation-in-a-subfolder/1005/2 "2019-09-11T07:08:03Z")

</div>

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.

> <https://github.com/agentejo/cockpit/blob/next/lib/Lime/App.php#L198-L210>

---

<div class="post-metadata">

**Author:** ![moabi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/moabi/32/417_2.png) [@moabi](https://discourse.getcockpit.com/u/moabi)\
**Post date:** [September 11, 2019, 1:10pm UTC](https://discourse.getcockpit.com/t/installation-in-a-subfolder/1005/3 "2019-09-11T13:10:32Z")

</div>

> [@raffaelj](#):
>
> $this[‘site\_url’]

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.'">';

```

---

<div class="post-metadata">

**Author:** ![moabi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/moabi/32/417_2.png) [@moabi](https://discourse.getcockpit.com/u/moabi)\
**Post date:** [September 13, 2019, 7:11am UTC](https://discourse.getcockpit.com/t/installation-in-a-subfolder/1005/4 "2019-09-13T07:11:01Z")

</div>

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 😵

```
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

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [September 13, 2019, 5:34pm UTC](https://discourse.getcockpit.com/t/installation-in-a-subfolder/1005/5 "2019-09-13T17:34:23Z")

</div>

> [@moabi](#):
>
> Instead I do this :
> 
> ```php
> //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.'">';
> 
> ```

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:

> <https://github.com/agentejo/cockpit/blob/next/lib/Lime/App.php#L816>

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

Maybe [this collection of paths, constants and function dependencies](https://discourse.getcockpit.com/t/understanding-cockpit-a-development-guide-work-in-progress/486/2) 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:

> <https://github.com/raffaelj/CpMultiplane/blob/master/bootstrap.php#L34>

> <https://github.com/raffaelj/CpMultiplane/blob/master/modules/Multiplane/bootstrap.php#L3-L14>

> [@moabi](#):
>
> BTW, this post title should be : Installation in a subFolder with a symlink

You could change it 😉
