I have installed Cockpit in a subfolder on a shared hosting and followed the information provided in https://github.com/agentejo/cockpit/issues/704#issuecomment-405016371 to setup the paths. Now I am able to access the admin interface at https://mydomain.com/cockpit and everything seems to work. But I am not able to accss API. If I am not logged in, every request is redirected to the login and if I am logged in, every request returns status 404. I try to reach the api at https://…n.com/cockpit/api/… What am I doing wrong?
EDIT: Sorry, I had to shorten the last link as the forum allows new users only to post two links in a post. It should also start with mydomain…
EDIT 2:
Some more information about my setup:
Cockpit is located at /home/user/public_html/dir/cockpit
The document root points to /home/user/public_html
A htaccess file is used to redirect everyting to “dir”
I use a “defines.php” file like provided in the above link to avoid having “dir” in the URL
If I remove the “defines.php”, the “dir” is in the url, but I can access the API.
I collected a few defines from tests on different hosts before. Maybe, there is one for you. If you nest your cockpit deeper, you may adjust some paths to something like basename(basename(__DIR__))…
Setup (I used PHP and not the API, but I tested the API for the forms endpoint):
Hi @raffaelj! I’ve read that you successfully used Cockpit with a subdomain on Uberspace. Maybe you can help me with it because I did not get it to work. I tried it with RewriteBase / and also with the file defines.php but nothing did really work. The best result until now was a successful installation of cockpit and getting redirected to the desired address /auth/login but there I got only an error from the browser saying there are too many redirects
Do you use Uberspace6 or 7? If I remember correctly, I only tested a subdomain in /var/www/$USER/virtual/sub.domain.com/ on an old U6 host and I had to set RewriteBase /. I think, I never tested it on an U7 with a subdomain, but I’m not sure anymore.
Is Cockpit in your root .../sub.domain.com/ or in a subfolder .../sub.domain.com/cockpit/?
Does Cockpit work in /var/www/$USER/virtual/html/?
Thanks for the quick reply.
I’m on Uberspace 7. Cockpit works in the default document root (/virtual/html/) but not for my subdomain (cms.$USERNAME.uber.space/) where I put it in root. So no extra folder.
When only including the RewriteBase rule I get redirected to cms.$USERNAME.uber.space/var/www/virtual/$USERNAME/cms.$USERNAME.uber.space/auth/login and the site is really broken:
The DOCUMENT_ROOT variable set by Apache always points to the one and only DocumentRoot /var/www/virtual/<username>/html so you will will get a misleading value. There is no way to change that behaviour. DocumentRoot — Uberspace 7 manual 7.15.4 documentation
So you would have to adjust some constants via defines.php
Or just create a second Uberspace and split the bill. I think, I never tested subdomains on an U7 host because they disabled wild card subdomains, which was a very fast way for quick tests.
We strongly suggest to use different accounts for different projects due to security reasons. If one of the DocumentRoots gets compromised (e.g. because of a CVE), all other files within all other DocumentRoots can be compromised as well.
(de) German cite from the old U6 wiki about multiple hosts
[…] uns ist schließlich egal, ob du z.B. monatlich 10 Euro für einen Uberspace bezahlst, oder ob du monatlich je 2 Euro für 5 Uberspaces bezahlst. Es macht ja auch keinen Unterschied vom Ressourcenbedarf her, ob du die gleichen Programme und die gleichen Besucherzahlen auf mehrere Accounts aufteilst oder nicht. […] Uberspace 7 manual — Uberspace 7 manual 7.15.4 documentation
No problem. After including every constant in the defines.php (also with the help of your debug snippet) the login page is now showing up correctly but strangely the login is not working after executing the install script and trying to login with admin / admin. It always states: Login failed.
Maybe you have an idea what the issue could now be? If not, thank you very much for your effort nevertheless.
Can you open your developer console and look at the response of /auth/check, that should be called after pressing the login button. Maybe it works already, but there is an error message on top of the json response that will stop the page from reading it as success and redirecting to the dashboard.
I don’t assume, that you use Internet Explorer, but if so, the login fails because of a missing Promise polyfill.
And if you get it running, please share your setup.
nano bootstrap.php --> add debugging snippet directly after the constants defines and before function cockpit(...) starts
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>";
die;
open https://username.uber.space in browser to see the expected constants
Now to the sub domain.
add sub domain uberspace web domain add test.myurl.de
test.myurl.de points to /var/www/virtual/username/test.myurl.de
Don’t forget to delete the debugging snippet in bootstrap.php.
Call /install in browser or use the cli to create a new user
I was able to login and to logout, I created a collection from the posts template and I saved one entry. I didn’t test anything else. So it seems to work with this setup.
Thanks for checking it again and sorry for not responding earlier. Hmm strange, I think I did the same things like you described and the developer console (on Chrome) didn’t show anything as far as I know. But I will have a look at it again later this week, when I have some time left.
I can’t remember, if I read it somewhere, but I’m pretty sure, that you can’t setup a “sub-subdomain”, which technically is a subdomain. $USER.uber.space is registered automatically and cms.$USER.uber.space would be a wildcard subdomain, that isn’t supported. In my test I used my own (sub)domain and it worked on the first try.