GCP
, Deployment
, Nginx
, Laravel6
gcloud init
gcloud auth login
gcloud config list project
gcloud projects create
==PROJECT_ID==)建立一個名稱為"test1023"的執行個體(GCE):gcloud compute instances create test1023 --image-project ubuntu-os-cloud --image-family ubuntu-1804-lts
若要指定網路區域可以下參數
--zone asia-east1-b
,否則區域為 gcloud init 時設定的那個
設定映像檔一定要這兩個參數:--image-project
,--image-family
進入 gcloud compute ssh "test1023"
(gcloud compute ssh --zone "asia-east1-b" "test1023"
)
輸入SSH 鑰匙密碼Enter passphrase for key '/Users/sarahcheng/.ssh/google_compute_engine':
開瀏覽器到 gcloud console 將防火牆打開
如果要刪除
gcloud compute instances delete test1023 --zone asia-east1-b
lsb_release -a
cat /etc/*release
php -v
,更新到 7.4
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt -y --allow-unauthenticated install php7.4
sudo apt-get install -y --allow-unauthenticated php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip,xml}
php -v
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
composer -v
sudo apt-get install mysql-server
若要安裝特定版本
sudo apt-get install mysql-server-5.7
若要設密碼:$sudo mysql_secure_installation
啟動 mysql-server:sudo systemctl start mysql
查看是否成功啟動:systemctl |grep mysql
進入 mysql server:sudo mysql -u root
查看目前使用者及其身份驗證方式:
SELECT User, Host, plugin FROM mysql.user;
CREATE USER 'sarah'@'localhost' IDENTIFIED WITH mysql_native_password BY '00000';
GRANT ALL PRIVILEGES ON *.* TO 'sarah'@'localhost';
select user,plugin,authentication_string from mysql.user;
sudo netstat -utlnp | grep 80
numeric 的意思是將名稱數字化(IP),例:原本的 localhost 會變成 127.0.0.1
sudo systemctl status apache2
sudo systemctl stop apache2
sudo apt-get install nginx -y
sudo apt-get -y --allow-unauthenticated install php7.4-fpm
sudo apt-get update
sudo apt-get upgrade -y --allow-unauthenticated
sudo apt-get install git
git clone https://github.com/laravel/laravel.git
修改 Nginx 設定檔中的讀取路徑為我們要部署的專案sudo vim /etc/nginx/sites-available/default
#root /var/www/html;
root /home/sarahcheng/laravel/public;
# 加入 index.php
index index.php
如圖:
location / {
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;
}
讓 niginx 重新載入修改完的設定檔:sudo nginx -s reload
進入專案安裝套件和設定環境:cd laravel
sudo composer install
mv .env.example .env
sudo php artisan key:generate
mysql -u sarah -p00000
CREATE DATABASE testdb;
show databases;
use testdb;
show tables;
(現在是空的)cd laravel
vim .env
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=testdb DB_USERNAME=sarah DB_PASSWORD=00000
php artisan migrate
(原本git clone 下來的專案就有寫好的 migration了)show tables;
(現在多了三個 table)exit
在專案目錄下:
sudo chown -R sarahcheng.www-data .
sudo chmod -R 2770 ./storage/
ls -al
外部 IP
。mysqldump --opt -usarahcheng -p laravel_shop > test.sql
gcloud compute scp test.sql test1023: --zone asia-east1-b
mysql -u 使用者名稱 -p 資料庫名稱 < backup.sql
$ sudo netstat -utlnp
基本上不用安裝laravel(不太可能在server上開發),不過還是提供參考指令:
sudo composer global require laravel/installer
vi ~/.bash_profile
export PATH="$HOME/.composer/vendor/bin:$PATH"
source ~/.bash_profile
laravel -V
p.s.composer show -i
查看 composer 安裝了什麼(composer.json)