How to install Nginx Ghost on FreeBSD 10.2

Source: Internet
Author: User

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.

  1. cd/usr/ports/www/node
  2. 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.

  1. cd/usr/ports/www/npm/
  2. 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.

  1. cd/usr/ports/databases/sqlite3/
  2. make install clean

If you have installed all the software, check the node. js and npm versions:

  1. node --version
  2. v0.12.6
  3. npm --version
  4. 2.11.3
  5. sqlite3 --version
  6. 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:

  1. adduser ghost
  2. 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:

  1. mkdir-p /var/www/
  2. cd/var/www/

Run the wget command to download the latest ghost version:

  1. wget--no-check-certificate https://ghost.org/zip/ghost-latest.zip

Decompress it to the "ghost" directory:

  1. unzip -d ghost ghost-latest.zip

Next, change the owner to "ghost". We will install and run it as this user.

  1. chown-R ghost:ghost ghost/

If all of them are complete, run the following command to switch to the "ghost" User:

  1. su- ghost

Then go to the installation directory "/var/www/ghost /":

  1. 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:

  1. 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:

  1. npm install --production

Next, copy the configuration file "config. example. js" to "config. js" and edit it in the nano Editor:

  1. cp config.example.js config.js
  2. nano-c config.js

Modify row 25th of the server module:

  1. host:'0.0.0.0',

Save and exit.

Run the following command to run ghost:

  1. 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:

  1. npm install forever -g

Now go to the rc. d directory and create a new file named ghost:

  1. cd/usr/local/etc/rc.d/
  2. nano-c ghost

Paste the following service script:

  1. #!/bin/sh
  2. # PROVIDE: ghost
  3. # KEYWORD:shutdown
  4. PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
  5. ./etc/rc.subr
  6. name="ghost"
  7. rcvar="ghost_enable"
  8. extra_commands="status"
  9. load_rc_config ghost
  10. : ${ghost_enable:="NO"}
  11. status_cmd="ghost_status"
  12. start_cmd="ghost_start"
  13. stop_cmd="ghost_stop"
  14. restart_cmd="ghost_restart"
  15. ghost="/var/www/ghost"
  16. log="/var/log/ghost/ghost.log"
  17. ghost_start(){
  18. sudo-u ghost sh -c "cd $ghost && NODE_ENV=production forever start -al $log index.js"
  19. }
  20. ghost_stop(){
  21. sudo-u ghost sh -c "cd $ghost && NODE_ENV=production forever stop index.js"
  22. }
  23. ghost_status(){
  24. sudo-u ghost sh -c "NODE_ENV=production forever list"
  25. }
  26. ghost_restart(){
  27. ghost_stop;
  28. ghost_start;
  29. }
  30. run_rc_command "$1"

Save and exit.

Next, add the executable permission to the ghost service script:

  1. chmod+x ghost

Create a new directory and file for the ghost log, and change the major to the ghost User:

  1. mkdir-p /var/www/ghost/
  2. touch/var/www/ghost/ghost.log
  3. 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:

  1. sysrc ghost_enable=yes

Run the following command to start ghost:

  1. service ghost start

Other commands:

  1. service ghost stop
  2. service ghost status
  3. service ghost restart

Ghost service commands

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.