Build Ghost's Open source blog system based on node. js

Source: Internet
Author: User
Tags mysql code install node



Install MySQL


# Install mysql$ apt-get Update # Update component $ apt-get install mysql-server mysql-client-y # Quick Install-y represents the default selection, and you only need to set the root password for MySQL # setting  Place MySQL code $ sudo vi/etc/mysql/mysql.cnf # search to [mysqld] Insert collation-server = utf8_unicode_ci init-connect = ' SET NAMES UTF8 ' Character-set-server = utf8$ service MySQL Restart # Restart effective $ mysql-u root-p # Enter the password set above $ show variables like ' char% ' $ sho W variables like ' collation% ' # to see if it is changed to Utf-8 or after the database memory is stored in Chinese is garbled # Create Ghost database $ create DB Mousycoder # Here's mousycoder for you want to Replace the database name, the proposal and the domain name consistent, convenient for later maintenance. $ CREATE Database Mousycoderdev # This is Ghost launcher there are 2 modes a development mode a production mode this is the database of development mode, if you do not want to be so troublesome, just use to build a database. $ create user ' mousycoder ' @ ' localhost ' identified by ' 123456 ' # here is a new user Mousycoder password is 123456, of course my password is not 123456, for your own =, also recommended user name, database name, service name, group name, and domain names are consistent, here is to establish a local operation only users, remote cannot operate, security policy. $ grant all privileges on mousycoder.* to ' mousycoder ' @ ' localhost ' $ grant all privileges on mousycoderdev.* to ' Mousycoder ' @ ' localhost ' # here is to give Mousycoder this local user all the permissions on the database Mousycoder and Mousycoderdev, of course here you can give the right according to the actual needLimit. $ FLUSH Privileges # re-read the data in the permissions table to memory, without restarting MySQL can allow permissions to take effect, the benefits can prevent the modification of errors, there is no room to go back.

Run node js forever 

Additional Information

Node forever

MySQL Remove anonymous account, disable root telnet:$ sudo mysql_secure_installation;answer N,y,y,y,y

Grant Usage: Grant permission 1, permission 2,... Permission n on the database name. Table name to User name @ user address identified by ' password '
Where permissions 1, permissions 2,... Permission N represents Select,insert,update,delete,create,drop,

How to run node server forever

Index,alter,grant,reload,references,shutdown,process,file14 a permission.
For example: ' Grant Select,insert,update,delete,create,drop on Mousycoder.employee to
[email protected] identified by ' 123456′ '
Delegate to the user hello from 10.163.225.87 to assign permissions to operations such as Select,insert,update,delete,create,drop the employee table mousycoder the database. and set the password to 123456.

Forever monitor node js

MySQL garbled reason detailed explanation can refer to the former civil People's blog

Installing Nginx






# installation nginx$ apt-get install nginx-y $ apt-get Install curl-y # curl is a command-line tool that sends a network request and then gets and extracts data. $ curl-i 127.0.0.1 # Make sure Nginx runs, default listener 80 Port # Set web directory and cache directory $ mkdir/var/www$ mkdir-p/var/cache/nginx #-P can suddenly put the middle path does not exist Folders are also built together, very practical $ chown www-data:www-data/var/www # Nginx installation will automatically establish user Www-data and default with this user action $ chown www-data:www-data/var/ cache/nginx# Modify configuration file (typically do not manipulate this file) $ cp/etc/nginx/nginx.conf/etc/nginx/nginx.conf.old # Backup originally configured $ vi/etc/nginx/nginx.conf # You can modify the default user for other users # to create an Nginx profile for ghost alone $ rm/etc/nginx/sites-enabled/default # Delete the default configuration $ vi/etc/nginx/sites-available/ Mousycoder # Creating an Nginx configuration file




























Nginx configuration file









