Deploying ThinkPHP Framework

Last updated: 2021-03-05 15:33:19


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


    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
    app: appDemo
    stage: dev
    component: thinkphp
    name: thinkphpDemo
        src: ./
          - .env
      region: ap-guangzhou
      runtime: Php7
          - http
          - https
        environment: release

    More configuration items >>

    3. Deploy


    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


    • 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.