Tutorial on using AppFog free cloud space

Tutorial on using AppFog free cloud space

About AppFog:

AppFog is a PaaS platform based on Cloud Foundry, similar to Google App Engine and Heroku. The bottom layer is based on IaaS platforms such as AWS, RackSpace, HP OpenStack, and MS Azure. The middle layer uses Cloud Foundry, and the top layer is AppFog.
Using memory allocation as the main pricing rule, you can seamlessly switch between IaaS platforms without having to worry about configuration issues. You can focus on code, which is the so-called "Work on code, not management." AppFog also provides an iPhone App to monitor your Web applications. Since it is based on Cloud Foundry, it can also be used with many third-party open source tools. You can learn more via their blog.
The most important thing is that the Free plan is very powerful :

  1. Unlimited number of applications, 2GB of total RAM, database service up to 1GB, up to 10 extensions (add-ons)
  2. Free, scalable and load-balanced app
  3. Use the fastest server instance on each platform (like m2.4xlarge)
  4. Free custom domain name
  5. 50GB of data per month

The programming languages ​​currently supported by AppFog include:

  • Java1.6.0, Java Grails2.0.3, Java Spring Mysql3.0.0
  • Node 0.6.8, Node Chat 1.0.0, Node Express 3.0.0
  • PHP5.3.2, PHP Drupal7.14.0, PHP WordPress3.3.2
  • Python 2.7.3, Python Django 1.4, Python Flask 0.8
  • Ruby on Rails 3.2.5, Ruby Sinatra 1.3.2

Currently supported databases and extensions include:

  • MySQL5.1, PostgreSQL9.1, MongoDB1.8 (databases are provided by AppFog itself)
  • MongoLab, MongoHQ (the following extensions are provided by third-party platforms and can be installed with one click)
  • ClearDB, IronMQ, IronWorker, Mailgun, Searchify, CloudMailin

Step 1. Register the service.

Very simple. . .

Step 2. Create an APP

Once you have registered, go to https://console.appfog.com/ and click New App. You can see that there are three steps to creating an app:
The first step is to select a type of application. We can see that there are three supported nodejs applications, nodejs, node chat and node express. Whether you use node express or not, you can choose the first nodejs . The key is to add all the libraries you depend on when uploading the code, that is, put the node moudles folder in the code directory.
The second step is to choose a server. It’s up to you. The one closest to you is the one in Singapore, which uses Amazon’s cloud storage service.
In the third step, enter your app subdomain, which is the name you gave your app.
After that, click Create App and you will see a progress list. When you see 'done', your app is created. Easy, isn't it? Next, you will enter the configuration interface.

Step 3. App configuration

A dashboard appears in front of you:

It looks simple enough, right? Let me introduce it. Instances, as the name suggests, are the number of instances started, and memory quota is the memory allocation. If you have 2G of memory, you can decide how much memory to allocate to it based on the size of the application. After adjusting, remember to click the blue Update in the lower right corner! After Done is displayed, the modification is completed.

Step 4. Create data service

A large part of web applications still require databases. Appfog provides three data engines: MongoDB, PostgreSQL, and MySQL. Click Services in the left sidebar, select a data service, enter a name below, and create it.

Note that it is not over yet. You need to bind the created service and application before you can use it. But if you wait a moment, it will automatically bind it for you.

Step 5. Modify the code and upload

Modify the code. The important thing is your database connection code. The page for creating the service above has connection instances in three languages, but it seems that it cannot be opened. Nodejs can use the following code:

 if(process.env.VCAP_SERVICES){ var env = JSON.parse(process.env.VCAP_SERVICES); var mongo = env['mongodb-1.8'][0]['credentials']; } else{ var mongo = { "hostname":"localhost", "port":27017, "username":"你的用戶名", "password":"你的密碼", "name":"你的應用名", "db":"db" } } var generate_mongo_url = function(obj){ obj.hostname = (obj.hostname || 'localhost'); obj.port = (obj.port || 27017); obj.db = (obj.db || 'test'); if(obj.username && obj.password){ return "mongodb://" + obj.username + ":" + obj.password + "@" + obj.hostname + ":" + obj.port + "/" + obj.db; } else{ return "mongodb://" + obj.hostname + ":" + obj.port + "/" + obj.db; } } var mongourl = generate_mongo_url(mongo);

Just assign mongourl to your database connection string.
ps: I forgot to set up the database connection at first, and still kept the 127.0.0.1 configuration during development, and the application could run normally. It was strange, but I changed it later.
To upload the code you need the ruby ​​gem and af under gem. Under Ubuntu,

 sudo apt-get install ruby1.9.1 ruby1.9.1-dev gem gem install af cd '你的應用目錄' af login(之后輸入你的郵箱和密碼) af update '你的應用名'

Wait for a series of OKs to complete. Return to the dashboard and click Visit Live Site on the right to see if it is running.
ps: The previous Step 2 can be implemented in the code root directory using the af command: af push. The process is to answer a few multiple-choice questions and fill-in-the-blank questions.
PPS: You need to keep all the dependent libraries node_moudles in the root directory. Some people must want to use package.json to let the server npm install itself. This method is of course possible. You need npm shrinkwrap. The specific method is here, but it is not as direct as uploading it directly, and it avoids inexplicable problems.

Step 6. Bind domain name

Note: Currently only paid services have the function of binding a domain name.

You already have a domain name provided by appfog, but what if you want to use your own domain name? Appfog uses the cname method to bind the domain name (if you don’t know what cname is, google it). Specific operations:
Click on Domain Names in the sidebar, enter your domain name in the blank box, and click Update. Then go to your domain name service provider to set the resolution method cname. The address is the URL starting with the red cname01. Appfog will automatically direct you according to the domain name you added, and then wait for all DNS to synchronize your information, and you can access it.
Ok, step 6, if nothing goes wrong, the deployment should be successfully completed.
For CLI control of appfog, see here, http://docs.appfog.com/getting-started/af-cli
For advanced level, please keep an eye on the documentation, but you will need to have a certain level of English reading ability.
via: http://cnodejs.org/topic/5033ab60f767cc9a51ad9bc1
http://alimon.yangjian.me/post/%E4%BD%BF%E7%94%A8AppFog%E9%83%A8%E7%BD%B2Web%E5%BA%94%E7%94%A8
http://www.freehao123.com/appfog/
http://www.henghengzhu.com/share/144.html

<<:  $7/month/2G memory/50G space/1000G traffic/OpenVZ VPS —— VMBox

>>:  CLICKHOST .ORG domain $4.99 discount

Recommend

VMVM: 35 yuan/month/512MB memory/15GB SSD space/2TB traffic/DDOS/KVM/Portland

VMVM, a Chinese merchant, currently only provides...

DomainzClub: $5.95/year Comodo SSL certificate

DomainzClub's SSL certificates are relatively...

123Systems is acquired by ChicagoVPS, offering 40% discount

123Systems was acquired by ChicagoVPS, and is off...

Dynadot 5-month .club discount of $1/first year

Registration address: https://www.dynadot.com/dom...

Solution to redirection caused by SSL when using Cloudflare in WordPress

The problem of redirection caused by SSL when usi...

$3.99/month/1024M memory/65G space/1000G traffic/OpenVZ:ServerHub

We have introduced ServerHub’s virtual hosting be...

HostDoc: £5/year/512MB memory/10GB space/1TB bandwidth/1Gbps/KVM/Dallas

HostDoc, a foreign hosting provider, has been est...

virpus 2015 latest offers

virpus, the service has been adjusted, based on X...