server {    listen 0.0.0.0:80; # Listening port number    server_name mousycoder.com; Replace the mousycoder.com with their own domain name, if there is no domain name or website has not been filed down here can write IP, For example, if you configure multiple Web sites, you can use different ports to correspond to different websites, for example, 120.25.150.209:81, 120.25.150.209, and so on if they can be accessed.    Access_log/var/log/nginx/mousycoder.log;    Location/{        proxy_set_header Host $http _host;        Proxy_set_header x-nginx-proxy true;        Proxy_set_header x-real-ip $remote _addr;        Proxy_pass http://127.0.0.1:2368;  # This is the default port when Ghost starts, can be changed according to the actual situation, the default can also        #proxy_buffering off;        Proxy_redirect off;    }}




























Then restart the service









$ ln-s/etc/nginx/sites-available/mousycoder/etc/nginx/sites-enabled/mousycoder # establishes a soft link to the actual configuration path, which facilitates uniform maintenance of configuration file changes. $ service Nginx Restart # Nginx installed when the system has been registered by default services, we can directly restart the Nginx service, let the configuration file take effect




























Additional Information





Nginx here is mainly to do port forwarding mapping, of course, it is very resistant to pressure.



Install node. js






$ wget http://nodejs.org/dist/v0.10.39/node-v0.10.39-linux-x64.tar.gz $ tar zxf node-v0.10.39-linux-x64.tar.gz & & CD node-v0.10.39-linux-x64$ CP bin/*/usr/bin # Copy execution directory, equivalent to set an environment variable to the user's Bin directory




























Additional Information





Download here is not the latest version of the Nodejs, in order to stabilize .
Ghost website Explained



Starting with ghost 0.6.0, the Ghost Chinese full package has integrated the Nodejs 0.12 version of the Sqlite3 native library, which can be directly on the Windows (32/64 bit), Linux (32/64 bit), Mac ( Run on the Nodejs 0.10.x and 0.12.x versions. However, we strongly recommend that you use the latest version of node. JS 0.10.x. Support for the node. JS 0.12.x release is yet to be tested!



For details see Ghost Chinese web, of course nodejs there are many kinds of installation methods, personally think this is the most suitable method here.



Install Ghost Download Ghost






$ cd/var/www/$ curl-l http://dl.ghostchina.com/Ghost-0.6.3-zh.zip-o mousycoder.zip$ unzip mousycoder.zip-d Mousycoder $ CD mousycoder/

























Configure Ghost


Ghost has two modes of operation: Development mode and product mode, configured via Config.js









$ cp config.example.js config.js$ VI config.js




























Configuring in the Config.js configuration file









-Production # production mode    production:{       URL: ' http://mousycoder.com ',       main:{},       database:{           client: ' MySQL ',           connection:{               host: ' 127.0.0.1 ',               User: ' Root ',  # Users of database connections               password: ' 123456 ',               Database: ' Mousycoder ',               CharSet: ' Utf-8 '           }       }    }-Development # Development mode    production:{       URL: ' Http://mousycoder.com ',       main:{},       database:{           client: ' MySQL ',           connection:{               host: ' 127.0.0.1 ', user               : ' root ',  # Users of database connections               password: ' 123456 ', "Database               : ' Mousycoderdev ',               CharSet: ' Utf-8 '}}    


























Installation and operation


Depending on the Package.json installation dependency package, enter the current Mousycoder directory









$ cd/var/www/mousycoder$ npm Install--production  # Product mode; Install only running packages $ NPM Install # development mode, default is development mode

NPM Start--production




























Run Ghost with Mousycoder (non-root account running Ghost is more secure)









$ adduser-shell/bin/bash--gecos ' mousycoder blog ' mousycoder$ chown-r mousycoder:mousycoder/var/www/mousycoder




























Install forever, keep ghost running in the background









$ cd/var/www/mousycoder$ NPM Install FOREVER-G # Global Installation Forever module $ node_env=production Forever start Index.js # production mode background run Gho St




























Installing system Services









$ Curl Https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost-o/etc/init.d/mousycoder # Download Ghost supplied script to the/etc/init.d/directory, which is the system service directory $ chmod +x/etc/init.d/mousycoder # give the script Execute permissions $ usermod-ag mousycoder Www-data # put W Ww-data user joins the Mousycoder group, allowing it to manipulate directories such as source files $ update-rc.d mousycoder Defaults # UPDATE-RC.D installation Service mousycoder$ UPDATE-RC.D Mousycoder Enable # Refreshes the service to prevent a previous duplicate name of the $ service Mousycoder status # To view the state of the Mousycoder service Mousycoder start # So the boot will start automatically Ghost production environment, do not believe reboot a bit




























Additional Information



Curl Common command details can refer to Nanyi's blog



$ curl-l https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost-o Ghost #-L Resolve website address auto Jump after not get file $ Curl-v www.baidu.com  # Show verbose process contains HTTP header $ curl-u Username:password URL Resolution page requires authorization to enter user name password condition $ curl-u username--data "param 1=value1¶m2=value2 "https://api.github.com  # POST Request $ curl-i-X DELETE https://api.github.com  # Fix get How to request outside post $ curl--form "[email protected]" Http://hostname/resource  # Upload file









chmod command



$ chmod-r A-W ABC # Cancel-W (write) permission for/ABC directory











Drwxr-xr-x first column D directory 第2-4 column owner permissions rwx 5-7 columns r-x same group user rights r-x is other group user rights, where rwx corresponds 4,2,1



System service Boot Order



$ update-rc.d A Start 1 2 3 4 5 stop 0 6$ start 50 1 2 3 4 5 # represents the 5 run levels in 1,2,3,4,5, in order, from small to large execution, 50th start run script $ stop 50 0 6 # Indicates that in 0,6 these two runlevel, in order, from small to to execution, 52nd stop this script run $ update-rc.d mousycoder Remove # uninstall Mousycoder Boot Service









Start


Open your browser and enter the IP or domain name you configured earlier





Home Http://hostname.com/ghost
Ghost Backstage Http://hostname.com/ghost





Now you can enjoy the ultimate simplicity that ghost has brought to you, write it quickly!





Build Ghost node. JS-based open source blog system

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.