- Node.js
- Ruby
- Bundler
This one's pretty simple, just change directory to somewhere sensible and run the following commands:
dirName="my-blog"
git clone "https://github.com/TryGhost/Ghost.git" $dirName
cd $dirName
git submodule update --init
npm install -g grunt-cli
npm install
bundle install
grunt init
npm start
If all goes well, you can now go to http://localhost:2368/ and see your wonderful new blog in all its un-styled glory. Go to http://localhost:2368/ghost/ to see the backend and create a new post (just enter your details to create an Administrator login).
Pretty cool huh? Okay, now time to make it purty...
No go and find yourself a theme that you like and drop it into content/themes
.
Here's where I went looking for themes:
http://marketplace.ghost.org/ http://themeforest.net/category/blogging/ghost-themes
You'll need to restart Ghost before it'll allow you to select newly install themes, so go back to your console and press Ctrl-C
to terminal Ghost and then run npm start
to start it up again. Now go to http://localhost:2368/ghost/settings/general/ and select one of the themes that you added in the Theme section of the form.
Now add your theme to the repo, or see below for bonus points:
git add -f "content/themes/{{theme directory}}"
git commit -m"Added theme"
Because Ellie was available on Github, and because I like to keep things neat and tidy I added Ellie as a git submodule and then created my own copy (I could have used a fork but, uh I didn't) which I added to my repo. This allows me to pull updates to Ellie in the future if I like, and copy them over to my theme.
This process was:
dirName="aexmachina"
git submodule add -f "https://github.com/Thomascullen92/Ellie.git" "content/themes/ellie"
mkdir "content/themes/$dirName"
cp -r "content/themes/ellie/*" "content/themes/$dirName"
git add -f "content/themes/$dirName"
git commit -m"Added themes"
Now you need to tell Ghost where your blog lives, so open up config.js in your editor of choice.
In the development section, change my-ghost-blog.com to localhost In the production section, change my-ghost-blog.com to the hostname you're going to use on the sever and change the port to '80' Replace host: '127.0.0.1' with host: '0.0.0.0' to accept connections from anywhere If you're on EC2 then you can use the ec2-54-206-12-73.ap-southeast-2.compute.amazonaws.com and change it to your domain later.
Now add these changes to your Git repo:
git add -f "config.js"
git commit -m "Updated config"
Okay now we need to push our changes to a Git repository. I recommend you create one on Github or Bitbucket (Bitbucket will let you keep your code private if that's your thing). This post assumes Github, but the same applies to Bitbucket.
When you complete this process they will provide you with a URL that you can use to push your changes:
You'll need to go through the process of setting up your SSH keys so that you don't need to enter your username and password every time, and so that you can access your repo from the server later on.
Now, copy that URL and:
git remote rename origin upstream
git remote add origin "{{the URL you copied before}}"
git push origin master --set-upstream
Congratulations, you've just pushed a Git repository!
We're going to use Upstart to make sure that our server starts when the instance boots up. Create a new file upstart.conf
in your text editor of choice and copy the code from this Gist into it, changing /data/my-blog to the whatever you used for $dirName above.
Now add this to Git using:
git add upstart.conf
git commit -m"Added upstart.conf"
git push origin master
Okay, so if you don't already have an EC2 instance then you create one using these instructions. Then you should SSH to your instance so we can set up Ghost.
You'll want to use SSH Agent Forwarding so that you can access your Git repo from the server. You can do this by adding -A
to your SSH command, but I recommend adding the following entry in your ~/.ssh/config file
:
Host {{your domain name}}
Hostname {{EC2 domain name e.g. ec2-54-206-12-73.ap-southeast-2.compute.amazonaws.com}}
User ubuntu
IdentityFile ~/.ssh/{{path to your Amazon .pem file}}
ForwardAgent yes
This allows you to SSH to {{your domain name}}
and to then authenticate over SSH as though you're on your local machine:
ssh {{your domain name}}
(Answer yes to the warning about the fingerprint.)
Okay, so you've SSHed to your instance. Now you'll need a few packages installed first:
sudo apt-get update
sudo apt-get install git nodejs npm ruby1.9.1 -y
~~sudo ln -s nodejs /usr/bin/node~~
sudo npm config set registry http://registry.npmjs.org/
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm install npm grunt-cli forever -g
sudo gem install bundler
If you want to run multiple sites on this instance then you'll need to set up Nginx or some other reverse proxy to listen on port 80 and then pass the requests to the appropriate process for each website. But that's outside the scope of this post, so I'm assuming that this is the only site you're running on this instance.
Now, let's clone your Ghost repo on the instance. Feel free to change $dirName
to whatever you want.
dirName="/data/my-blog"
sudo mkdir -p $dirName
sudo chown ubuntu $dirName
cd $dirName
git clone "{{the repository URL you copied from Github before}}" $dirName
(Answer yes to the warning about the fingerprint, then...)
git submodule update --init
sudo npm install
bundle
grunt init
grunt prod
sudo NODE_ENV="production" npm start
If everything's worked then you should be able to go to http://{{your domain name}}/ghost/settings/general/ and select your theme, and your shiny new blog will be online at http://{{your domain name}}/.
Copy the upstart.conf
file into /etc/init
so that your blog starts when the instance boots up:
cp upstart.conf "/etc/init/my-blog.conf"
Make sure you check that it does start by rebooting the instance using shutdown -r now
.
Now you've got your very own blog, and it's yours to do with as you please!
You can make some changes to your theme, add them to Git (using git add
, git commit
and git push
). Then when you're happy with them, SSH to your server, cd /data/my-blog
and run run git pull
to update your blog.
One final note: your server isn't set up to send email yet, but that's a topic for yourself to work out - I'm out of time here :)