66

How to deploy a meteor application to my own server?

flavour 1: the development and deployment server are the same;

flavour 2: the development server is one (maybe my localhost) and the deployment server is another (maybe a VPS in the cloud);

flavour 3: I want to make a "meteor hosting" domain, just like "meteor.com". Is it possible? How?

Update:

I'm running Ubuntu and I don't want to "demeteorize" the application. Thank you.

5
  • 3
    when Galaxy will be shipped these questions will be so easy to answer... :)
    – imslavko
    Jul 12, 2013 at 3:33
  • 1
    Galaxy alpha is planned for meteor 1.0, first release for 1.1. It's a matter of weeks Oct 26, 2014 at 7:56
  • 1
    Galaxy released today it just took a year instead of weeks… Oct 6, 2015 at 4:51
  • 4
    Galaxy is also expensive.
    – EvilJordan
    Dec 4, 2015 at 8:23
  • So dang expensive. Whats up with that? Jan 9, 2016 at 2:24

6 Answers 6

87

Meteor documentation currently says:

"[...] you need to provide Node.js 0.8 and a MongoDB server. You can then run the application by invoking node, specifying the HTTP port for the application to listen on, and the MongoDB endpoint."


So, among the several ways to install Node.js, I got it up and running following the best advice I found, which is basically unpacking the latest version available directly in the official Node.JS website, already compiled for Linux (64 bits, in my case):

# Does NOT need to be root user:

# create directory
mkdir -p ~/.nodes && cd ~/.nodes

# download latest Node.js distribution
curl -O http://nodejs.org/dist/v0.10.13/node-v0.10.13-linux-x64.tar.gz

# unpack it
tar -xzf node-v0.10.13-linux-x64.tar.gz

# discard it
rm node-v0.10.13-linux-x64.tar.gz

# rename unpacked folder
mv node-v0.10.13-linux-x64 0.10.13

# create symlink
ln -s 0.10.13 current

# add path to PATH
export PATH="~/.nodes/current/bin:$PATH"

# check
node --version
npm --version


And to install MongoDB, I simply followed the instructions in the MongoDB manual available in the Documentation section of its official website:

# Needs to be root user (apply "sudo" if not at root shell)

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list
apt-get update
apt-get install mongodb-10gen



The server is ready to run Meteor applications! For deployment, the main "issue" is where the "bundle" operation happens. We need to run meteor bundle command from inside the application source files tree. For example:

cd ~/leaderboard
meteor bundle leaderboard.tar.gz


If the deployment will happen in another server (flavour 2), we need to upload the bundle tar.gz file to it, using sftp, ftp, or any other file transfer method. Once the file is there, we follow both Meteor documentation and the README file which is magically included in the root of the bundle tree:

# unpack the bundle
tar -xvzf leaderboard.tar.gz

# discard tar.gz file
rm leaderboard.tar.gz

# rebuild native packages
pushd bundle/programs/server/node_modules
rm -r fibers
npm install [email protected]
popd

# setup environment variables
export MONGO_URL='mongodb://localhost'
export ROOT_URL='http://example.com'
export PORT=3000

# start the server
node main.js


If the deployment will be in the same server (flavour 1), the bundle tar.gz file is already there, and we don't need to recompile the native packages. (Just jump the corresponding section above.)



Cool! With these steps, I've got the "Leaderboard" example deployed to my custom server, not "meteor.com"... (only to learn and value their services!)

I still have to make it run on port 80 (I plan to use NginX for this), persist environment variables, start Node.JS dettached from terminal, et cetera... I am aware this setup in a "barely naked" one... just the base, the first step, basic foundation stones.

The application has been "manually" deployed, without taking advantage of all meteor deploy command magic features... I've seen people published their "meteor.sh" and "meteoric.sh" and I am following the same path... create a script to emulate the "single command deploy" feature... aware that in the near future all this stuff will be part of the pioneer Meteor explorers only, as it will grow into a whole Galaxy! and most of these issues will be an archaic thing of the past.

Anyway, I am very happy to see how fast the deployed application runs in the cheapest VPS ever, with a surprisingly low latency and almost instant simultaneous updates in several distinct browsers. Fantastic!

Thank you!!!

8
  • 1
    I'm looking forward for the meteor team to release their official deployment system. Feb 9, 2014 at 13:40
  • 2
    pushd bundle/server/node_modules should be pushd bundle/programs/server/node_modules
    – Alucard
    Apr 20, 2014 at 16:19
  • 1
    To install node, just do git clone [email protected]:visionmedia/n.git && cd n && make install && n stable. Hope this helps. Jul 14, 2014 at 9:25
  • 1
    Hey, I know this is an old post, but I was wondering if you could explain why we can't just install meteor on our server and run our app off port 3000, as we do locally when we are developing it. Is there something major I'm missing about why this isn't standard procedure?
    – Dave
    Feb 18, 2015 at 17:10
  • Hey @Dave, the reason you can't do that is that would necessitate when people visit your website they go to blahblahblah.com:3000 instead of just blahblahblah.com (which defaults to port 80). Mar 24, 2015 at 13:58
