Tuesday, 10 March 2020

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)



Thursday, 5 March 2020

Make my script auto-complete

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

This is good but sometimes I had to hit tab twice to see commands.

Lumen tutorial 2 - Lumen + AWS

Tutorial:
https://medium.com/@igliop/https-medium-com-igliop-running-a-serveless-lumen-rest-api-on-aws-lambda-804089b0852c

I was following above site, but had error while using below. Localhost was working but not live url in aws.

$ sam package — template-file template.yaml — output-template-file serverless-output.yaml — s3-bucket yourbucketname

Sunday, 1 March 2020

Lumen tutorial

Tutorial
https://auth0.com/blog/developing-restful-apis-with-lumen/

This link looks easy and thorough as well.
https://medium.com/@Dotunj/building-a-rest-api-with-lumen-403b67fec4d6

Following above url, I had below error.

Ins-MacBook-Pro:authors inheeoh$ php artisan make:migration create_authors_table
Created Migration: 2020_03_01_103525_create_authors_table
Ins-MacBook-Pro:authors inheeoh$ php artisan migrate

In Connection.php line 669:
                                                                                                                                    
  SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.t  
  ables where table_schema = matthew_schema and table_name = migrations and table_type = 'BASE TABLE')                              
                                                                                                                                    

In Connector.php line 70:
                                                                                           
  SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client  
                                                                                           

In Connector.php line 70:
                                                                                                                
  PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]  
                                                                                                                


I found the error reason is from my MySQL version 8.0


mysql> CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
Query OK, 0 rows affected (0.04 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

And changed .env file to use:
DB_DATABASE=matthew_schema
DB_USERNAME=user
DB_PASSWORD=yourpassword

mysql> select host, user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
| localhost | user             |
+-----------+------------------+
5 rows in set (0.00 sec)



Finally success!

Ins-MacBook-Pro:authors inheeoh$ php artisan migrate
Migration table created successfully.
Migrating: 2020_03_01_103525_create_authors_table
Migrated:  2020_03_01_103525_create_authors_table (0.01 seconds)
Ins-MacBook-Pro:authors inheeoh$ 




Running tutorial on AWS Ubuntu live server
While creating 'authors' project, I had below error.

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

Found solution
You have to install php-xml

I also had below error.
The following exception is caused by a lack of memory or swap, or not having swap configured


Run below site with sudo.
https://stackoverflow.com/questions/38828224/composer-update-the-following-exception-is-caused-by-a-lack-of-memory-and-not-h

ubuntu@ip-172-31-16-44:~$ sudo /sbin/mkswap /var/swap.1
mkswap: /var/swap.1: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=ac8bde7a-0271-4a81-913d-66c3e5117556
ubuntu@ip-172-31-16-44:~$ sudo /sbin/swapon /var/swap.1
swapon: /var/swap.1: insecure permissions 0644, 0600 suggested.

Then I could install lumen >> authors project successfully !


Visual Code

Cmd-Shift-x: extensions search/install
Cmd-Shift-p: preview >> json prettify, live server etc
(or F1)