简体中文 | English
Laravel Serverless Component for Tencent Cloud, support Laravel >= 6.0
.
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
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
Install the Serverless Framework globally:
$ npm install -g serverless
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.
# 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
Notice: Before deploying, you should clear local run config cache, run
php artisan config:clear
.
$ sls deploy
Notice:
sls
is short forserverless
command.
$ sls remove
Checkout the Serverless Components repo for more information.