Now we're gonna get back over to our html directory
so cd /var/www/html/bundle
and
what we're gonna do
is,
in order to run
a meteor application
we need to set
a few
environment variables
and
you can do this from terminal.
You can just type export and then
the name of the variable.
So let's just create a variable called MYVAR
= and then the value, so if you're using digits
or characters you don't have to put quotes but if you're putting a string,
so spaces
in there
you've got to put them in quotes.
So this is a variable
and I've just created that variable and then I would be able to echo that out
in the shell
by typing
that.
So rather than set the variables like this though,
because the downside is that as soon as I close this terminal
all those environment variables are lost and so
if I need to restart my app say in a week or so I don't want to have to retype
all the variables.
So what we're gonna do is create a shell script
to do this for us
so
type in
nano
and then
-/Documents.
So in my home directory in documents I'm gonna create env.sh.
So the first thing we need is the CrunchBang
and we need to tell it
what type of file it is so
usr/bin/sh this is gonna tell it to run with bash.
Then we can just start creating our variables so we need three.
The first one we're going to configure is port
and we're gonna set that to 58080. So that's the port
that this meteor application will run on.
The next one is the root URL so we need to set this
as to
what the URL is going to be that the app is running at
so in this case it's app.localhost.
And then, one more
we need to add a mongo
URL
and
this is going to be a URL using the mongo.db protocol
and so the way we type that is
mongodb://
the name of the user account of mongodb
and then, the password of that mongodb
user account
and then we put an @ symbol.
So the first two bits of information is it's username and password
and then the host name.
Another colon and we're gonna specify the port here
and then a / and the name of the database which in our case is app
and this is
literally all we need. So what I'm gonna do is hit ctrl O to save
and ctrl X.
Now,
what you're gonna have to do, so let's say I need to restart the app
in a week I won't need to
retype all the those variables and the values for them.
I'll just have to rerun the script. So how we run the script
is
normally you would run a shell scripts by typing sh
and then the location of the script
but in order for the,
the variables that we're exporting in that script
to be integrated into the environment that we're working in,
we're gonna use the source
command.
So just type source and then the location
of the script
and then, you should be able to echo
for instance PORT
and it should print out the port and it does.
So what we can do at this point
is run the application and
we should be good to go.
So, to do that just type nodejs main.js
and I'm getting an error because I might have
this running it already so I'm going to killall
node,
nodejs actually.
I'm gonna try that again so nodejs main.js
and no errors so I should be able to go to
localhost:58080
and I should reach the Todo app and I do
but aside from that I should also be able to go to
app.localhost/
and that works as well.
Now,
this will work but as soon as I exit out of here
you're gonna see that the app is unavailable
and that's because when you exit out of a nodejs
shell
instance, basically it
stops the app.
So in order to run this
outside of,
of this instance of nodejs.
You need to install an npm application called forever
so to do that type sudo npm install -g
and the -g
on the npm install
basically,
all it is, is it tells it that we're going to globally
install the following application.
Normally if I didn't include that -g,
that would just install forever to the current node instance which is our meteor
application and I wouldn't be able to use it elsewhere in the future if I needed to
unless I installed it there as well.
So I'm going to put the -g so that is globally installed, I can use it anywhere
and then just type
forever
and it's going to you know check through the, the package list of npm
and it should install it and when it does
you should see an output like this.
So,
now that we've got forever installed,
what you can do is type forever start main.js
and we get this notification here it says it's processing the file
main.js which means we should be able to access the app
and you'll notice that we're outside of that instance in terminal.
So if I were to close this terminal completely,
the app would still function
as normal
and so that was an example of how you would
deploy a meteor application
using Apache 2 and
the proxy pass
module in Apache 2
in order to serve the
application
through Apache
and do some internal translations between the ports and then the address.
And again, this was a look at
how
much more advanced Apache 2 can get.
There are some other things,
I'll touch on right quick so
if you are for instance using wordpress
and you want to enable
like pretty URL like
the column permalinks, if you wanna enable permalinks
you'll have to have
a mod of rewrite module
enabled
and so how you would do that is
sudo a2enmod rewrite
and it's now enabled and to
activate the new configuration you just need to reload the Apache 2 servers
using system control it's
it says service Apache 2 restart but
as I covered a few videos ago,
we're using system control
and
I would
recommend using system control
for that.
So I hope you guys enjoyed this video.
Thanks for watching.