How to rename ghost installation folder

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/'
4 Likes