14

Try Meteor Up too

With that you can deploy into any Ubuntu server. This uses meteor build command internally. And used by many for deploying production apps.

I created Meteor Up to allow developers to deploy production quality Meteor apps until Galaxy comes.

1
  • 3
    This was once a fantastic tool, but due to lack of maintenance it's now buggy and continuously fails to deploy even key Meteor example applications, such as Todos and Leaderboard.
    – Nick Bull
    Nov 11, 2016 at 13:56
8

I would recommend flavor two with a separate deployment server. Separation of concerns leads to a more stable environment for your code and its easier to debug.

To do it, there's the excellent Meteoric bash script that helps you deploy to Amazon's EC2 or your own server.

As for how to roll your own meteor.com, I suggest you break that out into it's own StackOverflow question as it's not related. Plus, I can't answer it :)

1
  • 1
    +1 Thanks, Jonatan. But I've studied the whole thing a bit, including Meteoric and former "Meteor.sh" scripts, and learned the step-by-step thing. I realized that rolling our own meteor.com, at the moment, is quite challenging... indeed. :-) ...I've added my own answer with what worked for me, and I will accept it as the answer to the question... it became a little tutorial... I upvoted your answer and thank you for the informations.
    – J. Bruni
    Jul 12, 2013 at 19:54
6

I done with it few days ago. I deployed my Meteor application to my own server on the DigitalOcean. I used Meteor Up tool for managing deploys and Nginx on the server to serve the app.

It's very simple to use. You should install meteor up with the command:

npm install -g mup

Then create the folder for deployment configuration and go to the created directory. Then run mup init command. It will created two configuration files. We are have interest for mup.json file. It have configurations for deployment process. It's looks like this:

{
  // Server authentication info
  "servers": [
    {
      "host": "hostname",
      "username": "root",
      "password": "password",
      // or pem file (ssh based authentication)
      //"pem": "~/.ssh/id_rsa",
      // Also, for non-standard ssh port use this
      //"sshOptions": { "port" : 49154 },
      // server specific environment variables
      "env": {}
    }
  ],

  // Install MongoDB on the server. Does not destroy the local MongoDB on future setups
  "setupMongo": true,

  // WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
  "setupNode": true,

  // WARNING: nodeVersion defaults to 0.10.36 if omitted. Do not use v, just the version number.
  "nodeVersion": "0.10.36",

  // Install PhantomJS on the server
  "setupPhantom": true,

  // Show a progress bar during the upload of the bundle to the server.
  // Might cause an error in some rare cases if set to true, for instance in Shippable CI
  "enableUploadProgressBar": true,

  // Application name (no spaces).
  "appName": "meteor",

  // Location of app (local directory). This can reference '~' as the users home directory.
  // i.e., "app": "~/Meteor/my-app",
  // This is the same as the line below.
  "app": "/Users/arunoda/Meteor/my-app",

  // Configure environment
  // ROOT_URL must be set to https://YOURDOMAIN.com when using the spiderable package & force SSL
  // your NGINX proxy or Cloudflare. When using just Meteor on SSL without spiderable this is not necessary
  "env": {
    "PORT": 80,
    "ROOT_URL": "http://myapp.com",
    "MONGO_URL": "mongodb://arunoda:[email protected]:10023/MyApp",
    "MAIL_URL": "smtp://postmaster%40myapp.mailgun.org:[email protected]:587/"
  },

  // Meteor Up checks if the app comes online just after the deployment.
  // Before mup checks that, it will wait for the number of seconds configured below.
  "deployCheckWaitTime": 15
}

After you fill all data fields you can start the setup process with command mup setup. It will setup your server.

After sucessfull setup you can deploy your app. Just type mup deploy in the console.

5

Another alternative is to just develop on your own server to start with. I just created a Digital Ocean box and then connected my Cloud9 IDE account.

Now, I can develop right on the machine in a Cloud IDE and deployment is easy--just copying files.

I created a tutorial that shows exactly how my set up works.

4

I had a lot of trouble with meteor up, so I decided writing my own deploy script. I also added additional info how to set up nginx or mongodb. Hope it helps!

See /sh folder in repository

What the script meteor-deploy.sh does:

  1. Select environment (./meteor-deploy.sh for staging, ./meteor-deploy.sh prod for production)
  2. Build and bundle production version of the meteor app
  3. Copy bundle to server
  4. SSH into server
  5. Do a mongodump to backup database
  6. Stop the running app
  7. Unpack bundle
  8. Overwrite app files
  9. Re-install app node package dependencies
  10. Start the app (uses forever)

Tested for the following server configurations:

  • Ubuntu 14.04.4 LTS
  • meteor --version 1.3.2.4
  • node --version v0.10.41
  • npm --version 3.10.3

Not the answer you're looking for? Browse other questions tagged or ask your own question.