Skip to content

Instantly share code, notes, and snippets.

@joeinnes
Last active May 11, 2016 17:18
Show Gist options
  • Save joeinnes/96edf2a251e22cfd7003 to your computer and use it in GitHub Desktop.
Save joeinnes/96edf2a251e22cfd7003 to your computer and use it in GitHub Desktop.
Set up Ghost on a fresh server.
#!/bin/bash
# Written by Andy Boutte and David Balderston of howtoinstallghost.com and allaboutghost.com
# Modified to include Nginx by Joe Innes
######Check to make sure script is being run as root######
if [[ `whoami` != root ]]; then
echo "This script must be run as root"
exit 1
fi
######Update Server########
apt-get update
apt-get -y upgrade
apt-get autoremove
apt-get autoclean
apt-get -y install unzip build-essential
######Download and install Node######
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
######Download and install Ghost######
mkdir -p /var/www
cd /var/www/
curl -L -O https://ghost.org/zip/ghost-latest.zip
unzip -d ghost ghost-latest.zip
rm ghost-latest.zip
cd ghost/
npm install --production
######Edit the Config File######
sed -e 's/127.0.0.1/0.0.0.0/' <config.example.js >config.js
######Install Forever######
npm install -g forever
#####Setup Forever Start Script######
echo "#!/bin/bash" >> /usr/local/bin/ghoststart.sh
echo "export PATH=/usr/local/bin:$PATH" >> /usr/local/bin/ghoststart.sh
echo "cd /var/www/ghost" >> /usr/local/bin/ghoststart.sh
echo "export NODE_ENV=production" >> /usr/local/bin/ghoststart.sh
echo "NODE_ENV=production forever -a -l /var/log/ghost start --sourceDir /var/www/ghost index.js" >> /usr/local/bin/ghoststart.sh
chmod 755 /usr/local/bin/ghoststart.sh
######Create Startup Cron######
echo "@reboot /usr/local/bin/ghoststart.sh" > mycron
crontab mycron
rm mycron
######Start Ghost with Forever######
sh /usr/local/bin/ghoststart.sh
######Install Nginx######
apt-get install nginx -y
######Configure Nginx######
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default
rm /etc/nginx/conf.d/default
wget -O /etc/nginx/sites-enabled/ghost.conf https://gist.githubusercontent.com/joeinnes/96edf2a251e22cfd7003/raw/26381f4594cf1385136999a18421a2f61534ce0e/ghost.conf
service nginx restart
server {
listen 80;
server_name your-domain-name.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment