Im in the process of installing flarum beta 9 on shared hosting with a given user directory, in which I created a flarum directory:

/home/user
/home/user/flarum
/home/user/flarum/vendor
/home/user/flarum/storage

etc.

Them, I have a public folder called html:

/home/user/html

... which is a symlink to

/var/www/virtual/user/html

I moved the contents of /home/user/flarum/public into the /var/www/virtual/user/html directory and adapted the /var/www/virtual/user/html/index.php and /home/user/flarum/flarum files:

index.php

<?php

/*
 * This file is part of Flarum.
 *
 * (c) Toby Zerner <toby.zerner@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/* require '/home/user/flarum/vendor/autoload.php'; */
require '/../../../../../home/user/flarum/vendor/autoload.php';

$server = new Flarum\Http\Server(
    Flarum\Foundation\Site::fromPaths([
        /* 'base' => '/home/user/flarum', */
        'base' => __DIR__.'/../../../../../home/user/flarum',
        /* 'public' => '/home/user/html', */
        'public' => __DIR__,
        /* 'storage' => '/home/user/flarum/storage', */
        'storage' => __DIR__.'/../../../../../home/user/flarum/storage',
    ])
);

$server->listen();

flarum

#!/usr/bin/env php
<?php
/*
 * This file is part of Flarum.
 *
 * (c) Toby Zerner <toby.zerner@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require 'vendor/autoload.php';

$server = new Flarum\Console\Server(
    Flarum\Foundation\Site::fromPaths([
        'base' => __DIR__,
        /* 'public' => __DIR__.'/../html', */
        'public' => __DIR__.'/../../../var/www/virtual/user/html',
        'storage' => __DIR__.'/storage',
    ])
);

$server->listen();

As you can see, I tried absolute as well as relative paths and pointing to the symlink as well as to the html directory directly.

Whatever I try, when Itry to access the start page I get an error in the console:

TypeError: flarum.core is undefined

And the code that leads to this error is in the generated html template:

        <script>
            document.getElementById('flarum-loading').style.display = 'none';

            try {
=>              flarum.core.app.load({"resources":...});
                flarum.core.app.bootExtensions(flarum.extensions);
                flarum.core.app.boot();
            } catch (e) {
                var error = document.getElementById('flarum-loading-error');
                error.innerHTML += document.getElementById('flarum-content').textContent;
                error.style.display = 'block';
                throw e;
            }
        </script>

The assets are included just fine (favicon, css, js, fonts), but the js execution fails.

Trying to access the admin panel ends with the same error.

Has anyone an idea what I'm doing wrong?

