Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation from source code
Components
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
How To Change the Tab Order of GUI Controls
How To Contribute
How to Create and Open a ".gmail.txt" Archive
How to deal with Git and Gitlab concerning your Project
How to deal with Git and Gitlab for Gambas
How To Deal With Subversion for Gambas
How To Display a Chinese Character
How To Draw with gb.Cairo
How To Enter Data With gb.db.form
How To Get Gambas Web Started (1)
How To Get Started
How To Interface Gambas With External Libraries
How To make a chart with the gb.chart component
How to make a report with Gambas
How To Make KDE Run Gambas Executables Automatically
How To Open, Debug & Compile The IDE
How To Open a MySQL connection and use it
How To Open a SQLite connection and use it
How To Open a Unix ODBC connection and use it
How To Package Gambas
How To Package your Project
How To Print
How to Run Gambas and Gambas Apps on Windows using WSL
How To Run Gambas On Windows using Cygwin
How To Translate A Gambas Project
How To Translate Gambas
How To Translate The Gambas IDE (deprecated)
How To Use Parallel Port
Language Index
Language Overviews
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

How To Get Gambas Web Started (1)

Introduction

Below is a brief tutorial on how to start and use a Gambas web site, the requirements and how to deploy the work you have done. Note that the testing of the web page inside the IDE is not the same as when it is called from the browser, because the IDE, when executed, uses its own embedded web server with different variables (very different) in respect to a production server, and different from the interpreted code.

Use the directory of the project as the program to compile it and embed it in the "real" web server.

A gambas web (CGI) program is very simply made, it is just a piece of code like this:

Public Sub Main()
    
    Response.Begin
    Print "<h1>hola mundo</h1>"
    Response.End
    
End

But this does not handle client requests (Request class) just a simple static "hola mundo" using the Response class to the web browser when the client (user) requests the CGI program code.

Illustrating the equivalents

The Gambas technology offers similar characteristics and features in a similar way to other technologies, let's see a comparison table of this:

Technology Interpreted Compiled
Gambas gbs files (Gambas server pages) gb programs (Gambas web component)
Java jsp (Javas server pages) servlets (Java Enterprise)
PhP php/phtml (php-cgi/php-fpm) N/A
.NET asp (active server pages) COM ( CLR runtime)

Preliminary concepts

Gambas web technology is provided to produce web 2.0 ( dynamic and also interactive content).

There are two ways to produce and/or render html in dynamic or static web content: Interpreted and/or pre Compiled.

The web content is produced with the help of a web server, using always CGI, directly announcing the pre Compiled program or as wrapper to the Gambas interpreter through script code.

Independently of the way the server delivers the document web page, all the time the CGI concept is used.

What its CGI?: Common Gateway Interface (CGI) offers a standard protocol for web servers to execute programs like console applications (also called command-line interface programs) running on a server that generates web pages dynamically. Such programs are known as CGI scripts or simply as CGIs. The server determines how the script is executed by the server.

Interpreted (as script) (Gambas server pages) permits interpreted source files based on their content as script and will render html or not using logic, its only recommended for static content that only needs minimal logic, if it fails it shows the source code in the webserver, this must be configured using the cgi as wrapper that delivers the request to interpreter.
Precompiled (as cgi) (Gambas web component) permits compiling the program that will act as a cgi program and produces the html rendering. The ide component will install many of the necessary, but in server its not recommended, this must be configured as the handler of the request directly.

Requirements

First we need a web server, a Gambas IDE compiler and Gambas script interpreter, If you only make cgi's the scripter is unnecessary. The recommended install commands must be done on your servers system, open a console and switch to root to install the Gambas distribution program packages, the required web server packages and setup the cgi components in the web server.

Installation requirements

First: get Gambas! The easiest way is to install Gambas from your Linux distribution. If Gambas is not yet contained in your distribution then download the distribution from http://gambas.sourceforge.net

Tip: If you have an ubuntu based web server you can use the PPA upgrade method to keep your gambas up to date with the latest version. See Ubuntu for more info.

Second: understanding! We REALLY need to understand the concepts of request Request and response Response, it is very much required to be familiar with this, HTTP is based on a request / response model, so there are two types of HTTP messages: the request and the response. The browser opens a connection to a server and makes a request. The server processes it, the client "makes a request" and webserver "returns a response"; so then data its sent and received using the two most commonly HTTP methods: GET and POST. Because Gambas is a RAD(Rapid Application Development) those concepts must be very clear for developing.

Last: get the environment! We need a webserver, that provides true gci capabilities. Nginx does not provide real capabilities u will need further tuneups to properly configure it. As general further info for high end production environments, that must configure as a duple of a server front end that provides a proxy reverse to the real cgi webserver with the Gambas3 cgi program.

Feature Comparison Chart and Status

Starting to develop in Gambas we need a right direction point, so here we provide a quick chart to see supported features in respect to other technologies.

The development of web technologies has gained strength from about 3 years ago in the Gambas community of developers, having today even a fully web graphical design component.

