Tencent Cloud ThinkPHP Serverless Component supports deploying RESTful API services based on ThinkPHP 6.x or above.
After the above two steps are completed, use Composer to initialize a ThinkPHP
project:
composer create-project topthink/think serverless-thinkphp
Use npm to install Serverless CLI globally:
npm install -g serverless
Create a serverless.yml
file in the project root directory:
$ touch serverless.yml
Configure serverless.yml
as follows:
# serverless.yml
app: appDemo
stage: dev
component: thinkphp
name: thinkphpDemo
inputs:
src:
src: ./
exclude:
- .env
region: ap-guangzhou
runtime: Php7
apigatewayConf:
protocols:
- http
- https
environment: release
Note:
Before deployment, you need to run
php think clear
to clear the locally running configuration cache.
Deploy by running the sls
command, and you can add the --debug
parameter to view the information during the deployment process:
$ sls deploy --debug
You can run the following command to remove the deployed ThinkPHP project:
$ sls remove --debug
Currently, you can scan a QR code to log in to the CLI by default. If you want to configure persistent environment variables/key information, you can also create a local .env
file:
touch .env # Tencent Cloud configuration information
Configure Tencent Cloud's SecretId
and SecretKey
information in the .env
file and save it:
# .env
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123
Note:
- If you don't have a Tencent Cloud account yet, please sign up first.
- If you already have a Tencent Cloud account, you can get
SecretId
andSecretKey
in API Key Management.
You can view more component information in the repository of Serverless Components.
Was this page helpful?