Wouldn't be easier to create symlink, so /var/www/virtual/user/html will point to/home/user/flarum/public? I'm using symlinks is such cases - it always works and does not require any additional changes in entry script.

    Hi,

    As far as I know, since a symlink is a shortcut in linux itself, you don't need to use the full path in PHP, making this easier.

    Edit: Removed long response of rubbish that would not work...

    Apparently I was wrong regarding the symlinks.

    Try

    'base' => __DIR__.'../../../../../../home/user/flarum',

    instead of

    'base' => __DIR__.'/../../../../../home/user/flarum',

    That is, start your paths with two dots. 🙂

      andreherberth That is, start your paths with two dots. 🙂

      Oh my goodness, this was really a dumb one. Thanks so much, sometimes you don't see the easiest issues.

      I will report later how it went.

      rob006 Wouldn't be easier to create symlink

      Yes that would have been my next strategy. But I like to know, why things don't work when I think they should. So avoiding an issue is not always my favorite, but when it's more elegant, I may warm up to the idea. And considering:

      it [...] does not require any additional changes in entry script.

      ... it is indeed quite elegant.

      On the other hand I like the idea of having the public folder outside of my /home/user/ path, maybe irrationally so.

      andreherberth That is, start your paths with two dots. 🙂

      Unfortunately this didn't work. I got a complaint, that the flarum folder and the storage folder didn't exist. It seems __DIR__ doesn't end with a slash, this also becomes clear if you look at the original index.php and flarum files.

      I ask myself whether there is yet another place other than the index.php and flarumfiles, where the relationship between the flarum and the public/html folder is defined. And I hope there is not one overlooked occurrence of a simple ../to access the flarum folder from the public one.

      You could omit the __DIR__ altogether and just put the absolute path yourself?

      All __DIR__ do is to insert the absolute path to index.php

        andreherberth You could omit the __DIR__ altogether and just put the absolute path yourself?

        As you may guess from my first post I tried that first. It didn't work either.

          Pollux

          ah, I read the comments wrong I guess,

          Just to clearify now, /home/user/html is the symlink?
          So the absolute path is /var/www/virtual/user/html?

          In that case, you could try to use "/var/www/virtual/user/html" like this:

          $server = new Flarum\Http\Server(
              Flarum\Foundation\Site::fromPaths([
                  'base' => '/home/user/flarum',
                  'public' => '/var/www/virtual/user/html',
                  'storage' => '/home/user/flarum/storage',
              ])
          );

          are you using PHP_FPM, and how does it, if so, treat symlinks?

          It can be set to treat symlinks as

          fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
          fastcgi_param DOCUMENT_ROOT $realpath_root;
          (https://serverfault.com/questions/848503/nginx-caching-symlinks)

          That said. I will try to spin up a test bed later today and try to recreate the issue.
          Can you tell me anything more about your setup? As to replicate settings properly.

            andreherberth

            I tried your suggestion with absolute paths avoiding the symlink. The error stays the same. So I assume there's nothing wrong with the paths.

            andreherberth Can you tell me anything more about your setup? As to replicate settings properly.

            My webspace provider is uberspace.de. You can read some details about their implementation of the HTTP Stack here:

            https://manual.uberspace.de/background-http-stack.html

            HTTP Stack

            A couple hundred users per host, a few domains each, security headers, HTTPS with let’s encrypt, websocket, pass-through, web backends, htaccess.. at some point a web setup reaches a point, when there are too many feature to handle them all with just one web server software. That’s why we’re employing two of them back-to-back: nginx and Apache httpd.

                       _
                     (`  ).
                    (     ).                 .-------.        .-------.
                   _(       '`.  ----------> | nginx | -----> | httpd |
               .=(`( Internet )              '-------'        '-------'
               ((    (..__.:'-'                  |                => php via php-fpm
               `(       ) )                      |                => static files
                 ` __.:'   )                     |                => htaccess
                        --'                      |
                                                 |            .--------------.
                                                 '----------> | Web Backends |
                                                              '--------------'
                                                                  => per-user nginx
                                                                  => nodejs, python, ruby, ...
                                                                  => gogs, mattermost, matrix, ...

            .

            nginx

            nginx handles all the nitty gritty of accepting requests from browsers, making sure HTTPS works properly and passing requests through to configured web backends. It also connects to apache for more traditional web development needs.

            php -v

            PHP 7.1.31 (cli) (built: Jul 31 2019 10:34:10) ( NTS )
            Copyright (c) 1997-2018 The PHP Group
            Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
                with Zend OPcache v7.1.31, Copyright (c) 1999-2018, by Zend Technologies

            https://manual.uberspace.de/lang-php.html

            We use the PHP FastCGI Process Manager (FPM) to connect the PHP interpreter to the webserver. Every user has its own PHP-FPM instance that is always running with the following configuration:

            pm = ondemand
            pm.max_children = 10
            pm.process_idle_timeout = 900s;
            ; The number of requests each child process should execute before respawning.
            pm.max_requests = 500

            We use a standard php.ini configuration with minimal modifications to fit the needs of popular software:

            realpath_cache_ttl = 300
            max_execution_time = 600
            max_input_time = 600
            max_input_vars = 1500
            memory_limit = 256M
            date.timezone = Europe/Berlin

            MySQL

            https://manual.uberspace.de/database-mysql.html

            We’re providing MariaDB 10.3 as a MySQL-compatible database server.

            Update: The paths were not the culprits.

            I still don't know what caused my problems but after changing the debug settings in config.php to true and back to false(and reloading the page in between) solved the issue. As I hadn't reloaded the admin panel in the first run I had to repeat it with the admin panel, again with the desired effect.

            So everything is fine for me right now.

            5 days later