How to install Nginx Ghost on FreeBSD 10.2
Node. js is an open-source runtime environment for developing server-side applications. The Node. js application is written in JavaScript and can run on any server with Node. js runtime. It supports Linux, Windows, OSX, ibm aix, And FreeBSD across platforms. Node. js was created in 2009 by Ryan Dahl and other developers working in Joyent. It is designed to build scalable network applications.
Ghost is a blog platform written using Node. js. It is not only open-source, but also has beautiful interface design, user-friendly and free. It allows you to quickly publish content on the network or create your hybrid website.
In this guide, we will install Nginx as the Ghost of the web server on FreeBSD. We will install Node. js, Npm, nginx, and sqlite3 on FreeBSD 10.2.
Step 1-install Node. js npm and Sqlite3
If you want to run ghost on your server, you must install node. js. In this section, we will install node. js from the freebsd porting software library. Please go to the "/usr/ports/www/node" directory and run the "make" command to install it.
cd/usr/ports/www/node
make install clean
If you have already installed node. js, go to the npm directory and install it. Npm is the software package manager used to install, release, and manage node programs.
cd/usr/ports/www/npm/
make install clean
Next, install sqlite3. By default, ghost uses sqlite3 as the database system, but it also supports mysql/mariadb and postgresql. We will use sqlite3 as the default database.
cd/usr/ports/databases/sqlite3/
make install clean
If you have installed all the software, check the node. js and npm versions:
node --version
v0.12.6
npm --version
2.11.3
sqlite3 --version
3.8.10.2
Node and npm versions
Step 2-Add a Ghost user
We will install and run ghost as a common user "ghost. Run the "adduser" command to add a new user:
adduser ghost
FILL WithYour INFO
Add User Ghost
Step 3-install Ghost
We will install the ghost to the "/var/www/" directory. First, create a directory and enter the installation directory:
mkdir-p /var/www/
cd/var/www/
Run the wget command to download the latest ghost version:
wget--no-check-certificate https://ghost.org/zip/ghost-latest.zip
Decompress it to the "ghost" directory:
unzip -d ghost ghost-latest.zip
Next, change the owner to "ghost". We will install and run it as this user.
chown-R ghost:ghost ghost/
If all of them are complete, run the following command to switch to the "ghost" User:
su- ghost
Then go to the installation directory "/var/www/ghost /":
cd/var/www/ghost/
Before installing ghost, we need to install the sqlite3 module for node. js and use the npm command to install it:
setenv CXX c++; npm install sqlite3 --sqlite=/usr/local
Note: run with the "ghost" user instead of the root user.
Now, we are ready to install the ghost. Run the npm command to install it:
npm install --production
Next, copy the configuration file "config. example. js" to "config. js" and edit it in the nano Editor:
cp config.example.js config.js
nano-c config.js
Modify row 25th of the server module:
host:'0.0.0.0',
Save and exit.
Run the following command to run ghost:
npm start --production
Verify by accessing the Server ip address and port 2368.
Ghost Installation Complete
The "ghost" user installs the ghost in the "/var/www/ghost" directory.
Step 4-run Ghost as the FreeBSD Service
To run an application as a service on freebsd, you need to add a script in the rc. d directory. We will create a new service script for ghost in the "/usr/local/etc/rc. d/" directory.
Before creating a service script, to run ghost as a service, we need to install a node. js module and use the npm command to install the forever module with sudo/root permissions:
npm install forever -g
Now go to the rc. d directory and create a new file named ghost:
cd/usr/local/etc/rc.d/
nano-c ghost
Paste the following service script:
#!/bin/sh
# PROVIDE: ghost
# KEYWORD:shutdown
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
./etc/rc.subr
name="ghost"
rcvar="ghost_enable"
extra_commands="status"
load_rc_config ghost
: ${ghost_enable:="NO"}
status_cmd="ghost_status"
start_cmd="ghost_start"
stop_cmd="ghost_stop"
restart_cmd="ghost_restart"
ghost="/var/www/ghost"
log="/var/log/ghost/ghost.log"
ghost_start(){
sudo-u ghost sh -c "cd $ghost && NODE_ENV=production forever start -al $log index.js"
}
ghost_stop(){
sudo-u ghost sh -c "cd $ghost && NODE_ENV=production forever stop index.js"
}
ghost_status(){
sudo-u ghost sh -c "NODE_ENV=production forever list"
}
ghost_restart(){
ghost_stop;
ghost_start;
}
run_rc_command "$1"
Save and exit.
Next, add the executable permission to the ghost service script:
chmod+x ghost
Create a new directory and file for the ghost log, and change the major to the ghost User:
mkdir-p /var/www/ghost/
touch/var/www/ghost/ghost.log
chown-R /var/www/ghost/
Finally, if you want to run the ghost service, you need to run the sysrc command to add the ghost service to start the application at startup:
sysrc ghost_enable=yes
Run the following command to start ghost:
service ghost start
Other commands:
service ghost stop
service ghost status
service ghost restart
Ghost service commands
For more details, please continue to read the highlights on the next page: