You're viewing old version number 27. - Current version

7 min

Installing nodejs, nginx, and ghost on Digital Ocean Droplet

Week of November 10, 2013

Buying a Domain Name

I used networksolutions.com to buy a domain name.

Web Hosting at Digital Ocean

  • http://digitalocean.com

    • create an account
    • purchase the $5 per month Droplet.
    • I used Ubuntu Linux.
    • Digital Ocean will e-mail the username and password for the Linux server. This info is used to log into the server with SSH.
  • while logged into the web-based Digital Ocean dashboard:

    • click DNS and add the domain name purchased above. the domain name will be associated with the droplet created, but also need to add the domain name to the DNS setting.
    • add the Digital Ocean name servers to the Network Solutions account for the domain name.
  • Linux server

    • use remote shell/SSH to log into the Digital Ocean server and change the password.
    • they provide root access to the server.
    • may need to change config so that root cannot log into the server remotely. create a new user account to login with and then su to root.
    • it's a clean, simple, bare-bones Linux install.
    • need to install gcc.
    • need to install unzip.
    • need to isntall curl.

Installing Node.js

https://www.digitalocean.com/community/articles/how-to-install-an-upstream-version-of-node-js-on-ubuntu-12-04

sudo apt-get update

sudo apt-get install build-essential

sudo apt-get install curl

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc

. ~/.bashrc

mkdir ~/local mkdir ~/node-latest-install

cd ~/node-latest-install

curl http://nodejs.org/dist/node-latest.tar.gz | tar xz -stripcomponents=1