Here are not included the leaning curve because learn Basic its obviously more easy rather any other programing language, and Gambas are Basic like!

A performance comparison mail https://lists.gambas-basic.org/pipermail/user/2020-January/068432.html (January 2020) at the mail list; demonstrating how Gambas performs as well or better as php with interesting results.

FEATURE Gambas Java .NET Python Php
Based Coding Language Basic C++,C Basic,C++ CPython,C Perl,C
Backguard coding compatible always always Breaking API each 4 years Incompatible always
Running On Unix based Any OS Only MS based Almost Any OS Almost Any OS
Web server Any cgi based Tomcat, Jboss, Glassfish, Websphere, Weblogic IIS Apache2, IIS, Lightty, Hiawatta,Ngynx Apache2, IIS, Lightty, Hiawatta,Ngynx
Runtime Gambas Runtime Java virtual Machine Common Languaje Runtime Python runtime Zend Engine
Graphical Designer Gambas IDE Eclipse thirparty .NET IDE Not Not
Web Components gb.web, gb.http, gb.web.feed, gb.util.web, gb.curl EJB, JSP, JSF, Spring, GWT ASP, Spring, COM Many php-cgi, php-fpm, php-curl, php-sockets, more..
Web frameworks Gambasforge Spring, Struts, GWT Buil-in Django,CubicWeb Codeigniter, Lavarel, Symphony
DBMS Data Access ODBC, MySQL, SqLite, Postgres JDBC: Oracle, Sybase, MSSQL, MySQL, Sqlite, DB2, etc ADO.NET-oleDB, ODBC PyODBC: ODBC php-odbc, Php-pysql, php-sybase, php-pgsql, php-sqlite
DBMS Data Mapping Jbsan MapBD Hibernate, Dozer, Commons, Mapstruts, ModelMapper ADO.NET Django, Pandas Codeigniter, Kohana, Doctrine
Web services gb.xml Build-in Buil-in Add-on (many) php-soap, php-xml
Mobile native not yet Androit SDK Xamarin(MOno) Kivy, BeeWare Not possible
Unit Tests By own JUnit NUnit,MSUTF PyUnit PhpUnit

Starting coding

Gambas its a RAD software so lest assume will use the IDE, due you can always also use a normal text editor and then compile the cgi program by hand in console.

Start to code in IDE

When finished with the installation you can then use Gambas:

  • In a terminal window type "gambas3.gambas"

  • The Gambas IDE will open, select "New project...".

  • Select "Create a application web gb.web", click next,

  • Find a directory where to put the web project, click next,.

  • Enter a name for your web project, click OK.

  • Close the tips of the day window.

This starts with a main module that when built renders a page that prints out all the important values it needs to understand to manage web cgi's,

  • In the project window find the start button, press it (or press F5 key).

  • Then the default browser will be opened or a new tab and a web address from localhost will be displayed

this starts a local embedded webserver using a bind port 8080, displaying the server GCI standard values, those are very important to understand for high level production web pages.

Deploy the results

When the IDE runs its a local embedded server, this is significantly different to how it runs on the server You must specify what its the "entry point" of the web application.

As a directory path root: All the cgi's will processed in the path, example: http://domain/thegcipath/ As a single entry: the cgi will be called directly by the request, example: http://domain/thegcipath/thecgiprogram

1) configuring CGI in webserver

On standard web server of providers web servers there's only two paths where the "produced program" (the Gambas compiled program u make) can be deployed, in the "/cgi-bin/" web path, and there's two only places for them, globally and per users, there's configurations for both cases:

Webserver Initial/global configs Per user configs Script additions module related
apache ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AddHandler cgi-script .cgi .sh .pl
<Directory "/home/*/public_html/cgi-bin/">
Options ExecCGI
SetHandler cgi-script
</Directory>
AddHandler cgi-script .gbs (*) a2enmod cgi cgid alias userdir
lighttpd $HTTP =~ "^/cgi-bin/" {
cgi.assign = ( "" => "" )
}
$HTTP =~ "^(/~[^/]+)?/cgi-bin/" {
cgi.assign = ("" => "")
}
cgi.assign = ("gbs" => "gbs3")
cgi.assign = ("gambas" => "gbr3")
lighty-enable-mod cgi alias userdir

() in apache there's still no way to workaround the interpreting of the scrips at the moment of writing this, it will try to execute anything.

2) Producing an deploying in webserver

  • In the IDE, go to project

  • Create-> executable

  • If you use the "per user configuration" choose the directory output as "public_html" under your home

  • Choose the name of the output program, by default "programname.gambas"

  • If the webserver only permits cgi's programs with .cgi extension put in second input: mv $(FILE) $(FILE).cgi

  • The cgi program now can be invoked from url http://localhost/~username/cgi-bin/programname.gambas.cgi

All of this its taking in consideration that inside your home, there's a "public_html" directory, used and handled by the webserver as per user web content, and also under this there's a "cgi-bin" directory, that its for cgi programs, and the webservers software are only apache2 or lighttpd.

See also