Ghost is an opensource publishing platform for the modern web. This setup uses MariaDB and Nginx to provide a complete production environment to run websites and blogs powered by Ghost.
This post shows new users and students how to easily install Ghost on Ubuntu 16.04 / 17.10 and 18.04. Ghost is a fairly new blogging platform powered by Node.js. Ghost is a very clean and lightweight platform designed for bloggers who want to focus on blogging and nothing else.
To get Ghost quickly running on Ubuntu, follow the steps below
To get started with installing Ghost, follow the steps below:
Step 1: Install Nginx HTTP Server
Ghost CMS requires a web server and Nginx HTTP server is the most popular open source web server available today. To install Nginx server, run the commands below:
sudo apt update sudo apt install nginx
After installing Nginx, the commands below can be used to stop, start and enable Nginx service to always start up with the server boots.
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
Now that Nginx is installed. to test whether the web server is working, open your browser and browse to the URL below.
If you see the page above, then Nginx is successfully installed.
Step 2: Install MariaDB Database Server
Ghost also requires a database server to store its content. If you’re looking for a truly open source database server, then MariaDB is a great place to start. To install MariaDB run the commands below:
sudo apt-get install mariadb-server mariadb-client
After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.
Run these on Ubuntu 16.04 LTS
sudo systemctl stop mysql.service sudo systemctl start mysql.service sudo systemctl enable mysql.service
Run these on Ubuntu 18.10 and 18.04 LTS
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.
When prompted, answer the questions below by following the guide.
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Enter password
- Re-enter new password: Repeat password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Now that MariaDB is installed, to test whether the database server was successfully installed, run the commands below.
sudo mysql -u root -p
type the root password when prompted.
If you see a similar screen as shown above, then the server was successfully installed.
Step 4: Create Ghost Database
Now that you’ve installed all the packages that are required for Ghost to function, continue below to start configuring the servers. First run the commands below to create a blank Ghost database.
To logon to MariaDB database server, run the commands below.
sudo mysql -u root -p
Then create a database called ghost
CREATE DATABASE ghost;
Create a database user called ghostuser with a new password
CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'new_password_here';
Then grant the user full access to the database.
GRANT ALL ON ghost.* TO 'ghostuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
Finally, save your changes and exit.
FLUSH PRIVILEGES; EXIT;
Step 5: Install Node.js package
Since Ghost is based on Node.js run the commands below to download Node.js packages from its repository
sudo apt install curl curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
Next, run the commands below to install Node.js and required packages in order for Ghost to function. Nginx webserver will be needed for this. s
sudo apt-get install nodejs
Next, run the commands below to include Yarn repository and enable it.
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt update sudo apt-get -o Dpkg::Options::="--force-overwrite" install yarn
Step 6: Install and Configure Ghost
For this, we’re going to create a new user account called ghostuser which will be used to install Ghost.
Run the commands below to create a new user account called ghostuser. You’ll be asked to create a new password
sudo adduser ghostuser
Then enable the new account to run sudo command
sudo usermod -aG sudo ghostuser
Next, change or su – to ghostuser
su - ghostuser
Now create a new Ghost root directory for its content.
sudo mkdir -p /var/www/html/ghost/
Next, change the directory permissions so the ghostuser owns it
sudo chown -R ghostuser:ghostuser /var/www/html/ghost sudo chmod -R 755 /var/www/html/ghost
If npm isn’t installed, run the commands below to install it
sudo yarn global add ghost-cli
Then change into the ghost root directory and run the commands below to install Ghost. make sure you’re running the command as ghostuser.
cd /var/www/html/ghost ghost install
This should begin Ghost installation. you’ll be prompted for info about the site URL, database connection information to complete the installation.
Checking system Node.js version ✔ Checking logged in user ✔ Checking current folder permissions ✔ Checking operating system compatibility ✔ Checking for a MySQL installation ✔ Checking memory availability ✔ Checking for latest Ghost version ✔ Setting up install directory ✔ Downloading and installing Ghost v2.6.0 ✔ Finishing install process ? Enter your blog URL: https://example.com ? Enter your MySQL hostname: localhost ? Enter your MySQL username: ghostuser ? Enter your MySQL password: [hidden] ? Enter your Ghost database name: ghost ✔ Configuring Ghost ✔ Setting up instance + sudo useradd --system --user-group ghost + sudo chown -R ghost:ghost /var/www/html/ghost/content ✔ Setting up "ghost" system user ? Do you wish to set up "ghost" mysql user? (Y/n)
Type Y to setup MySQL user.
Do not enable SSL if you don’t have it
✔ Setting up Nginx ? Do you wish to set up SSL? Yes Enter your email (used for Let's Encrypt notifications) email@example.com Running sudo command: mkdir -p /etc/letsencrypt Running sudo command: ./acme.sh --install --home /etc/letsencrypt Running sudo command: /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --domain example.com --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail firstname.lastname@example.org Running sudo command: openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048 Running sudo command: mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf ✔ Creating ssl config file at /var/www/html/ghost/system/files/example.com-ssl.conf Running sudo command: ln -sf /var/www/html/ghost/system/files/example.com-ssl.conf /etc/nginx/sites-available/example.com-ssl.conf Running sudo command: ln -sf /etc/nginx/sites-available/example.com-ssl.conf /etc/nginx/sites-enabled/example.com-ssl.conf Running sudo command: nginx -s reload ✔ Setting up SSL ? Do you wish to set up Systemd? Yes ✔ Creating systemd service file at /var/www/html/ghost/system/files/ghost_example-com.service
Next, accept these settings and complete the setup
✔ Setting up Systemd ? Do you want to start Ghost? Yes + sudo systemctl is-active ghost_example-com ✔ Ensuring user is not logged in as ghost user ✔ Checking if logged in user is directory owner ✔ Checking current folder permissions + sudo systemctl is-active ghost_example-com ✔ Validating config ✔ Checking folder permissions ✔ Checking file permissions ✔ Checking content folder ownership ✔ Checking memory availability + sudo systemctl start ghost_example-com ✔ Starting Ghost + sudo systemctl is-enabled ghost_example-com + sudo systemctl enable ghost_example-com --quiet ✔ Enabling Ghost instance startup on server boot Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/mail ------------------------------------------------------------------------------ Ghost was installed successfully! To complete setup of your publication, visit: https://example.com/ghost/
After that, Ghost should be installed and ready to use. Continue with setting up your Ghost site.
Congratulations! You have successfully install Ghost on Ubuntu with Nginx suppot.
You may also like the post below: