The Martian Chronicles

Easy deploy of Pharo applications on the web (linux)

(For this instructions, I assume you are using Pharo 4.0)

You need to put you application somewere, isn't? So, easiest way is to install your application along your image/changes files:

1. copy you application .image and .changes file into the place you are going to run your web application (usually /var/www/YourApplication)

2. in the same place, do:

 $ wget -O- get.pharo.org/vm40 | bash

3. create a startup script, something like this:

File name: run.sh

sudo -u pharo nohup ./pharo /var/www/YourApplication/YourApplication.image --no-quit &

(Notice that we use an alternative user to run app. Is never recommendable to use root permissions. Remember you need also to change permission of all "YouApplication" subdirectory)

... and thats all :). This is enough to have your application running.

4. [OPTIONAL] Startup script with initialisation

Sometimes you need to prepare some things that might change (for example, running ports, database hosts, etc.).

For this the easiest way is to modify your run.sh script:

sudo -u pharo nohup ./pharo /var/www/YourApplication/YourApplication.image eval --no-quit "
"Start web server"
ZnZincServerAdaptor startOn: 8080.
"Start Voyage-MongoDB"
(VOMongoRepository host: 'localhost' database: 'myApplication') enableSingleton." &

Notice that is very easy to adapt this to receive ports, etc. as an script parameter (in case you need to scale your application and use several ports, for example).

5. [OPTIONAL] NGINX configuration

I do not use Apache since some years, so I do not remember how this is done (but is doable, of course). This is a basic config that works:

 server {
listen 80;
server_name myApplication.com;

location / {
proxy_pass http://127.0.0.1:8080/;
proxy_redirect default;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $host;
proxy_pass_request_headers on;
}
}

And that's is :)

Posted by Administrator at 26 April 2016, 1:36 pm link

Leave your comment