Saturday, 14 March 2020

Ember data read from json file

Search for 'json file' from Ember tutorial page



It talks about putting json file public >> api >> workorder.json
Main route file, workorder.js file will read the json file as below.


export default class WorkordersRoute extends Route {

async model() {
let response = await fetch('/api/workorders.json');
let parsed = await response.json();
console.log("parsed", parsed);
return parsed;

}
}

You can add css into public >> assets >> scr.css
and include it from index.html file.

<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/sydney-camera-repair.css">


API working, route is working. good



{{#each @model as |wo|}}
<span class="mybold">{{wo.id}}</span>
<WorkOrderListing @workorder={{wo}} />
{{/each}}



Create Workorders api on Lumen



1. Create controller
Http >> Controllers >> WorkOrderController.php

2. Create Model

WorkOrder.php
Make sure class name is WorkOrder not Author.

3. Add routes
routes >> web.php
$router->get('workorders', ['uses' => 'WorkOrderController@showAllWorkOrders']);
$router->get('workorders/{id}', ['uses' => 'WorkOrderController@showOneWorkOrder']);
$router->post('workorders', ['uses' => 'WorkOrderController@create']);
$router->delete('workorders/{id}', ['uses' => 'WorkOrderController@delete']);
$router->put('workorders/{id}', ['uses' => 'WorkOrderController@update']);



4. Make sure your database (matthew_schema according to .env file) has 'work_orders' table. If model name is WorkOrder, system looks for work_orders. If model name is Author it looks for authors table.


5. Copy 1200 rows from browser to ember project /api/json file.
/Users/inheeoh/work/sydney-camera-repair/public/api/workorders.json

6. Ember routes will filter only this year's tasks.


7. it shows on website.







Tuesday, 10 March 2020

Let's install Lumen on LAMP in AWS

I had an error while running the first lumen command.
ubuntu@ip-172-31-26-11:~$ composer create-project --prefer-dist laravel/lumen authors


Problem 1
    - phpunit/phpunit 8.5.x-dev requires ext-dom * -> the requested PHP extension dom is missing from your system.

resolution:
https://stackoverflow.com/questions/43408604/php7-install-ext-dom-issue

In above link, both below commands failed and takes long.
composer update
composer require cviebrock/eloquent-sluggable

For above memory exception, below link has a solution.

https://github.com/geerlingguy/drupal-vm/issues/547


sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Above seems working. Failed to download....Now trying to download from source ...INstalling... continue.

composer update is finished.
Below takes forever. have a coffee.
composer require cviebrock/eloquent-sluggable
I also had bunch of below error. which could be resolved by below url. I think I should have installed these first.
https://stackoverflow.com/questions/41274829/php-error-the-zip-extension-and-unzip-command-are-both-missing-skipping
The zip extension and unzip command are both missing,
NOw, let's create the lumen project again.
composer create-project --prefer-dist laravel/lumen authors
Beautiful, project created on LAMP! It was not working on XAMPP.
Before running sql part, migration, you have to 
(1) create schema manually by running mysql
(2) edit .env with root userid/password
Deploy
This url saved me!
https://laracasts.com/discuss/channels/lumen/how-to-deploy-lumen-on-web-hosting
and this looks helpful as well.
https://stackoverflow.com/questions/55629307/how-to-deploy-lumen-framework-on-shared-hosting-subdomain
lumen deploy The requested URL was not found on this server.'
The error fixed by below
https://stackoverflow.com/questions/28242495/laravel-the-requested-url-was-not-found-on-this-server

ubuntu@ip-172-31-26-11:/etc/apache2/mods-enabled$ sudo vim /etc/apache2/apache2.conf 
ubuntu@ip-172-31-26-11:/etc/apache2/mods-enabled$ sudo systemctl restart apache2

Following the godaddy url, my lumen api structure look as below.


Install XAMPP

Installation
Ssh connection
matthew@SYDNEY-D-003:~/Dropbox/TechDoc/AWS Documentation/keypair$ ssh -i "matt_singapore_ec2_keypair.pem" ubuntu@54.251.163.161
ubuntu@ip-172-31-16-44:~$ sudo apt-get update
sudo /etc/inid.d/apache stop
Restart webserver
sudo /opt/lampp/lampp restart
Change config file >> all granted
phpmyadmin
username: root
password: xxx
Go to index.html
ubuntu@ip-172-31-16-44:~$ cd /opt/lampp/htdocs/

Install LAMP on Ubuntu

Stop existing aws instance

Create new Ubuntu instance on AWS. - Ubuntu 18.04

Associate the existing elastic IP to the new instance.
Stop old ubuntu server.

When ssh the ubuntu, you may be asked to reset .ssh configuration file.

inheeoh@Ins-MacBook-Pro bin % . runssh
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:0RZhkCIw/9uUZ/9/S70oN00G/lrYhkMQSQLUXK8++9U.
Please contact your system administrator.
Add correct host key in /Users/inheeoh/.ssh/known_hosts to get rid of this message.

https://serverfault.com/questions/321167/add-correct-host-key-in-known-hosts-multiple-ssh-host-keys-per-hostname


Follow this link for step by step

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04

After apache2 install, you will be able to see web page. if cannot, check AWS EC2 ip address >> security group >> inbound rule.



ubuntu@ip-172-31-26-11:~$ mysql -V
mysql  Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using  EditLine wrapper

ubuntu@ip-172-31-26-11:~$ php --version
PHP 7.2.24-0ubuntu0.18.04.3 (cli) (built: Feb 11 2020 15:55:52) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.3, Copyright (c) 1999-2018, by Zend Technologies

Restore my aws backup files
inheeoh@Ins-MacBook-Pro keypair % . restore_aws

// restore AWS files into bin folder...
index.php                                                                                   100%  765     6.9KB/s   00:00    
antman.png                                                                                  100%  893KB  98.9KB/s   00:09    
spiderman.jpg                                                                               100%   84KB 100.7KB/s   00:00    
ironman.png                                                                                 100% 113

Make my bash script accessible everywhere
https://askubuntu.com/questions/153251/launch-shell-scripts-from-anywhere

Make my script auto complete
https://askubuntu.com/questions/68175/how-to-create-script-with-auto-complete

Monday, 9 March 2020

Let's run Lumen on top of XAMPP (No good >> so many errors)

Lumen migrate error

ubuntu@ip-172-31-16-44:/opt/lampp/htdocs/authors$ sudo php artisan migrate

In Connection.php line 669:
                                                                                                                                         
  could not find driver (SQL: select * from information_schema.tables where table_schema = matthew_schema and table_name = migrations and 
  table_type = 'BASE TABLE')                                                                                                             
                                                                                                                                         

In Connector.php line 70:
                       
  could not find driver
                       

I found that XAMPP did not install MySQL...

ubuntu@ip-172-31-16-44:/opt/lampp/mysql$ mysql

Command 'mysql' not found, but can be installed with:

sudo apt install mysql-client-core-5.7 
sudo apt install mariadb-client-core-10.1

ubuntu@ip-172-31-16-44:/opt/lampp/mysql$ sudo apt install mysql-client-core-5.7

MariaDB is MySQL. You can run
ubuntu@ip-172-31-16-44:~/bin$ /opt/lampp/bin/mysql

https://askubuntu.com/questions/95241/how-do-i-start-the-mysql-console-in-xampp

ubuntu@ip-172-31-16-44:~/bin$ sudo ln -s /opt/lampp/bin/mysql /usr/local/bin/mysql

Now, you don't have below error - Can't connect to local MySQL ... any more when you type in 'mysql'.


I had to install mysql server not mysql-client.



ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
When you type mysql and enter, I got above error.


Install Lumen on Xampp Ubuntu
https://www.codentricks.com/installing-xampp-laravel-linux/

It talks about ln -s command etc.

Same approach as before...
https://stackoverflow.com/questions/50994393/laravel-php-artisan-migrate
https://stackoverflow.com/questions/50177216/how-to-grant-all-privileges-to-root-user-in-mysql-8-0

MariaDB [(none)]> CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BY 'yourpassword'' at line 1
MariaDB [(none)]> CREATE USER 'user'@'localhost' IDENTIFIED BY 'yourpassword';
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.000 sec)