啟用 EC2 Instance 選擇 Ubuntu Server 18.04 LTS (HVM), SSD Volume Type
記得設定 Key pair,並使用 ssh + .pem 檔案連入 Instance
$ ssh -i "xxxxxx.pem" ubuntu@xxxxxx.compute-1.amazonaws.com$ sudo apt update
$ sudo apt upgrade$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update$ sudo apt install php7.3-fpm$ sudo apt install php7.3$ sudo apt install php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-intl -y$ sudo apt install nginx這邊使用 mysql 8.0.19 先加入 mysql apt 庫
$ wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb
$ sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb出現畫面選第一個然後選 8.0 再選 OK 接著安裝
$ sudo apt update
$ sudo apt-get install mysql-server出現畫面輸入 root 密碼,會確認一次 接著選項選第二個(選第一個設定上會怕麻煩) 安裝完成後連入 mysql 並建立 schema
$ mysql -u root -p
mysql> create database `moe`;
mysql> exit使用 nvm
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
$ . ~/.nvm/nvm.sh
$ nvm install node$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"將 composer.phar 移動到 /usr/local/bin 並且命名為 composer 之後執行比較快
$ sudo mv composer.phar /usr/local/bin/composer下載專案與必要套件
$ git clone https://gitlab.lab412.ee.ntut.edu.tw/www13751/MoE.git
$ cd MoE
$ npm install
$ composer install執行 webpack
$ npm run dev加入 .env,以下為範例
$ touch .env
$ vim .env然後直接 command + v 貼上(macOS + iTerm2)辦得到 記得要編輯正確 db 連線設定
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
APP_DEBUG=true
APP_URL=http://localhost/moe
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=xxxxx
DB_USERNAME=xxxxx
DB_PASSWORD=xxxxx
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
最後執行 migration,並看看資料有沒有寫入
$ php artisan migrate:refresh --seed$ mysql -u root -p moe
mysql> select * from users;
mysql> exit首先將 MoE 底下所有檔案(所有) 移動至 /var/www/html
$ sudo rm -rf /var/www/html/index.nginx-debian.html
$ sudo cp -a . /var/www/html調整檔案權限
$ sudo chown -R ubuntu:www-data /var/www/html
$ sudo chmod 755 /var/www/html/storage
$ sudo chmod 755 /var/www/html/bootstrap/cache編輯 nginx 設定
$ sudo vim /etc/nginx/sites-available/default對照以下並修改編輯
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html/public;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}
error_log /var/log/nginx/default_error.log error;
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include fastcgi_params;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
接著編輯 fpm 設定
$ sudo vim /etc/nginx/fastcgi_params將以下加入第一行
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
最後重啟服務
$ sudo service nginx restart
$ sudo service php7.3-fpm restart直接在瀏覽器打上 EC2 的 public DNS,即可成功訪問站台