This topic describes how to deploy a ThinkPHP application to Function Compute. Function Compute provides a method different from traditional deployment methods. You can deploy a traditional ThinkPHP application to Function Compute and use the application for production without performing operations such as purchasing a server. The deployed ThinkPHP application can use the auto scaling, pay-as-you-go, and O&M-free features of Function Compute.

Prerequisites

The following operations are complete:
Notice

The content about how to use Funcraft to migrate an application from a traditional framework is no longer maintained. We recommend that you use Serverless Devs to migrate relevant frameworks to Function Compute.

For more information about how to migrate Function Compute-related resources from Funcraft to Serverless Devs, see Migrate resources from Funcraft to Serverless Devs.

For more information about how to use Serverless Devs to migrate an application from a web framework, see Use Serverless Devs to migrate web frameworks.

We apologize for any inconvenience caused.

Background information

ThinkPHP is a free, open source, fast, simple, lightweight, and object-oriented PHP development framework. ThinkPHP is designed to develop agile web applications and simplify enterprise application development. ThinkPHP complies with the guidelines of simplicity and practicality. ThinkPHP features excellent performance and is simple in code, and also pays more attention to ease of use. You can use ThinkPHP free of charge because it is distributed under the Apache2 open source license. You can release applications that you develop in ThinkPHP as open source projects or commercial products.

Procedure

Notice

The content about how to use Funcraft to migrate an application from a traditional framework is no longer maintained. We recommend that you use Serverless Devs to migrate relevant frameworks to Function Compute.

We apologize for the inconvenience caused.

  1. Run the following command to create a ThinkPHP project.
    composer create-project topthink/think tp                        
    Note If a ThinkPHP project already exists, skip this step.
  2. Run the following command to open the ThinkPHP project:
    cd <project-name>            
  3. Run the on-premises project.
    php think run           
  4. Run the fun deploy -y command to deploy the application to Function Compute.
    fun deploy -y
    Expected output:
    current folder is not a fun project.
    downloading nginx and php7.2 zip from https://gosspublic.alicdn.com/fun/frameworks/support/fun-support-custom-php-d73a6bd6.zip to /private/var/folders/wl/_2ngtj291wx1cj55xlnn290w0000gn/T/fun-support-custom-php-d73a6bd6.zip...
    extract nginx and php7.2 zip to custom runtime...
    Generating 
    ... ... ...
            trigger httpTrigger deploy success
        function tp deploy success
    service tp deploy success
    Detect 'DomainName:Auto' of custom domain 'Domain'
    Request a new temporary domain ...
    The assigned temporary domain is 15631862-XXX.test.functioncompute.com, expired at 2020-04-10 13:17:42, limited by 1000 per day.
    Waiting for custom domain Domain to be deployed...
    custom domain Domain deploy success         

    After the application is deployed, you can check logs to find the temporary domain name that is generated by Function Compute. You can use the temporary domain name to access the deployed application.

    Note The temporary domain name is used only for demonstration and development purposes. It is valid for a limited period of time. You must use a domain name that has obtained an Internet Content Provider (ICP) filing from Alibaba Cloud for production. For more information, see Configure a custom domain name.