BookStackApp / BookStack

A platform to create documentation/wiki content built with PHP & Laravel
https://www.bookstackapp.com/
MIT License
14.87k stars 1.87k forks source link

How to Change domain on Bookstack #4061

Closed Nitro-Zeus98 closed 1 year ago

Nitro-Zeus98 commented 1 year ago

Attempted Debugging

Searched GitHub Issues

Describe the Scenario

Hi, i have used this ticket as "help" to my problem; https://github.com/BookStackApp/BookStack/issues/2305 But I cant get it to work, I want to change my domain name for bookstack since it's expiring soon, an I already have a new ready.

I tried to enter the path -> cd /etc/apache2/sites-enabled then -> sudo nano bookstack.conf ctrl + W ctrl + R i replaced my old domain with the new one. and saved the file.

Then exit and tried to restart apache with the command -> service apache2 restart

But i get error, see the picture. Dont know what to do here?

2023-02-22_18-38-59

I have installed Bookstack with this guide: https://www.bookstackapp.com/docs/admin/installation/ Ubuntu 22.04 Installation Script without any errors. before now where i need to change the domain name.

Exact BookStack Version

Ubuntu 22.04 Installation Script

Log Content

No response

PHP Version

No response

Hosting Environment

Server hosted in Hetzner on ESXI The Virtual Machine with bookstack is sitting behind a pFsense firewall.

ssddanbrown commented 1 year ago

@Nitro-Zeus98 Based on that error, it's very likely the edited apache config file is now invalid in some way. The shown output is providing a hint to gain more information on the error. Run sudo journalctl -xeu apache2.service to gain more info on what's wrong. Otherwise you might find more info in the apache error log file (Commonly at /var/log/apache2/error.log).

Nitro-Zeus98 commented 1 year ago

i have changed the domain back as i did not work with the new one, so i can still access bookstack and everything.

See .txt and picture, what log do you want me to open ? 2023-02-22_21-27-02 journalctl .txt

ssddanbrown commented 1 year ago

@Nitro-Zeus98 error.log is the one. Running tail -n 500 error.log should give you the last 500 lines of it.

Nitro-Zeus98 commented 1 year ago

The website is currently on https://nitrozeus.site/

See the two pictures. 2023-02-23_16-05-51 2023-02-23_16-07-36

ssddanbrown commented 1 year ago

@Nitro-Zeus98 Thanks but you may have gotten to that a little late. Same with the journalctl.txt provided above. These logs can fill fairly fast. Ideally you'll want to check these right after the error has occurred so that the error should be expected at the end of the logs.

Nitro-Zeus98 commented 1 year ago

alright, that makes sense, so what do you want me to do? I tried to change the domain name from nitrozeus.site to cloud-chefen.dk it did not work, so I changed it back. can you give me a guide perhaps on how to do that, I only need to change the domain, I will use certbot later to create a certificate for the domain.

ssddanbrown commented 1 year ago

You could check the logs right after causing the error to occur again. Alternatively, you could provide your config file and explain the changes you made to see if there's anything obvious.

Nitro-Zeus98 commented 1 year ago

I'm not so experienced in this. all did was follow the same thing that was posted here: https://github.com/BookStackApp/BookStack/issues/2305

Is it possible for you to tell me what to do, if I need to change the domain, where should I make the changes? I cannot find any guide on it anywhere :(

If I could just get a how-to I would have no problem doing so, but I need to know where to do the changes :)

ssddanbrown commented 1 year ago

@Nitro-Zeus98 I'd need to know the current state of your BookStack Apache config first to be able to accurately make recommendations. There are things, such as if HTTPS is at play in the config, that can significantly change the steps required.

Nitro-Zeus98 commented 1 year ago

alright, what info would you like me to send to you :) HTTPS does not matter, i will use certbot later to create that for the new domain.

Let me know the commands i should run and i will send you data.

ssddanbrown commented 1 year ago

Please provide the contents of the /etc/apache2/sites-available/bookstack.conf file if it exists.

Nitro-Zeus98 commented 1 year ago

2023-03-01_13-29-44

ssddanbrown commented 1 year ago

Okay, Since there's HTTPS variants for the current apache config it's properly cleaner to set things up as a new virtualhost entry. Before anything, ensure you have the machine backed-up/snapshotted if possible. Some of these commands are potentially dangerous to the system or BookStack content.

If you encounter errors along the way, or things are not as you might expect, stop at that step and report back.

Step 1

Create a new apache virtualhost file, with the path & name: /etc/apache2/sites-available/bs2023.conf, containing the below contents. Replace the single instance of docs.example.com with your new domain in the content of this file.

