Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cockpit in Subfolder and Domain redirect #704

Closed
marwie opened this issue Mar 12, 2018 · 3 comments

Comments

@marwie
Copy link

commented Mar 12, 2018

Hello,

I'm trying to install cockpit for a friend.
His domain is redirected to a subfolder on his webserver e.g. the server path is "domain.com/subfolder".
I then put cockpit into "/subfolder/cms" and open "domain.com/cms/install" which tells me to go on and change the user name so I click on the button but cockpit now redirects to "domain.com/subfolder/cms/auth/login" instead of "domain.com/cms/auth/login" - How can I make cockpit use the correct domain base path instead of the server path?
I guess .htaccess? but would be nice to have cockpit automatically register the domain url on installation as well or some config file where I can change the base cms url :)

best
marcel

@moabi

This comment has been minimized.

Copy link

commented Mar 14, 2018

Have a look at the bootstrap.php file, it looks for a defines file

if (file_exists(__DIR__.'/defines.php')) {
    include(__DIR__.'/defines.php');
}

Just create this file and add your constant (COCKPIT_DIR, COCKPIT_SITE_DIR, COCKPIT_CONFIG_DIR, etc...) to match the good path

@marwie

This comment has been minimized.

Copy link
Author

commented Mar 17, 2018

that code does not exist in my bootstrap.php, these defines are directly inside bootstrap.php defined. My cockpit version is from end of 2017.
After replacing the subfolder from $COCKPIT_BASE I'm able to open the login site, that works again - but all the image paths and styles are broken, they still contain "subfolder"

I also downloaded a more recent version where bootstrap contains the defines code but what does it help if I set any constant there when bootstrap.php overwrites them right away again or am I missing something?

@raffaelj

This comment has been minimized.

Copy link
Contributor

commented Jul 14, 2018

You used the outdated legacy branch. In the master and next branches, cockpit checks for the defines.php file.
Bootstrap.php doesn't override the constants. It only sets variables and checks a few lines later, if the constant (from defines.php) already exists.

I tried to install Cockpit on a shared host (strato) on a subdomain. Your setup may differ a bit, but this is my setup for inspiration:

System: PHP7+, Apache

  • sub.domain.de points to .../htdocs/redesign
  • my cockpit directory is named ...htdocs/redesign/admin
  • without redefined paths, I got redirected from sub.domain.de/admin to sub.domain.de/redesign/admin/auth/login with 404 Not found
  • now create the file defines.php inside the cockpit folder (in this case admin) with this content:
<?php
define('COCKPIT_BASE_URL', '/admin');
define('COCKPIT_BASE_ROUTE', '/admin');
define('COCKPIT_DOCS_ROOT', dirname(__DIR__));

Without the last line, the redirect works fine, but all assets have wrong paths. After setting COCKPIT_DOCS_ROOT it worked for me. This solution is inspired by #106 (comment) with the new use of defines.php.

For debugging and exploring all the paths, you could add this code to modules/Cockpit/views/layouts/login.php at the beginning of body:

<?php
echo "<pre style='position:absolute;top:0;left:0;'>";//avoid pre to get centered (body CSS)
print_r($_SERVER['DOCUMENT_ROOT']); // may differ from __DIR__
echo "\r\n";
print_r(get_defined_constants(true)['user']); // list all user constants
print_r($app->config['paths']); // list all config paths
echo "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.