Saturday 29 February 2020

Install MySQL on my mac

Download and install

https://dev.mysql.com/downloads/file/?id=492745

MySQL strong password
root
Kxx

Install MySQL workbench as well.

You can create a new schema (eg, matthew_schema) in MySQL workbench. It will show as below.
Some helpful, but too long video:
https://www.youtube.com/watch?v=UcpHkYfWarM

> mysql -u root -p
xxx

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| matthew_schema     |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)


mysql> use matthew_schema;


Start/Stop MySQL Server

https://osxdaily.com/2014/11/26/start-stop-mysql-commands-mac-os-x/

or
System preference >> MySQL

Samples

mysql> select table_schema,table_name,table_type from information_schema.tables where table_schema = 'matthew_schema' 
    -> ;
+----------------+------------+------------+
| TABLE_SCHEMA   | TABLE_NAME | TABLE_TYPE |
+----------------+------------+------------+
| matthew_schema | t_test     | BASE TABLE |
+----------------+------------+------------+
1 row in set (0.00 sec)


mysql> select table_schema,table_name,table_type from information_schema.tables where table_schema = 'matthew_schema' and table_name ='migrations' and table_type = 'BASE TABLE';


Friday 28 February 2020

Install Lumen on your MacOS


Testing Lumen with AWS (Serverless Lumen API)
https://medium.com/@igliop/https-medium-com-igliop-running-a-serveless-lumen-rest-api-on-aws-lambda-804089b0852c

29/2/20 The above link does not work for me. I had the below error while sam packaging.

Ins-MacBook-Pro:lambda-lumen-test inheeoh$ sam package --template-file template.yaml --output-template-file serverless-output.yaml --s3-bucket lumen-serverless-lambda
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/0.43.0/libexec/lib/python3.7/site-packages/samcli/yamlhelper.py", line 90, in yaml_parse
    return json.loads(yamlstr, object_pairs_hook=OrderedDict)
  File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 361, in loads
    return cls(**kw).decode(s)
  File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


During handling of the above exception, another exception occurred:





To test Lumen on my mac, I had to install Composer first.
https://medium.com/@igliop/https-medium-com-igliop-running-a-serveless-lumen-rest-api-on-aws-lambda-804089b0852c

After doing trials for a while, I found that 'apt' is not command for mac, and you have to use 'homebrew'.


Ins-MacBook-Pro:~ inheeoh$ touch .bash_profile
Ins-MacBook-Pro:~ inheeoh$ vim .bash_profile 
Ins-MacBook-Pro:~ inheeoh$ echo $JAVA_HOME

Ins-MacBook-Pro:~ inheeoh$ . .bash_profile
Ins-MacBook-Pro:~ inheeoh$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Ins-MacBook-Pro:~ inheeoh$ 
Ins-MacBook-Pro:~ inheeoh$ 
Ins-MacBook-Pro:~ inheeoh$ 
Ins-MacBook-Pro:~ inheeoh$ sudo apt update
Password:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin/apt" (-1)


Install Composer with brew
https://gist.github.com/tomysmile/3b37ab4a1ddd604093fe724d0a882166
This takes a while, 10min?

Downloaded Command Line Tools for Xcode
Installing Command Line Tools for Xcode

Done with Command Line Tools for Xcode

...
Ins-MacBook-Pro:bin inheeoh$ composer -V
Composer version 1.9.3 2020-02-04 12:58:49
Ins-MacBook-Pro:bin inheeoh$ 

Ins-MacBook-Pro:bin inheeoh$ . goaws
Ins-MacBook-Pro:aws inheeoh$ pwd
/Users/inheeoh/aws
Ins-MacBook-Pro:aws inheeoh$ ls

Ins-MacBook-Pro:aws inheeoh$ cd lambda-lumen-test/
Ins-MacBook-Pro:lambda-lumen-test inheeoh$ ls
LICENSE README.md src template.yaml
Ins-MacBook-Pro:lambda-lumen-test inheeoh$ vim template.yaml
Ins-MacBook-Pro:lambda-lumen-test inheeoh$ pwd
/Users/inheeoh/aws/lambda-lumen-test
Ins-MacBook-Pro:lambda-lumen-test inheeoh$ cd src/php/lumen/

Ins-MacBook-Pro:lumen inheeoh$ composer update



Ins-MacBook-Pro:lumen inheeoh$ php -S localhost:8000 -t public
PHP 7.3.11 Development Server started at Sat Feb 29 14:15:52 2020
Listening on http://localhost:8000
Document root is /Users/inheeoh/aws/lambda-lumen-test/src/php/lumen/public
Press Ctrl-C to quit.
[Sat Feb 29 14:16:07 2020] [::1]:55050 [404]: /
[Sat Feb 29 14:16:07 2020] [::1]:55051 [404]: /favicon.ico - No such file or directory
[Sat Feb 29 14:16:13 2020] [::1]:55054 [200]: /hello