How to deploy Meteor Apps with
This is a short tutorial for deploying your Meteor applications. (We are using Amazon EC2 with node v5.11.1. and the newest Meteor release - July 2016) I am the creator of pm2-meteor and this is only how I setup my Meteor machines. So this doesn't mean that it is the correct way for everybody.
Step one (prepare your machine) - on host
- Skip, if you have nodejs + npm + pm2 on your host machine
- First you should log in to your machine and install nodejs and npm. $ ssh host$ sudo apt-get install nodejs$ sudo apt-get install npm
- Install pm2
- Install nginx
Step two (prepare nginx) - on host
- Edit your nginx config to use ssl and redirecting to your Meteor Port (people often ask if pm2-meteor can deploy with ssl - no! You should configure your nginx to use ssl - I don't think this is a job for a deployment tool)
- Read step one of this for configuring nginx for Meteor Apps WITH SSL
Step three (prepare mongodb) - on host
- Skip if you already have a MongoDB
- Read step two of this for setting up a MongoDB
Step four (prepare your app) - on local
- Install pm2-meteor on your local machine$ npm i pm2-meteor -g
- Go to the root of your app and create a (hidden) deployment folder (This is not a common convention - this is just how I store my pm2-meteor.json files. You also could create a common deployment folder for all your apps or just use your desktop folder I don't care ;-) )$ cd Workspace/abc/meteor-app$ mkdir .deployment && cd .deployment
- Init a pm2-meteor settings file$ pm2-meteor init
- Edit the created pm2-meteor.json in the .deployment folder "appName": "ninja-app""appLocation":// Path to your app"local": "~/Workspace/company/ninja-app"// Path to the meteor settings"meteorSettingsLocation": "~/Workspace/company/ninja-app/settings.json""meteorBuildFlags": "--architecture os.linux.x86_64""env":"ROOT_URL": """PORT": 3002"MONGO_URL": "mongodb://mongodbuser:thepassword@mongourlOrIP:27017/ninjaApp""server":"host": "my-host.com""username": "ubuntu"// I don't use passwords ..."pem": "~/.ssh/my-key.pem""deploymentDir": "/home/ubuntu/meteor-apps""loadProfile": """exec_mode": "cluster_mode""instances": 2
- Don't forget to add .deployment to your .gitignore file !!!
Step five (deploy) - on local
- In the .deployment folder just run:$ pm2-meteor deploy
- That's it - now every time you make changes to your app, just go into the .deployment folder and run
$ pm2-meteor deploy. Or you could write a script in package.json e.g.
"push-deploy": "cd .deployment && pm2-meteor deploy".