---
# System prepended metadata

title: 測試機安裝流程
tags: [JOHSON]

---

###### tags: `JOHSON`
# 測試機安裝流程

## 連線
```
ssh -i "Asia-EC-TestServer-EC2-Key.pem" ubuntu@ec2-43-206-119-147.ap-northeast-1.compute.amazonaws.com
```

## 安裝php7.4
```
apt-get install software-properties-common gnupg2 -y
add-apt-repository ppa:ondrej/php
apt-get update -y
apt-get install php7.4 php7.4-fpm php7.4-cli -y php7.4-curl php7.4-dom php7.4-mysql php7.4-zip
```
## 安裝composesr
```
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php /tmp/composer-setup.php --install-dir=/usr/bin --filename=composer
```
## 設定gitlab ssh
```
ssh-keygen -o -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub
```
## clone 專案
```
cd /var/www/html/ 
git clone git@gitlab.com:johnson_backend/shopifyadmin.git
```
## 設定env
```
cp .env.example .env
```

## 安裝nginx
```
apt-get update
apt-get install nginx 
vim /etc/nginx/conf.d/shopifyadmin.conf
```
# config
```
server {
    listen      80;
    listen [::]:80;
    listen     443;
    listen [::]:443;
    server_name 127.0.0.1;
        
    #access_log  logs/host.access.log  main;
    root   /var/www/html/shopifyadmin/public;
    index  index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # pass the PHP scripts to FastCGI server    
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
```
```
nginx -t
service nginx restart
```
## nginx 權限
```
chown -R www-data:www-data /var/www/html/shopifyadmin/
```
## 安裝mysql
```
apt-get update
apt-get install mysql-server
```
## mysql 設定
```
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Jhtadb@2022';
CREATE DATABASE shopifyadmin CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
use mysql;
exit
mysql_secure_installation
```
> [color=#e88f4c] Eason: 為了方便我連線我改了mysqld.cnf
> bind-address = 0.0.0.0
> 因為我沒辦法使用ssh_tunnel連線,推測是ubuntu22.04的關係
> 有其它解決方案可以跟我說

## 上傳金流檔案/解壓
```
scp -i "Asia-EC-TestServer-EC2-Key.pem" "D:/Java V2.1.zip" ubuntu@ec2-43-206-119-147.ap-northeast-1.compute.amazonaws.com:/home/ubuntu

scp -i "Asia-EC-TestServer-EC2-Key.pem" "D:/php-java-bridge-7.2.1.zip"  ubuntu@ec2-43-206-119-147.ap-northeast-1.compute.amazonaws.com:/home/ubuntu

scp -i "Asia-EC-TestServer-EC2-Key.pem" "D:/RSA.zip"  ubuntu@ec2-43-206-119-147.ap-northeast-1.compute.amazonaws.com:/home/ubuntu


apt-get install zip unzip

unzip /home/ubuntu/Java V2.1.zip
unzip /home/ubuntu/php-java-bridge-7.2.1.zip
unzip /home/ubuntu/RSA.zip
```

## 安裝金流套件

```
apt-get install openjdk-8-jdk
cp /home/ubuntu/Java V2.1/lib/* /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/

cp /home/ubuntu/php_java_bridge_7.2.1/* /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/

mkdir /usr/lib/jvm/java-8-openjdk-amd64/jre/classes
cp /home/ubuntu/conf/* /usr/lib/jvm/java-8-openjdk-amd64/jre/classes/

mkdir /usr/RSA
cp /home/ubuntu/RSA/* /usr/RSA/

 java -jar /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/JavaBridge.jar SERVLET_LOCAL:8080
 ```
 
 
## Redis

```
apt install redis-server

```

## Supervisor

```
apt install supervisor

```
Add .conf to /etc/supervisor/conf

## Cron
```
apt-get install cron
```

crontab -e
## Nvm
```
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

source ~/.profile 

nvm install 14.0.0

nvm use 14.0.0

專案安裝 npm install
```
