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
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
-
Stop your instance
cd /var/www/old && ghost stop
(reset) - cd ~
-
Rename the folder
mv /var/www/old /var/www/new
-
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"
-
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 contexta.
ssl-params.conf
- change
ssl_dhparam /var/www/old/system/files/dhparam.pem
tossl_dhparam /var/www/new/system/files/dhparam.pem
b.
*-ssl.conf
- change
root /var/www/old/system/nginx-root;
toroot /var/www/new/system/nginx-root;
- change
include /var/www/old/system/files/ssl-params.conf;
toinclude /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 theexample.com.conf
(replaceexample.com
with your domain)
- replace
root /var/www/old/system/nginx-root;
withroot /var/www/new/system/nginx-root;
- change
-
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
-
Restart all services
- Nginx -
sudo nginx -s reload
- Systemd -
sudo systemctl daemon-reload
- Ghost -
cd /var/www/new && ghost start
- Nginx -
-
Profit
- 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):
- (~/.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/'
- (this is just here to fix formatting)
- (/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/'