Glad-I-Was-Here (PHP, Postgresql)
/docs/gears/developer/toyapps/gladiwashere-php-postgresql/
This version of the Glad-I-Was-Here guestbook App also uses PHP, but chooses Postgresql instead of Mariadb as its database.
If you have not already read through Glad-I-Was-Here (PHP, Mariadb), we recommend you do so first as we’ll only discuss things in this section that were not covered before.
To obtain the source code:
% git clone https://gitlab.com/ubos/ubos-toyapps
Go to subdirectory gladiwashere-php-postgresql.
Package lifecycle and App deployment
Like all other Apps on UBOS including Hello World,
gladiwashere-php-postgresql is built with makepkg, installed with
pacman and deployed with ubos-admin:
% makepkg -f
% sudo pacman -U gladiwashere-php-postgresql-*-any.pkg.tar.xz
% sudo ubos-admin createsite
Specify gladiwashere-php-postgresql as the name of the App.
Manifest JSON
Let’s examine this App’s UBOS Manifest file. It is identical
to that of gladiwashere-php-mysql, with the following differences:
-
It declares a different
defaultcontextso you can run both the MySQL and the Postgresql version of this App at the same time on the same device with their respective default context URL, which is different from each. -
It specifies the
postgresqlrole instead of themysqlrole, to use Postgresql instead of MySQL. -
It uses Postgresql database drivers to access Postgresql from PHP.
{
"type" : "app",
"roles" : {
"apache2" : {
"defaultcontext" : "/guestbook-postgresql",
"depends" : [
"php",
"php-apache",
"php-pgsql"
],
"apache2modules" : [
"php7"
],
"phpmodules" : [
"pgsql"
],
"appconfigitems" : [
{
"type" : "file",
"name" : "index.php",
"source" : "web/index.php",
},
{
"type" : "file",
"name" : "config.php",
"template" : "tmpl/config.php.tmpl",
"templatelang" : "varsubst"
},
{
"type" : "symlink",
"name" : "gladiwashere.php",
"source" : "web/gladiwashere.php"
}
]
},
"postgresql" : {
"appconfigitems" : [
{
"type" : "database",
"name" : "maindb",
"retentionpolicy" : "keep",
"retentionbucket" : "maindb",
"privileges" : "select, insert"
}
],
"installers" : [
{
"name" : "maindb",
"type" : "sqlscript",
"source" : "sql/create.sql"
}
]
}
}
}
-
phpmoduleslists the PHP modules that the App requires. In this case, it needs Postgresql drivers, and not MySQL drivers. -
By specifying the role
postgresqlinstead ofmysqlin the lower part of the manifest file, UBOS knows that the database to be provisioned (and backed up, restored etc.) is supposed to be a Postgresql database. -
Correspondingly, in the
config.php.tmplthe variables refer to Postgresql:<?php $dbName = '${appconfig.postgresql.dbname.maindb}'; $dbUser = '${appconfig.postgresql.dbuser.maindb}'; $dbPass = '${escapeSquote( appconfig.postgresql.dbusercredential.maindb )}'; $dbServer = '${appconfig.postgresql.dbhost.maindb}';