Top 1% !
Popularity: 33790th place
No tags for this snippet yet.

Running Meteor.js apps on Digital Ocean with Phusion Passenger and NGNIX

Running Meteor.js apps on Digital Ocean with Phusion Passenger and NGNIX:
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
# How to setup Meteor.js with Phusion Passenger and ngnix ### Introduciton This article will guide you thru running a development ready meteor.js app on Digital Ocean with Phusion Passenger and ngnix. ### Quick Summary 1. Create a droplet 2. Install Phussion Passanger with NGNIX 3. Install node.js 4. Configure NGNIX 5. Run NGNIX on server reboot 5. Bundle your app a deploy for production 6. Make it run! 7. Check for errors ## 1. Create a droplet Go to your account and crate a Droplet, choose a plan, deployment infrastructure (US, EU, ASIA) and OS (we will be working with `Debian 7 x64` droplet). If you are deploying a production ready app, make sure to run it with at least 1GB RAM. ## 2. Installing Phussion Passenger with NGNIX Passenger is very similar to NGNIX or APACHE, it can run as a standalone server or a module to APACHE or NGNIX, although we are going to use it with ngnix. Passenger also takes care of starting/restarting out app, which simplifies the setup a lot. 1. To install anything on your server you have to use `ssh`. Which is present on any UNIX-like system. If you are on windows please use `PUTTY` or other ssh client. > ssh root@DROPLET_IP If this is your first time loggin in to the droplet, the systtem will ask you to change your ssh password. 2. Install passenger > follow [this tutorial]( up to the end of step 2.3.3. This will install Passenger along with NGNIX. You can check that everything went fine by visiting `YOUR_SERVER_IP` and you should see a ngnix welcome screen. ## 3. Install node.js Passanger is just a server and it does not take care of installing node.js for you, so we'll have to do it. 1. Setup system > apt-get install curl > curl -sL | bash - 2. Install node.js > apt-get install -y nodejs 3. Don't forget to install build essentials! > Build essentials come in hande when you deploy your meteor app afterwards because meteor uses bcrypt which needs to be recompiled on each system. > apt-get install -y build-essential ## 4. Configure NGNIX Since we are running NGNIX we'll have to configure it to make use of Passenger. 1. Open the `sites-available/default` with [nano]( editor > sudo nano /etc/nginx/sites-available/default 2. Setup your vhost conf by editing the file > You should see that there is alredy a `server {}` block, scroll pass it and copy/paste the following server { listen 80; server_name; #same as ROOT_URL root /var/www/YOURAPPNAME/public; #DO NOT FORGET THE CHANGE THE NAME passenger_enabled on; passenger_sticky_sessions on; passenger_set_cgi_param MONGO_URL mongodb://; #DO NOT FORGET TO CHANGE IT passenger_set_cgi_param MONGO_OPLOG_URL mongodb://; #DO NOT FORGET TO CHANGEIT passenger_set_cgi_param ROOT_URL; passenger_set_cgi_param METEOR_SETTINGS '{}' #If you are using 'meteor --settings settings.json' in development, copy paste your values here passenger_app_type node; passenger_startup_file main.js; } This basicaly tells ngnix to listen for incomming traffic at `port 80` which points to your `server name` and uses passanger module to handle the request. `MONGO_URL`, `MONGO_OPLOG_URL` and `ROOT_URL` are needed by Meteor to run. The last two lines tells passanger that our app is a `node` app and starts with `main.js`. Afte you are done editing push `ctr + x` to exit than `y` to confirm changes and `enter` to go back to ssh. Or `ctrl + o` to Write Out change and `enter` to confirm and `ctrl + x` to exit. ## 4. Run ngnix on server reboot By defualt ngnix or passanger are not started on server boot, we have to handle that. 1. Create a file in `/etc/init.d/` called `` > sudo nano /etc/init.d/ 2. Paste this line to the file > /etc/init.d/nginx start Afte you are done editing push `ctr + x` to exit than `y` to confirm changes and `enter` to go back to ssh. Or `ctrl + o` to Write Out change and `enter` to confirm and `ctrl + x` to exit. Now whenever the `droplet reboots` the ngnix server will start. ## 5. Bundle your app and deploy it to the droplet Bundling meteor apps is very easy, because meteor CLI give is the great funcionality of `meteor bundle` 1. Open a new terminal Window 2. Cd into your Meteor app 3. Budnle your meteor app > meteor bundle bundle.tar.gz 4. Upload the bundle to the server > scp bundle.tar.gz root@DROPLET_IP: > login 5. login to your serve again via `ssh` 6. Create the `/var/www/` directory, cd to it, and extract the bundle > sudo mkdir /var/www/ && cd ../var/www/ #create and change directory > sudo tar xzvf ~/budnle.tar.gz #extracts the bundle to ./budnle > sudo mv budnle YOURAPPNAME #rename the bundle folder to your desired name 7. Create `public` and `tmp` directiories which are needed by Passenger > mkdir -p YOURAPPNAME/public YOURAPPNAME/tmp 8. Install dependecies `Meteor bundle` turns the meteor app in to almost standart `node` app so we have the install the depndencies. > cd YOURAPPNAME/programs/server && sudo npm install 9. Reinstall `npm-bcrypt` Unfortunately Meteor bundle also, bundles `npm-bcrypt` which needs to be compiled on every platform, so if you bundled the app on OSX or Windows Machine the app wont start, and will give you `bcrypt_lib.node: invalid ELF` error. So we need to rebuild `bcrypt`. 1. Delete the current `npm-directory` and recreate it a now > rm -rf npm/npm-bcrypt/ && mkdir -p /npm/npm-bcrypt/node_modules/bcrypt/ 1. Move to the projects root directory > cd ../../ 2. Install `npm-bcrypt` > npm install bcrypt 3. Now move it to the recreated `npm-directory` > cp -r /programs/server/node_modules/bcrypt programs/server/npm/npm-bcrypt/node_modules/bcrypt/ ## 6. Make it RUN! So far it everything went butter smooth you should have a working Meteor deployment on Digital Ocean and Phusion Passenger 1. Restart ngnix > /etc/init.d/nginx restart 2. Visit your domain name provider and create an `A` record which points to your `DROPLET_IP` 3. Visit `` and configure it accordingly to your DNS and ngnix default configuration 4. Save all of those settings 5. It will take 30 min probably to synchronize DNS records 6. Visit your page! ## 7. Error checking App is not running? ngnix does not want to start? > sudo nano /var/log/nginx/error.log
If you want to be updated about similar snippets, Sign in and follow our Channels