How to rename ghost installation folder

Hello.

I would like to rename one of my ghost installation folder from x.dn.tld to y.dn.tld. I updated the contentPath value in config.production.json accordingly but ghost encounters an error:

✖ Starting Ghost
A GhostError occurred.

Message: Ghost process exited with code: 0

Reverting the folder name and the contentPath value to their original name resolves the issue.

I am running multiple ghost instances behind a fairly standard reverse proxy.

Debug error aren’t helpful:

Debug Information:
    OS: Debian, v9.4
    Node Version: v8.11.3
    Ghost-CLI Version: 1.8.1
    Environment: production
    Command: 'ghost start'
Message: Ghost process exited with code: 0
Stack: Error: Ghost process exited with code: 0
    at ChildProcess.cp.on (/home/jhnchr/.npm-global/lib/node_modules/ghost-cli/lib/utils/local-process.js:56:24)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
1 Like

Changing folders is pretty tricky because every aspect of the installation needs to be updated. Here’s what needs to be done for the recommended stack (Ubuntu 16 + nginx + systemd)

Run these commands as the user that installed Ghost. I think this is everything you need to do, but I might be missing something. Think of this post as a living document :smile:

Please don’t blindly copy and paste these commands without understanding what they do fully. There’s implicit example information in these commands which could make life harder if you don’t update the command.

These commands are based on migrating from /var/www/old to /var/www/new

  1. Stop your instance

    cd /var/www/old && ghost stop

(reset) - cd ~

  1. Rename the folder

    mv /var/www/old /var/www/new

  2. Update the global config (~/.ghost/config).

    Open up your favorite editor and manually update the text (if you don’t have a favorite editor, nano is a great choice) - nano ~/.ghost/config.

    You’re looking for the line that says "cwd": "/var/www/old", which you want to update to "cwd": "/var/www/new"

  3. Update the nginx config

    All of the config files that Ghost uses are located in /path/to/ghost/system/files. To update your nginx config, you need to edit 3 files (assuming you have ssl enabled). cd into the config files directory and open up the following files in your editor, making the changes following the filename. All you’re doing is updating folder names - the extra info I’m writing is to give you proper context

    a. ssl-params.conf

    1. change ssl_dhparam /var/www/old/system/files/dhparam.pem to ssl_dhparam /var/www/new/system/files/dhparam.pem

    b. *-ssl.conf

    1. change root /var/www/old/system/nginx-root; to root /var/www/new/system/nginx-root;
    2. change include /var/www/old/system/files/ssl-params.conf; to include /var/www/new/system/files/ssl-params.conf;

    c. The other .conf file

    • there’s no wildcard way to tell you which file this is, so just run ls -al /var/www/old/system/files/ and look for the example.com.conf (replace example.com with your domain)

    1. replace root /var/www/old/system/nginx-root; with root /var/www/new/system/nginx-root;
  4. Update the systemd config

    This config file is located in the same directory as the nginx config files (/path/to/ghost/system/files)

    *.service - replace /var/www/old with /var/www/new

  5. Restart all services

    • Nginx - sudo nginx -s reload
    • Systemd - sudo systemctl daemon-reload
    • Ghost - cd /var/www/new && ghost start
  6. Profit :sunglasses:

    • Hopefully everything went off without a hitch!

Sed

Sed (stream editor) is a really powerful tool which might be able to make updating these files easier. These commands aren’t bulletproof. Use with caution. If you don’t trust it, the manual version is perfectly acceptable. You might want to make a backup of these files. Here’s the sed command you can run instead of manually editing files (the number corresponds to the step above):

  1. (~/.ghost/config) sed -i ~/.ghost/config -e 's/cwd\": \"\/var\/www\/old/cwd\": \"\/var\/www\/new/'
    4.a.1 (/path/to/ghost/system/files/ssl-params.conf) sed -i /path/to/ghost/system/files/ssl-params.conf -e 's/\/var\/www\/old/\/var\/www\/new/'
    3.b.1 (/path/to/ghost/system/files/example.com-ssl.conf) sed -i /path/to/ghost/system/files/example.com-ssl.conf -e 's/\/var\/www\/old/\/var\/www\/new/'
    4.b.2 - nothing (4.b.1 handles it for you!)
    4.c.1 (/path/to/ghost/system/files/example.com.conf) sed -i /path/to/ghost/system/files/example.com.conf -e 's/\/var\/www\/old/\/var\/www\/new/'
  2. (this is just here to fix formatting)
  3. (/path/to/ghost/system/files/name_example-com.service) sed -i /path/to/ghost/system/files/name_example-com.service -e 's/\/var\/www\/old/\/var\/www\/new/'
