All Products
Search
Document Center

Function Compute:Deploy a code package

Last Updated:Apr 01, 2026

Deploy a PHP function with third-party dependencies to Function Compute by packaging your code and the vendor directory into a ZIP file. This guide uses Nette\Utils as an example dependency and covers two deployment methods: Composer with the Function Compute console, and Serverless Devs.

Prepare your code

Set up a local code directory with your function handler before deploying.

  1. Create a directory named mycode for your function code.

    • Linux and macOS: Run mkdir -p /tmp/mycode.

    • Windows: Create a folder named mycode.

  2. In the mycode directory, create index.php with the following content:

    <?php
    
    require_once __DIR__ . '/vendor/autoload.php';
    
    use Nette\Utils\Arrays;
    
    function handler($event, $context) {
        return Arrays::contains([1, 2, 3], 1);
    }

Method 1: Use Composer

Install dependencies locally with Composer, package the code into a ZIP file, and upload it through the Function Compute console.

Prerequisites

Before you begin, ensure that you have:

Install dependencies and deploy

  1. In the mycode directory, create composer.json:

    {
      "require": {
        "nette/utils": "v3.2.5"
      }
    }
  2. In the mycode directory, run composer install to install dependencies. After the command completes, Composer creates a composer.lock file and a vendor directory in mycode. Your downloaded dependencies are stored in vendor.

  3. Package all files in mycode into a ZIP file.

    • Linux and macOS: Navigate to the mycode directory and run:

      zip code.zip -r ./*
      Note: Make sure you have read and write permissions on the directory.
    • Windows: Open the mycode directory, select all files, right-click, and compress them into a ZIP file.

    Note: Make sure that index.php is in the root directory of the package.
  4. In the Function Compute console, open the function you want to update. In the upper-right corner of the function details page, click Upload Code and select the ZIP file. Alternatively, upload a ZIP file when creating a function. See Create an event function.

  5. On the Code tab of the function details page, click Test Function to verify the deployment.

Method 2: Use Serverless Devs

Use Serverless Devs with Docker to build and deploy your function without manually managing the ZIP file.

Prerequisites

Before you begin, ensure that you have completed the following:

Install dependencies and deploy

  1. In the mycode directory, create s.yaml with the following content:

    edition: 3.0.0
    name: fcDeployApp
    access: "default"
    
    vars: # The global variables.
      region: "cn-hangzhou"
    
    resources:
      hello_world:
        component: fc3 # The name of the component.
        props:
          region: ${vars.region}              # For information about how to use variables, visit https://docs.serverless-devs.com/serverless-devs/yaml#%E5%8F%98%E9%87%8F%E8%B5%8B%E5%80%BC.
          functionName: "testphp"
          description: 'this is a test'
          runtime: "php7.2"
          code: ./
          handler: index.handler
          memorySize: 128
          timeout: 30
  2. In the mycode directory, create composer.json:

    {
        "require": {
            "nette/utils": "^3.0"
        }
    }
  3. Run the following command to install dependencies inside a Docker container that matches the Function Compute runtime environment:

    sudo s build --use-docker

    After the command completes, Serverless Devs installs the dependencies and code into the ./vendor directory.

  4. Run the following command to deploy the function:

    sudo s deploy

    After the command completes, your function is deployed to Function Compute.

What's next

To manage dependencies without packaging them into every deployment, use Function Compute layers. See Create a custom layer.