Recently, I migrated This Dev Brain and Brain Archives to new VPSs. In both cases, I had to set up the operating systems and install Ghost from scratch. As a result, I've prepared this concise set of instructions in case I need to do this again.
Configure Ubuntu
Add user
Create a new user:
adduser ghostuserAdd user to superuser group to unlock admin privileges:
usermod -aG sudo ghostuserLog in as the new user:
su - ghostuserUpdate packages
Update package lists:
sudo apt-get updateUpdate installed packages:
sudo apt-get upgradeInstall Nginx
Install Nginx package:
sudo apt-get install nginxEnable Nginx in firewall:
sudo ufw allow 'Nginx Full'Install Node.js
Download and import the Nodesource GPG key:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpgCreate deb repository:
NODE_MAJOR=18 # Set latest version that is compatible with Ghost
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.listUpdate and install packages:
sudo apt-get update
sudo apt-get install nodejs -yInstall MySQL
Install MySQL server package:
sudo apt-get install mysql-serverSecure MySQL:
sudo mysql_secure_installationConfigure it like this:
- Set root password? [Y/n] Y
- 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] YIn some cases themysql_secure_installationmight fail because of authorization error. In that case runsudo mysqland then, in MySQL console, run this command:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'Here_Is_Your_MySQL_Root_User_Password';Once database is updated, themysql_secure_installationscript should work properly.
Once the MySQL server is configured, start and enable the MySQL service:
sudo systemctl start mysql
sudo systemctl enable mysqlSetup Database
Login to MySQL server:
sudo mysql -u root -pCreate database:
CREATE DATABASE ghostdb;Create user:
CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'Here_is_Ghost_User_Password';Set privileges:
GRANT ALL PRIVILEGES ON ghostdb. * TO 'ghostuser'@'localhost';Flush privileges:
FLUSH PRIVILEGES;Close MySQL terminal:
exit;Setup Ghost
Ghost CLI
Install Ghost CLI:
sudo npm install ghost-cli@latest -gSetup folder with the site
Create directory. Change sitename to name of your website:
sudo mkdir -p /var/www/<sitename>Set directory owner. Replace ghostuser with the name of the user created at the very beginning of this article:
sudo chown ghostuser:ghostuser /var/www/<sitename>Set the correct permissions
sudo chmod 775 /var/www/<sitename>Then navigate into it:
cd /var/www/<sitename>Ghost Blog
Install Ghost Blog:
ghost installSetup Ghost:
Install questions
? Enter your blog URL: https://sitename.com
? Enter your MySQL hostname: 127.0.0.1
? Enter your MySQL username: ghostuser
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghostdbOnce Ghost Blog is configured, it should start and be ready for further setup at https://sitename.com/ghost.
Comments
Anything interesting to share? Write a comment.