3 Likes

Thanks, that was the missing step.

Curiously there was only one of the ghost instances referenced in my ~/.ghost/config file so I fixed that and now ghost status seems to work as expected.

It was also necessary to repair two broken links:

$ ln -s $ghostpath/current/content/themes/casper $ghostpath/content/themes/casper
$ ln -s $ghostpath/versions/1.24.4 $ghostpath/current

I am running a bunch of ghost instances on different ports each and apache2 is used as a reverse proxy and handles vhost and SSL. Sorry for not being more explicit about it, it would have saved you time (but as you wrote it it’s going to be useful for someone else anyway :) )

You’re right, I missed that! I’ll update my OP in a bit

No worries, as you said I wrote it because I’ve seen it asked a few times and figured it was worth spending a bit of time documenting it :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

Thanks gargol for reopening this topic and thanks vikaspotluri123 for your solution, it helped me.

In addition to the above, I also had to fix folder ownerhip and systemctl issues (broken symlinks in /etc/systemd/system/).

My environment looks like this:

  • Multiple Ghost instances are configured to be served through Apache via reverse proxy
  • We are running Ubuntu 18.10.

A quick overview of what I had to do (note that I’m fairly new to Linux so some of this may not be the best way to do this:

  1. Rename the original directory or move the files
  2. Fix Apache vhost files in /etc/apache2/sites-available (if running reverse proxy with Apache, otherwise follow the steps posted above by vikaspotluri123 to fix NGINX)
  3. Update your ghost config file vi config.production.json
  4. Fix broken symlinks with ln -sf (use the “f” option to overwrite the existing, broken links)
    (a) /current should point to /versions/YOUR_CURRENT_VERSION so for me I had to run (from my ghost instance directory):
    ln -sf ./versions/2.25.2 ./current
    (b) and /content/themes/casper should point to /current/content/themes/casper, so:
    ln -sf ./current/content/themes/casper ./content/themes/casper
  5. Fix any broken folder ownerships with ghost doctor
  6. Fix any broken symlinks in /etc/systemd/system/ so that systemd can automatically start your ghost blog
    (a) You can check if you have any broken services with systemctl list-unit-files | grep bad or by running ls -lha from /etc/systemd/system/
    (b) I had to run the following to fix my broken service file: sudo ln -sf /var/www/hungariantranslation.com/en/system/files/ghost_be ghost_beta-hungariantranslation-com.service

You can read a more detailed write-up.

1 Like

P.s. if there are any Ghost devs here, some of the above steps would not be necessary if the ghost installer created relative symlinks instead of absolute ones! Although there may be a good reason for doing so. It’s just a thought.
Also, wouldn’t it be great if ghost CLI could automate the above with a “move” command to move an existing ghost installation? ;-) In any case, I :green_heart: Ghost!

1 Like

For folks who are struggling to make this work, make sure that you follow each and every instruction of @lieszkol along with the ones written by @vikaspotluri123 .

Some additional notes from my side

Fix Apache vhost files in /etc/apache2/sites-available (if running reverse proxy with Apache, otherwise follow the steps posted above by vikaspotluri123 to fix NGINX)

Most people would be using nginx instead of apache, especially if they used the default ghost installer. In that case fix the the broken sylinks in /etc/nginx/sites-available to point to the appropriate files in /path/to/ghost/system/files.

Update your ghost config file vi config.production.json

I missed this step thinking that it was the same instruction covered by @vikaspotluri123 in third point. But its diffrent. Mentioning just in case someone else misses this step as well.

Also @lieszkol has written a more detailed post here. Its not super visible so mentioning it again.

@lieszkol @vikaspotluri123 Thanks for the awesome write up. Much power to you :slight_smile:

2 Likes

and the one that drove me nuts - fix the contents of /var/www/new-name/.ghost-cli*

I’ve just done this to one of my domains :slight_smile: but I haven’t yet managed to restart ghost. Will keep trying all options mentioned in this thread. :slight_smile: My error log:

Debug Information:
    OS: Ubuntu, v20.04.1 LTS
    Node Version: v12.18.4
    Ghost Version: 3.33.0
    Ghost-CLI Version: 1.14.1
    Environment: production
    Command: 'ghost setup'
Message: Could not communicate with Ghost
Suggestion: journalctl -u ghost_be-digitalentrepreneur-eu -n 50
Stack: Error: Could not communicate with Ghost
    at Server.<anonymous> (/usr/lib/node_modules/ghost-cli/lib/utils/port-polling.js:56:20)
    at Object.onceWrapper (events.js:421:28)
    at Server.emit (events.js:315:20)
    at emitCloseNT (net.js:1654:8)
    at processTicksAndRejections (internal/process/task_queues.js:83:21)

The issue with this error message is that it doesn’t say anything about the broken parts, i.e.:

  • the broken casper theme link
  • the broken systemd link (though I reconfigured that and still failed)
  • the broken current version link

I’ve fixed all these though, even went again through ghost setup and reconfigured it, but it still fails to start.

The error put out by journalctl:

Sep 21 16:32:57 ghost-tigros-ro node[70495]: - Inspecting operating system
Sep 21 16:32:57 ghost-tigros-ro node[70519]: /home/forge/be.digitalentrepreneur.eu/public/versions/3.33.0/core/shared/config/util>
Sep 21 16:32:57 ghost-tigros-ro node[70519]:         throw new Error('Your content path does not exist! Please double check `path>
Sep 21 16:32:57 ghost-tigros-ro node[70519]:         ^
Sep 21 16:32:57 ghost-tigros-ro node[70519]: Error: Your content path does not exist! Please double check `paths.contentPath` in >
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at exports.Provider.doesContentPathExist (/home/forge/be.digitalentrepreneur.eu/>
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Object.loadNconf (/home/forge/be.digitalentrepreneur.eu/public/versions/3.33.>
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Object.<anonymous> (/home/forge/be.digitalentrepreneur.eu/public/versions/3.3>
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Module._compile (internal/modules/cjs/loader.js:1137:30)
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Module.load (internal/modules/cjs/loader.js:985:32)
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Function.Module._load (internal/modules/cjs/loader.js:878:14)
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Module.require (internal/modules/cjs/loader.js:1025:19)
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at require (internal/modules/cjs/helpers.js:72:18)
Sep 21 16:32:57 ghost-tigros-ro node[70519]:     at Object.<anonymous> (/home/forge/be.digitalentrepreneur.eu/public/versions/3.3>
Sep 21 16:32:58 ghost-tigros-ro systemd[1]: ghost_be-digitalentrepreneur-eu.service: Succeeded.
Sep 21 16:32:58 ghost-tigros-ro systemd[1]: ghost_be-digitalentrepreneur-eu.service: Scheduled restart job, restart counter is at>
Sep 21 16:32:58 ghost-tigros-ro systemd[1]: Stopped Ghost systemd service for blog: be-digitalentrepreneur-eu.
Sep 21 16:32:58 ghost-tigros-ro systemd[1]: ghost_be-digitalentrepreneur-eu.service: Start request repeated too quickly.
Sep 21 16:32:58 ghost-tigros-ro systemd[1]: ghost_be-digitalentrepreneur-eu.service: Failed with result 'start-limit-hit'.
Sep 21 16:32:58 ghost-tigros-ro systemd[1]: Failed to start Ghost systemd service for blog: be-digitalentrepreneur-eu.

LE: found that during the setup, ghost changed the port, so I had to update that one in config.production.json to get it back to its original version. However, ghost still doesn’t start (tried even a server restart). I’ve found the wrong content path in config.production.json though (which solved the issue), heh. :slight_smile:

Is there yet a simpler method to move a local ghost installation to a different folder via a simple CLI command perhaps?

Looking for step by step guide how to move Ghost from one directory to another.