Deploying ThinkPHP Framework

Last updated: 2020-09-04 15:55:38

    Overview

    Tencent Cloud ThinkPHP Serverless Component supports deploying RESTful API services based on ThinkPHP 6.x or above.

    Prerequisites

    Initializing ThinkPHP project

    1. The PHP environment has been set up locally. The recommended version is PHP 7.1 or above (ThinkPHP 6 is recommended).
    2. Install Composer: ThinkPHP uses Composer to manage dependencies. For the installation method, please see here.

    After the above two steps are completed, use Composer to initialize a ThinkPHP project:

    composer create-project topthink/think serverless-thinkphp

    Operation Guide

    1. Install

    Use npm to install Serverless CLI globally:

    npm install -g serverless

    2. Configure

    Create a serverless.yml file in the project root directory:

    $ touch serverless.yml

    Configure serverless.yml as follows:

    # serverless.yml
    org: orgDemo
    app: appDemo
    stage: dev
    component: thinkphp
    name: thinkphpDemo
    
    inputs:
      src:
        src: ./
        exclude:
          - .env
      region: ap-guangzhou
      runtime: Php7
      apigatewayConf:
        protocols:
          - http
          - https
        environment: release

    More configuration items >>

    3. Deploy

    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

    4. Remove

    You can run the following command to remove the deployed ThinkPHP project:

    $ sls remove --debug

    Account configuration (optional)

    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 and SecretKey in API Key Management.

    More components

    You can view more component information in the repository of Serverless Components.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help