Its All Romantic¶
In this section we will talk about ethna, smarty, localhost & webserver (Heroku) The goal upon this section is to set up ethna on a heroku. Ethna being lightweight we will not install it on heroku but rather just copy the required libs to the server.
Setting app on Heroku¶
Go to Heroku and set up your account.
First step here is to set up an app on heroku, lets name it ethna-web
.
Upon creating the app, go to settings and get the Git URL: git@heroku.com:ethna-web.git
Tip
Also install the Heroku Toolbelt based on your operating system if you haven’t done that already. https://toolbelt.heroku.com/
Back to Terminal¶
Now on the terminal, make a new Directory lets say mkdir ~/Documents/Ethna-Web_Heroku
And go to that directory.
Lets quickly create a file in that directory,
$ echo "<?php echo 'Hello Heroku'; ?>" >index.php
Initialize the git
$ git init
$ git add .
$ git commit -m "Committing the index.php"
Add the Remote
Because we have already created the app named ethna-web
. Lets just add
a remote for the existing app using the terminal
$ heroku git:remote -a ethna-web
Push
Note
Note that we added index.php
which also indicates heroku that its a PHP application
Test on your url (e.g. http://ethna-web.herokuapp.com/) provided by heroku for your app if hello
is rendered on the web browser.
Getting Ethna to work
While in the Dir ~/Documents/Ethna-Web_Heroku
. Lets do the following to add a project.
$ ethna add-project ethnaweb
Now if you have installed Ethna on your local machine, we need to copy the libraries to heroku server.
First copy,
$ cp -a ~/pear/share/pear/Smarty ethnaweb/app/
$ cp -a ~/pear/share/pear/Ethna ethnaweb/app/
Tip
You may also want to copy the DB files
$ cp -a ~/pear/share/pear/DB ethnaweb/app/
All Done
Push the changes to heroku’s repo
$ git add .
$ git commit -m "pushing ethna"
$ git push heroku master
Ethna should render the welcome page on the url http://ethna-web.herokuapp.com/ethnaweb/www/
Setting up Database¶
Setting the database (DB) requires following 2 steps:
- Create a DB on Heroku
- Set it up in Ethna
To create a DB on Heroku, I am going to use the free one Heroku Postgres. Note that the previous tutorial about DB uses Ethna’s Backend to call a query to MySQL, but we are not restricted to just using Ethna’s, misc DB can also be easily integrated.
Getting Heroku username & password
$ heroku config | grep HEROKU_POSTGRESQL
...HEROKU_POSTGRESQL_MAROON_URL: postgres://himvd
$ heroku pg:credentials MAROON
The above will output the username & password like the following
"dbname=abcdefg host=****.amazonaws.com port=5432 user=**** password=**** sslmode=require"
Setting PDO in Ethna
Setup the username and password in etc/ethnaweb-ini.php
$config = array(
// site
'url' => '',
// debug
// (to enable ethna_info and ethna_unittest, turn this true)
'debug' => false,
// db
// sample-1: single db
// 'dsn' => 'mysql://user:password@server/database',
// 'dsn' => 'dbname=d5thfeu7cb8dms host=ec2-54-227-252-82.compute-1.amazonaws.com port=5432 user=himvdmapqkjhav password=zGN3cprl66dNc1Qh-HzEsTwez7 sslmode=require',
'pghost' => '***82.compute-1.amazonaws.com',
'pgdbname' => '*****',
'pguser' => '*****',
'pgpassword'=> '*****',
<?php
function prepare()
{
//Access the config array
$host = $this->config->get('pghost');
$dbname = $this->config->get('pgdbname');
$user = $this->config->get('pguser');
$pass = $this->config->get('pgpassword');
// $dbh = new PDO('pgsql:host=localhost;dbname=[YOUR_DATABASE_NAME]');
// $db = new PDO('pgsql:host='.$host.';'.'dbname='.$dbname.';user='.$user.';password='.$pass);
$db = new PDO('pgsql:host='.$host.';'.'dbname='.$dbname, $user, $pass);
All Done ! Create the table in heroku using terminal and do the queries from ethna
Tip
CLI interface to connect to heroku’s postgresql
$ psql -h HOSTNAME -U USERNAME DBNAME