<VirtualHost *:80>

    # This is a simple example of an Apache VirtualHost configuration
    # file that could be used with BookStack.
    # This assumes mod_php has been installed and is loaded.
    #
    # Change the "docs.example.com" usage in the "ServerName" directive
    # to be your web domain for BookStack.
    #
    # Change the "/var/www/bookstack/public/", used twice below, to the
    # location of the "public" folder within your BookStack installation.
    #
    # This configuration is only for HTTP, Not HTTPS.
    # For HTTPS we recommend using https://certbot.eff.org/

    ServerName docs.example.com
    DocumentRoot /var/www/bookstack/public/

    <Directory /var/www/bookstack/public/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        <IfModule mod_rewrite.c>
            <IfModule mod_negotiation.c>
                Options -MultiViews -Indexes
            </IfModule>

            RewriteEngine On

            # Handle Authorization Header
            RewriteCond %{HTTP:Authorization} .
            RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

            # Redirect Trailing Slashes If Not A Folder...
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_URI} (.+)/$
            RewriteRule ^ %1 [L,R=301]

            # Handle Front Controller...
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Step 2

Activate the above config via sudo a2ensite bs2023.conf. Then restart apache via sudo systemctl restart apache2.service.

Step 3

Assuming the domain is pointing at your server, test access by visiting your domain URL. Visit with /login on the end if your site requires login. You should see your BookStack instance load on that URL but any further links may lead you back to the old site. Also, styles could be missing making everything look strange, that's expected and we'll adjust that later.

Step 4

Go through the certbot process now if you're looking to add HTTPS. Run certbot and select the new domain. Easiest to do that now to avoid repeating the next couple of steps.

Step 5

Now we need to configure the new domain with BookStack. Edit the /var/www/bookstack/.env file and update the APP_URL variable to start with the new base URL for your BookStack site. This should start with http:// (or https:// if done step 4) and should not have a trailing slash.

Step 6

Now, we need to update the URL in the BookStack database content. This can be done via the below command, but you'll need to replace the two URLs in this command, so the old base URL is first, and the new base URL is second.

php /var/www/bookstack/artisan bookstack:update-url https://old-domain.example.com https://new-domain.bookstackapp.com
ssddanbrown commented 1 year ago

Since there's been no follow-up on the above I'll close this off but feel free to still comment if needed.

Nitro-Zeus98 commented 1 year ago

Sorry for the late replies, have been kinda busy

The virtual machine is backed up with Veeam to a storage box.

Step one, how do i create a new apache virtual host file. How do i do that.

is there no other way than this :O I just ned the domain name changed? it's okay to remove the https if that helps?

ssddanbrown commented 1 year ago

how do i create a new apache virtual host file. How do i do that.

You just create and edit a file at the described name (Using your favourite editor like nano or vim or whatever).

is there no other way than this :O I just ned the domain name changed?

There's probably a few ways, I have tried to provide the most direct way I could explain since the exiting website state can complicate matters.

it's okay to remove the https if that helps?

Not really, but i've made this optional as touched upon in step 4.

Nitro-Zeus98 commented 1 year ago

Alright so step one the following command goes sudo nano /etc/apache2/sites-available/bs2023.conf the replace docs.example.com with cloud-chefen.dk and paste in the command

image

step 2 does not work, i have not tried to type anything after that, what should i write. image

ssddanbrown commented 1 year ago

step 2 does not work, i have not tried to type anything after that

I'm not sure I understand, that looks like it's worked. Run the other command i listed in step 2 then move on to step 3.

Nitro-Zeus98 commented 1 year ago

my bad xD i have some issues with firewall rules, regarding certificate registration, i will fix that and return later with info

Nitro-Zeus98 commented 1 year ago

i think that's all should i do more as of now? image

ssddanbrown commented 1 year ago

@Nitro-Zeus98 If you've gone through all the steps, that's all that should be needed.

Nitro-Zeus98 commented 1 year ago

should i do as it says on the picture "Be sure to run php artisan cache:clear to clear any old URLs in the cache" ?

Website seems to be working amazing with the new domain name, Thank you so much <3 you don't know how much this means to me :)

ssddanbrown commented 1 year ago

should i do as it says on the picture, "Be sure to run php artisan cache:clear to clear any old URLs in the cache" ?

Might as well, there's no harm in running that.

Website seems to be working amazing with the new domain name, Thank you so much <3 you don't know how much this means to me :)

Happy to hear that, thanks, and happy to help!

Nitro-Zeus98 commented 1 year ago

Hmm does not seem to work xD image

ssddanbrown commented 1 year ago

@Nitro-Zeus98 Such commands are ran from your BookStack install directory. So cd /var/www/bookstack first then run the command.

Nitro-Zeus98 commented 1 year ago

Amazing works like a champ, thanks again Dan this is very much appreciated. Hope you have a nice day :) image

ssddanbrown commented 1 year ago

Awesome! will go ahead and close this off.