Skip to content

Latest commit

 

History

History
executable file
·
130 lines (87 loc) · 2.88 KB

README.en.md

File metadata and controls

executable file
·
130 lines (87 loc) · 2.88 KB

Serverless PHP Laravel Tencent Cloud

Tencent Laravel Serverless Component

简体中文 | English

Introduction

Laravel Serverless Component for Tencent Cloud, support Laravel >= 6.0.

Content

  1. Prepare
  2. Install
  3. Create
  4. Configure
  5. Deploy
  6. Remove

0. Prepare

Initial Laravel Project

Before use this component, you should init a laravel project:

composer create-project --prefer-dist laravel/laravel serverless-laravel

Notice:Laravel use Composer manage dependencies, so you should install Composer firstly. Refer to Official Install

Modify Laravel Project

When cloud funtion running, only /tmp folder is writable, so we should change the APP_STORAGE folder to /tmp.

Add this line in bootstrap/app.php after $app = new Illuminate\Foundation\Application:

$app->useStoragePath(env('APP_STORAGE', '/tmp'));

We will also need to customize the location for compiled views, as well as customize a few variables in the .env file:

# views compiled path
VIEW_COMPILED_PATH=/tmp/storage/framework/views

# We cannot store sessions to disk: if you don't need sessions (e.g. API)
# then use `array`, else store sessions in database or cookies
SESSION_DRIVER=array

# Logging to stderr allows the logs to end up in Cloudwatch
LOG_CHANNEL=stderr

# app storage dir must be /tmp
APP_STORAGE=/tmp

1. Install

Install the Serverless Framework globally:

$ npm install -g serverless

2. Create

Just create the following simple boilerplate:

$ touch serverless.yml
$ touch .env           # your Tencent api keys

Add the access keys of a Tencent CAM Role with AdministratorAccess in the .env file, using this format:

# .env
TENCENT_SECRET_ID=XXX
TENCENT_SECRET_KEY=XXX
  • If you don't have a Tencent Cloud account, you could sign up first.

3. Configure

# serverless.yml

component: laravel
name: laravelDemo
org: orgDemo
app: appDemo
stage: dev

inputs:
  src: ./
  region: ap-guangzhou
  runtime: Php7
  apigatewayConf:
    protocols:
      - http
      - https
    environment: release

4. Deploy

Notice: Before deploying, you should clear local run config cache, run php artisan config:clear.

$ sls deploy

Notice: sls is short for serverless command.

 

5. Remove

$ sls remove

More Components

Checkout the Serverless Components repo for more information.