Web Hosting at Digital Ocean
Installing Node.js
Installing Nginx
Sub Domains
Installing and Configuring Ghost
Other Ghost Install Links to Read
Notes
Installing MySQL
Using Ghost
Creating a new post
Configuring Ghost
Ghost Settings
Writing Posts
You're viewing old version number 47. - Current version
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 --strip-components=1
./configure --prefix=~/local
make install
curl https ://npmjs.org/install.sh | sh
node -v
Installing Nginx
http://0v.org/installing-ghost-on-ubuntu-nginx-and-mysql
sudo apt-get install nginx
sudo mkdir /var/cache/nginx
sudo chown web-data:web-data /var/cache/nginx
sudo mkdir /var/www
sudo chown web-data:web-data /var/www
vi /etc/nginx/nginx.conf
(Delete everything and replace it with the text below.)
user web-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
Sub Domains
13Nov2013
How to add a subdomain?
"You can add subdomains as either A or CNAME records. A records you would point them to a specific IP, and with CNAME records you can point them to a canonical name."
I created CNAME records:
- enter name: ghost
- enter hostname: @
Then from this: https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3
Create the New Virtual Host File
The next step is to create a new file that will contain all of our virtual host information.
nginx provides us with a layout for this file in the sites-available directory (/etc/nginx/sites-available), and we simply need to copy the text into a new custom file:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/ghost.soupmode.com
Open up the new virtual host file— you will see all the information you need to set up virtual host within.
sudo vim /etc/nginx/sites-available/ghost.soupmode.com
We need to make a couple of changes in these few lines:
server {
listen 80; ## listen for ipv4; this line is default and implied
# listen [::]:80 default ipv6only=on; ## listen for ipv6
root /home/ghost/default;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name ghost.soupmode.com;
}
Uncomment "listen 80" so that all traffic coming in through that port will be directed toward the site
Change the root extension to match the directory that we made in Step One. If the document root is incorrect or absent you will not be able to set up the virtual host.
Change the server name to your DNS approved domain name or, if you don't have one, you can use your IP address
You do not need to make any other changes to this file. Save and Exit.
The last step is to activate the host by creating a symbolic link between the sites-available directory and the sites-enabled directory. In apache, the command to accomplish this is "a2ensite."
nginx does not have an equivalent shortcut, but it's an easy command nonetheless.
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ghost.soupmode.com
To both avoid the "conflicting server name error" and ensure that going to your site displays the correct information, you can delete the default nginx server block:
sudo rm /etc/nginx/sites-enabled/default
Step Six—Restart nginx
We’ve made a lot of the changes to the configuration. Restart nginx and make the changes visible.
sudo service nginx restart
Possibly other helpful pages:
- https://www.digitalocean.com/community/articles/how-to-set-up-a-host-name-with-digitalocean
- http://blog.martinfjordvald.com/2010/07/nginx-primer/
- https://www.digitalocean.com/community/questions/how-do-i-setup-subdomains-for-my-droplet
- https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts
Installing and Configuring Ghost
Update currently running Ghost from /home/ghost instead of /var/www.
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
(In top-level directory where contents were unzipped:)
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 web-data:web-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
If not unzipped in /var/www, then:
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:
(Next command is not working at the moment. Using the commands in the notes section below.)
sudo ./starter.sh
That should start Ghost, nginx was already running, as was mysql. Visit http://YOUR_DOMAIN and you should see the default page.
Other Ghost Install Links 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
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.
cd /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 (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.
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/
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.
Configuring Ghost
http://docs.ghost.org/usage/configuration/
index.js
config.js
Ghost provides test and production environments.
Ghost Settings
http://docs.ghost.org/usage/settings/
Writing Posts
http://docs.ghost.org/usage/writing/
#webhosting - #nodejs - #javascript - #ghost - #blogging
From JR's : articles
1726 words - 13304 chars
- 9 min read
created on
updated on
- #
source
- versions
Related articles
Installing nodejs, nginx, mysql, junco, and ghost on Digital Ocean Droplet - Sep 26, 2016
NodeJS for newbies - Nov 01, 2013
Veery Blog App - April 2015 - Aug 03, 2015
Learning Node.JS Programming - Nov 10, 2014
Will Twitter eliminate its 140-character post limit? - Mar 16, 2015
more >>