Host Ghost on Ploi

Host Ghost on Ploi

Running multiple PHP versions on a server by yourself can be a real pain in the ass. Being a developer, I just want to get things out on the web.  Test a new product here, play with a new technology there. So recently I started with Ploi as a way to help more easily manage my PHP versions on the server set up with the currently acceptable best practice for speed and security.

Ploi does an excellent job with all this PHP. They provide extra tools for Laravel projects, WordPress installs, CakePHP, etc.  And recently they've added node support. This blog is made using Ghost, a node project. After moving all my other projects over to Ploi, I was a bit annoyed that I would have to keep my old server running just to host a few Ghost blogs. Then an email came touting a new feature on Ploi - Node.js.

I followed the suggestions, installed Node, tried to get Ghost installed, and was thwarted! Using the Ghost command line requires some special sudo privileges so that it can set up permissions correctly after the install. But I have my sites set up under separate users on the server in hopes that it will be less attractive to those crazy hackers (at least that's what I tell myself), and don't want to put each of those users in as sudoers.  Luckily, there are other ways to install ghost!  If you have the same issue, check out this article from nehalist.io.  It's outdated now, since it's talking about installing version 1.0, but you can definitely get the idea and make any necessary changes to get that thing installed!

Now Ghost's installed, it's running, and I configured the NodeJS settings before spawning a new instance.  I loaded up the URL and... 502 Bad Gateway. Check out the logs and everything looks good; the site's up, but it's not accepting connections through the reverse proxy for some odd reason. Not wanting to waste a ton of time with this, I looked for ways to make sure that Ghost was always running the background with Supervisor, manually, instead of going through Ploi's admin section. After getting that set up, we had a site working perfectly!

I run ubuntu, so supervisor config is under /etc/supervices/conf.d, and I quickly whipped up a conf file with the help of Ahmed Amayem.

[program:woodnbooze_ghost]
command = node /home/woodn...com/index.js
directory = /home/woodn...com
user = woodn...
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/woodnbooze_ghost.log
stderr_logfile = /var/log/supervisor/woodnbooze_ghost_err.log
environment = NODE_ENV="production"

Restart supervisor and it'll pick up this config file. Since Ploi was already set with nginx to reverse proxy requests off to the ghost node server on the correct port, so as soon as ghost starts up, your web address starts working!  Finally.

Of course, the easy way out of all of this is to pay for ghost hosting at ghost.org and just let them deal with all the node things if you don't want to bother with any of it yourself.