2 single: Deploying Web Applications in the Cloud; Introduction
4 =======================================
5 Deploying Web Applications in the Cloud
6 =======================================
8 In this chapter we will learn about deploying Ring Web Applications in the Cloud using Heroku
11 pair: Deploying Web Applications in the Cloud; Introduction
16 We created a new project and tutorial to explain how to deploy Ring web applications in the Cloud using Heroku
18 Demo : http://testring.herokuapp.com/
20 Project : https://github.com/ring-lang/RingWebAppOnHeroku
22 Heroku Website : https://www.heroku.com/
24 .. image:: ringincloud.png
25 :alt: Ring Web Application in the Cloud
28 pair: Deploying Web Applications in the Cloud; Usage
33 To use this project and deploy it on Heroku
35 (1) Create Heroku account
37 (2) Open your Heroku account and create new application
41 Note (You have to select a unique name for your application)
43 (3) Open the command prompt, Create new folder : MyApp
49 (4) Open the application folder
55 (5) Clone this projet using Git (Don't forget the dot in the end to clone in the current directory)
59 git clone https://github.com/ring-lang/RingWebAppOnHeroku .
61 (6) Login to Heroku (Enter your Email and Password)
67 (7) Add heroku (remote) to your Git project
69 change testring to your application name
73 heroku git:remote -a testring
75 (8) Set the buildpacks (So Heroku can know how to support your project)
79 heroku buildpacks:add --index 1 https://github.com/ring-lang/heroku-buildpack-apt
80 heroku buildpacks:add --index 2 https://github.com/ring-lang/heroku-buildpack-ring
82 (9) Now build your project and deploy it
86 git push heroku master
88 (10) Test your project (In the browser)
95 pair: Deploying Web Applications in the Cloud; Ring source code files and permissions
97 Ring source code files and permissions
98 ======================================
100 To be able to run your new Ring scripts, Set the permission of the file to be executable using Git
102 For example, if you created a file : myscript.ring
106 git update-index --chmod=+x myscript.ring
107 git commit -m "Update file permission"
109 If you are using TortoiseGit, From windows explorer, select the file
111 Right click ---> Properties ---> Git ---> Executable (+x)
113 Then commit and deploy!
116 pair: Deploying Web Applications in the Cloud; Hello World program
121 file : ringapp/helloworld.ring
123 To run it : http://testring.herokuapp.com/ringapp/helloworld.ring
127 #!/app/runring.sh -cgi
129 see "content-type: text/html" +nl+nl
130 see "Hello, World!" + nl
132 file : ringapp/helloworld2.ring
134 To run it : http://testring.herokuapp.com/ringapp/helloworld2.ring
138 #!/app/runring.sh -cgi
142 text("Hello, World!")
146 pair: Deploying Web Applications in the Cloud; Application Database
151 When you depoly the application, Everything will works directly!
153 No change is required, but in practice, You will need to update the next files to use your database
155 There are two scripts to interact with the database (We are using PostgreSQL in the cloud)
157 You will need to update the connection string in these files if you will use another database
159 * file: ringapp/database/newdb.ring (We run it using the browser for one time to create the tables)
160 * file: ringapp/datalib.ring (Class: Database)
162 In your practical projects, You can write better code (To be able to change the database)
164 Also you can create configuration file (To write the connection string in one place)
166 Database service : https://www.heroku.com/postgres
169 pair: Deploying Web Applications in the Cloud; Deploying after updates
171 Deploying after updates
172 =======================
174 Just use Git and commit then push to heroku
176 file: build.bat contains the next commands for quick tests
181 git commit -m "Update RingWebAppOnHeroku"
182 git push heroku master
186 pair: Deploying Web Applications in the Cloud; Local Tests
191 Local tests using Ring Notepad on Windows (Using local Apache Web Server)
193 Replace the first line in the file : ringapp/index.ring with
199 Then run it from Ring Notepad (Ctrl+F6)