./configure --prefix=~/local ```

(this step takes a while) make install

curl https://npmjs.org/install.sh | sh

node -v (returns v0.10.21)

h2. Installing Nginx

http://0v.org/installing-ghost-on-ubuntu-nginx-and-mysql

sudo apt-get install nginx

sudo mkdir /var/cache/nginx sudo chown www-data:www-data /var/cache/nginx

sudo mkdir /var/www sudo chown www-data:www-data /var/www

vi /etc/nginx/nginx.conf

(Delete everything and replace it with the text below.)

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    proxy_cache_path  /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
    proxy_temp_path /var/tmp;
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    gzip on;
    gzip_comp_level 6;
    gzip_vary on;
    gzip_min_length  1000;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    gzip_buffers 16 8k;

    upstream ghost_upstream {
      server 127.0.0.1:2368;
      keepalive 64;
    }

    server {
    listen 80;

    server_name YOUR_DOMAIN www.YOUR_DOMAIN;

    if ($host = 'YOUR_DOMAIN' ) {
            rewrite  ^/(.*)$  http://www.YOUR_DOMAIN/$1  permanent;
    }

#        location ~ ^/(ghost/signup/) {
#                rewrite ^/(.*)$ http://YOUR_DOMAIN/ permanent;
#        }

    location ~ ^/(img/|css/|lib/|vendor/|fonts/|robots.txt|humans.txt) {
      root /var/www/core/client/assets;
      access_log off;
      expires max;
    }

    location ~ ^/(shared/|built/) {
      root /var/www/core;
      access_log off;
      expires max;
    }

    location ~ ^/(favicon.ico) {
      root /var/www/core/shared;
      access_log off;
      expires max;
    }

    location ~ ^/(content/images/) {
      root /var/www;
      access_log off;
      expires max;
    }

    location / {
      proxy_redirect off;
      proxy_set_header   X-Real-IP            $remote_addr;
      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Proto $scheme;
      proxy_set_header   Host                   $http_host;
      proxy_set_header   X-NginX-Proxy    true;
      proxy_set_header   Connection "";
      proxy_http_version 1.1;
      proxy_cache one;
      proxy_cache_key ghost$request_uri$scheme;
      proxy_pass         http://ghost_upstream;
    }
    }

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

(Now you need to edit the contents and replace everywhere it says YOUR_DOMAIN with your actual domain like example.com.)

(You can now restart nginx:) sudo /etc/init.d/nginx restart

h2. Installing and Configuring Ghost

bq. Update currently running Ghost from /home/ghost instead of /var/www.

[something to read http://ghost.centminmod.com/how-to-install-ghost-blogging-platform/]

[init.d script to run Ghost under a service account. https://gist.github.com/emiller42/7191554]

http://0v.org/installing-ghost-on-ubuntu-nginx-and-mysql

http://docs.ghost.org/installation/

http://ghosted.co/install-ghost-digitalocean/

(download the zipped source code) https://ghost.org/download/

(copy .zip file to Digital Ocean server)

(install the unzip utility)

sudo apt-get install unzip

(unzip the ghost source code)

unzip ghost-0.3.3.zip

npm install --production

npm install forever -g

vi /var/www/starter.sh

(Paste in the script below:)

#!/bin/sh

if [ $(ps aux | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
    export PATH=/usr/local/bin:$PATH
    export NODE_ENV=production
    NODE_ENV=production forever start --sourceDir /var/www index.js >> /var/log/nodelog.txt 2>&1
fi

Now enter this command:

sudo chmod +x /var/www/starter.sh Next up we want to fix all the permissions:

sudo chown R www-data:www-data /var/www/ Now we need to add a line to your crontab:

sudo crontab -e If this is the first time you've used crontab -e then it will ask you which editor to use. I prefer nano for simple edits, but you can choose anything. Place this line at the end of the file and save:

@reboot /var/www/starter.sh

cp config.js /var/www

The Ghost config.js file is up next. Open it up to edit:

Edit the lines with "url:" right under development and production declarations replacing the default URL with yours:

development: {
    // The url to use when providing links to the site, E.g. in RSS and email.
    url: 'http:// YOUR_DOMAIN',

and

production: {
    url: 'http:// YOUR_DOMAIN',

(I did not edit the database section of the config.js file, since I'm using the default sqlite.)

You are now done. Ghost should be ready to go. Get into the /var/www directory and enter this command:

sudo ./starter.sh (not working at the moment. use the commands in the notes section below.)

That should start Ghost, nginx was already running, as was mysql. Visit http://YOUR_DOMAIN and you should see the default page.

h2. Notes

i unzipped the ghost code in /home/ghost. http://0v.org/installing-ghost-on-ubuntu-nginx-and-mysql recommended :

Download the zip file from your ghost.org account. Get it unzipped and uploaded. Make sure you put the files into /var/www. Now go into /var/www and run these commands: sudo npm install --production sudo npm install mysql sudo npm install forever -g

The Ov.org user chose mysql instead of sqlite.

Other options for starting and stopping ghost. /home/ghost forever start index.js forever stop index.js

h2. Installing MySQL

(if want to use a different database.)

This is another simple one. Run this command:

sudo apt-get install mysql-client mysql-server While its running it will ask you to set a root password. Make sure to remember this.

Now lets add a couple ghost databases and a user. Enter this command to get into mysql's command line interface: (it will ask for the root password you set earlier)

mysql -uroot -p You should see output like this:

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1269 Server version: 5.5.32-0ubuntu0.13.04.1 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> At the "mysql>" prompt you need to enter these commands one at a time: (replace YOUR_PASSWORD with a password you will remember)

create database ghostdev; create database ghost; create user 'ghost'@'localhost' identified by 'YOUR_PASSWORD'; grant all privileges on ghost.* to 'ghost'@'localhost'; grant all privileges on ghostdev.* to 'ghost'@'localhost'; flush privileges; quit You now have mysql setup with a production and development database.

h2. Using Ghost

http://docs.ghost.org/usage/

The home page and the default test post that came with the Ghost code should display fine.

Now it's time to create an account to create new content.

Navigate to your new blog in your favourite browser, and then change the URL to http://yourURL/ghost/signup

Fill in your Full Name as the name you want to appear as the author of blog posts. Then enter your Email Address - make sure it's valid, and carefully enter a sensible Password (it needs to be at least 8 characters long). Hit the big blue Sign Up button, and you will be logged in to your blog. That's it! You can now start writing blog posts.

Message will be displayed: "Ghost is currently unable to send e-mail. See http://docs.ghost.org/mail for instructions"

This isn't critical to setting up your blog so you can get started writing, but it is a good idea to mosey on over to the email documentation at some point, and learn about configuring Ghost to send email. This is currently only used to send you a reset email if you forget your password. Not important for blogging, but really useful if you ever need it!

http://yourdomain/ghost/signin/

h3. Creating a new post

Click the "New Post" link in upper left part of site.

Ghost uses Markdown. For a new test post, I used the text from this post: http://jothut.com/cgi-bin/junco.pl/blogpost/5118/19Sep2013/Perl-ForecastIO-module-README-for-GitHub

The above ForecastIO readme for GitHub was created in Markdown.

h2. Configuring Ghost

http://docs.ghost.org/usage/configuration/

index.js config.js

Ghost provides test and production environments.

h3. Ghost Settings

http://docs.ghost.org/usage/settings/

h3. Writing Posts

http://docs.ghost.org/usage/writing/

#webhosting - #nodejs - #javascript - #ghost - #blogging

From JR's : articles
1343 words - 10339 chars - 7 min read
created on
updated on - #
source - versions

Related articles
Installing nodejs, nginx, mysql, junco, and ghost on Digital Ocean Droplet - Sep 26, 2016
CSS, HTML, Javascript, jQuery, jQuery Mobile, Typography, Accessibility, and Responsive Design Info - Sep 25, 2013
Ghost blog theme info - Mar 11, 2015
NodeJS for newbies - Nov 01, 2013
Veery Blog App - April 2015 - Aug 03, 2015
more >>



A     A     A     A     A

© 2013-2017 JotHut - Online notebook

current date: May 5, 2024 - 7:44 p.m. EDT