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

6 min

Installing nodejs, nginx, and ghost on Digital Ocean Droplet

Week of November 10, 2013

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

Buying a Domain Name

I used networksolutions.com to buy a domain name.

Web Hosting at Digital Ocean

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

- log into the Digital Ocean server and change the password.
- have root access to the server.
- it's 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 --strip-components=1

./configure --prefix=~/local

(this step takes a while)
make install

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

node -v
(returns v0.10.21)

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 <a href="http://www-data;">www-data;</a>
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 <a href="http://www.YOUR_DOMAIN;">www.YOUR_DOMAIN;</a>

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

#        location ~ ^/(ghost/signup/) {
#                rewrite ^/(.*)$ <a href="http://YOUR_DOMAIN/">http://YOUR_DOMAIN/</a> 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         <a href="http://ghost_upstream;">http://ghost_upstream;</a>
    }
    }

    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

Installing and Configuring Ghost

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>&amp;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.

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

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 © 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.

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.

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

From JR's : articles
1158 words - 9037 chars - 6 min read
created on
updated on - #
source - versions

Related articles
Installing nodejs, nginx, mysql, junco, and ghost on Digital Ocean Droplet - Sep 26, 2016
App idea to learn new code - Mar 10, 2014
Links feb 25, 2017 - Feb 25, 2017
Proposed Ghost blogging platform - Feb 13, 2014
CSS, HTML, Javascript, jQuery, jQuery Mobile, Typography, Accessibility, and Responsive Design Info - Sep 25, 2013
more >>



A     A     A     A     A

© 2013-2017 JotHut - Online notebook

current date: Nov 14, 2024 - 12:40 p.m. EST