Deploying PHP Laravel

Last updated: 2020-07-31 14:34:53

    Operation Scenarios

    Tencent Cloud Laravel Serverless Component supports Laravel v6.0 and above.


    Initializing Laravel project

    Before using this component, you need to initialize a laravel project first:

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


    Laravel uses Composer to manage dependencies, so you need to install Composer first. For more information, please see here.

    Modifying Laravel project

    When a function is executed, only /tmp is readable/writable; therefore, you need to write the storage directory of the laravel framework runtime into this directory by modifying the bootstrap/app.php file and adding the following content after $app = new Illuminate\Foundation\Application:

    $app->useStoragePath($_ENV['APP_STORAGE'] ?? $app->storagePath());

    Then, add the following configuration to the .env file in the root directory:

    # View file compilation path
    # Because it is a serverless function, it is impossible to store sessions on the disk. If sessions are not needed, you can use `array`
    # If necessary, you can store the session in a cookie or database
    # You are recommended to output the error log to the console for easier viewing in the cloud
    # The application storage directory must be `/tmp`



    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
    component: laravel
    name: laravelDemo
    org: orgDemo
    app: appDemo
    stage: dev
      src: ./
      region: ap-guangzhou
      runtime: Php7
          - http
          - https
        environment: release

    Detailed Configuration >>


    Run the following command to deploy by scanning code:

    sls deploy


    • Before deployment, you need to clear the local configuration cache by running php artisan config:clear.
    • To grant persistent permission, please see Account Configuration.


    You can run the following command to remove the deployed service:

    sls remove

    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.

    Was this page helpful?

    Was this page helpful?

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