Ghost-CLI is to makes it possible to install or update Ghost with a single command. In addition, it performs useful operations to assist with maintaining your environment, such as:
- Checking for common environment problems
- Creating a logical folder structure
- Providing for production or development installs
- Allowing for upgrades and rollbacks
- Handling user management and permissions
- Configuring Ghost
- Configuring NGINX
- Setting up MySQL
- Configuring systemd
- Accessing Ghost log files
- Managing existing Ghost installs
Install & update
Ghost-CLI is an npm module that can be installed via either npm.@latest means this command with either install or update ghost-cli and you only have to remember the one command for both ✨
Useful options
There are some global flags you may find useful when usingghost-cli:
Commands
Below are the available commands in Ghost-CLI. You can always runghost --help or ghost [command] --help to get more detail, or inline help for available options.
Ghost config
ghost config accepts two optional arguments: key and value. Here are the three different combinations and what happens on each of them:
ghost config command only affects the configuration files. In order for your new config to be used, run ghost restart.
Options
If you’re usingghost config to generate a configuration file, you can supply multiple key-value pairs in the form of options to avoid being prompted for that value.
All of these options can also be passed to ghost install and ghost setup , as these commands call ghost config.
See the config guide or run ghost config --help for more detailed information.
Application options
Debugging
In order for your new config to be used, runghost restart.
Ghost install
Theghost install command is your one-stop-shop to get a running production install of Ghost.
This command includes the necessary mysql, nginx and systemd configuration to get your publication online, and provides a series of setup questions to configure your new publication. The end result is a fully installed and configured instance ✨
Not ready for production yet?
ghost install local installs ghost in development mode using sqlite3 and a local process manager. Read more about local installs.How it works
Theghost install command runs a nested command structure, but you only ever have to enter a single command.
First, it will run ghost doctor to check your environment is compatible. If checks pass, a local folder is setup, and Ghost is then downloaded from npm and installed.
Next, ghost setup runs, which will provide prompts for you to configure your new publication via the ghost config command, including creating a MySQL user, initialising a database, configure nginx and sets up SSL.
Finally, the CLI will prompt to see if you want to run Ghost and if you choose yes ghost start will run.
Arguments
Options
Asghost install runs nested commands, it also accepts options for the ghost doctor, ghost config, ghost setup and ghost start commands.
See the individual command docs, or run ghost install --help for more detailed information.
Directory structure
When you install Ghost using Ghost-CLI, the local directory will be setup with a set of folders designed to keep the various parts of your install separate. After installing Ghost, you will have a folder structure like this which should not be changed:Ghost setup
ghost setup is the most useful feature of Ghost-CLI. In most cases you will never need to run it yourself, as it’s called automatically as a part of ghost install.
How it works
Setup configures your server ready for running Ghost in production. It assumes the recommended stack and leaves your site in a production-ready state. Setup is broken down into stages:- mysql - create a specific MySQL user that is used only for talking to Ghost’s database.
- nginx - creates an nginx configuration
- ssl - setup SSL with letsencrypt, using acme.sh
- migrate - initialises the database
- linux-user - creates a special low-privilege
ghostuser for running Ghost
What if I want to do something else?
TheGhost-CLI tool is designed to work with the recommended stack and is the only supported install method. However, since Ghost is a fully open-source project, and many users have different requirements, it is possible to setup and configure your site manually.
The CLI tool is flexible and each stage can be run individually by running ghost setup <stage-name> or skipped by passing the --no-setup-<stage-name> flag.
Arguments
Options
Asghost setup runs nested commands, it also accepts options for the ghost config, ghost start and ghost doctor commands. Run ghost setup --help for more detailed information.
Ghost start
Runningghost start will start your site in background using the configured process manager. The default process manager is systemd, or local for local installs.
The command must be executed in the directory where the Ghost instance you are trying to start lives, or passed the correct directory using the --dir option.
Options
Debugging
If runningghost start gives an error, try use ghost run to start Ghost without using the configured process manager. This runs Ghost directly, similar to node index.js. All the output from Ghost will be written directly to your terminal, showing up any uncaught errors or other output that might not appear in log files.
Ghost stop
Runningghost stop stops the instance of Ghost running in the current directory. Alternatively it can be passed the name of a particular ghost instance or directory. You can always discover running Ghost instances using ghost ls.
Arguments
Options
Ghost restart
Runningghost restart will stop and then start your site using the configured process manager. The default process manager is systemd, or local for local installs.
The command must be executed in the directory where the Ghost instance you are trying to start lives, or passed the correct directory using the --dir option.
Options
Debugging
If runningghost restart gives an error, try using ghost run to debug the error.
Ghost update
Runghost update to upgraded to new versions of Ghost, which are typically released every 1-2 weeks.
Arguments
Options
Major updates
Every 12-18 months we release a major version which breaks backwards compatibility and requires a more involved upgrade process, including backups and theme compatibility. Use the update documentation as a guide to the necessary steps for a smooth upgrade experience.Debugging
If runningghost update gives an error, try using ghost run to debug the error.
Ghost backup
Runghost backup to generate a zip file backup of your site data.
How it works
When performing manual updates it’s recommended to make frequent backups, so if anything goes wrong, you’ll still have all your data. This is especially important when updating to the latest major version. This command creates a full backup of your site data, including:- Your content in JSON format
- A full member CSV export
- All themes that have been installed including your current active theme
- Images, files, and media (video and audio)
- A copy of
routes.yamlandredirects.yamlorredirects.json
Ghost doctor
Runningghost doctor will check the system for potential hiccups when installing or updating Ghost.
This command allows you to use ghost-cli as a diagnostic tool to find potential issues for your Ghost install, and provides information about what needs to be resolved if any issues arise.
The CLI automatically runs this command when installing, updating, starting or setting up ghost - and you can use is manually with ghost doctor.
Arguments
Options
Runghost doctor --help for more detailed information.
Ghost ls
Theghost ls command lists all Ghost sites and their status from the ~/.ghost/config file. This is useful if you can’t remember where you installed a particular instance of Ghost, or are working with multiple instances (local, production, staging and so on).
Output
Ghost log
View the access and error logs from your Ghost site (not the CLI). By defaultghost log outputs the last 20 lines from the access log file for the site in the current folder.
Ghost’s default log config creates log files in the content/logs directory, and creates two different files:
- An access log that contains all log levels, named e.g.
[site_descriptor].log - An error log that contains error-level logs only, named e.g.
[site_descriptor].error.log
[proto]__[url]__[env] e.g. http__localhost_2368__development or https__mysite_com__production. The files are be rotated, therefore you may see many numbered files in the content/logs directory.
Arguments
Options
Debugging
There may be some output from Ghost that doesn’t appear in the log files, so for debugging purposes you may also want to try the ghost run command. If you have a custom log configuration theghost log command may not work for you. In particular the ghost log command requires that file logging is enabled. See the logging configuration docs for more information.
Ghost uninstall
Use with caution - this command completely removes a Ghost install along with all of its related data and config. There is no recovery from this if you have no backups. The commandghost uninstall must be executed in the directory containing the Ghost install that you would like to remove. The following tasks are performed:
- stop ghost
- disable systemd if necessary
- remove the
contentfolder - remove any related systemd or nginx configuration
- remove the remaining files inside the install folder
Running
ghost uninstall --no-prompt or ghost uninstall --force will skip the warning and remove Ghost without a prompt.Ghost help
Use the help command to access a list of possibleghost-cli commands when required.
This command is your port of call when you want to discover a list of available commands in the Ghost-CLI. You can call it at any time ✨
Output
Options
It’s also possible to runghost install --help and ghost setup --help to get a specific list of commands and help for the install and setup processes. Don’t worry - you got this! 💪
Knowledgebase
SSL
The CLI generates a free SSL certificate from Let’s Encrypt using acme.sh and a secondary NGINX config file to serve https traffic via port 443. SSL configuration After a successful ssl setup, you can find your ssl certificate in/etc/letsencrypt.
SSL for additional domains
You may wish to have multiple domains that redirect to your site, e.g. to have an extra TLD or to support www. domains. Ghost itself can only ever have one domain pointed at it. This is intentional for SEO purposes, however you can always redirect extra domains to your Ghost install using nginx.
If you want to redirect an HTTPS domain, you must have a certificate for it. If you want to use Ghost-CLI to generate an extra SSL setup, follow this guide:
acme.sh manually if you need to perform extra tasks. The following command will output all available options:
Systemd
systemd is the default way of starting and stopping applications on Ubuntu. The advantage is that if Ghost crashes, systemd will restart your instance. This is the default recommended process manager.
Permissions
Ghost-CLI will create a new system user and user-group calledghost during the installation process. The ghost user will be used to run your Ghost process in systemd.
This means that Ghost will run with a user that has no system-wide permissions or a shell that can be used (similar to other services such as NGINX). Sudo is required to modify files in the The <install-directory>/content/.
To prevent accidental permissions changes, it’s advisable to execute tasks such as image upload or theme upload using Ghost admin.
File Permissions
Theghost-cli enforces default linux permissions (via ghost doctor hooks) for installations.
- For normal users, default directory permissions are 775, and default file permissions are 664.
- For root users, default directory permissions are 755, and default file permissions are 644.
drwxrwxr-x) permissions and file with 664 (-rw-rw-r--) permissions.
These file permissions don’t need to be changed. The only change that is executed by ghost-cli is changing ownership, file permissions stay untouched.
If permissions were changed, the following two commands will revert file and directory permissions to the ones of a non-root user.
setuid and setguid). If your commands keep failing because of file permissions, ensure your directories have no flags!
