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

Step 1: Prepare the environment

  1. Install Funcraft. For more information, see Install Funcraft.
    Note You do not need to install Docker but only Funcraft. The easiest way to install Funcraft is to download the executable binary files. You can run the fun --version command to check whether the installation is successful.
  2. Configure Funcraft. For more information, see Configure Funcraft.
  3. Install Composer. For more information, visit the Composer official website.

Step 2: Migrate the application

  1. Run the following command to create a Laravel project. For more information, see the official documentation. If you already have a Laravel project, skip this step.
    composer create-project laravel/laravel=5.8.*  --prefer-dist   mylaravel
  2. Run the following command to open the sample application or an existing application:
    cd mylaravel
  3. In the bootstrap directory on your local machine, open the app.php file and add the following code. This way, the storage directory of the project is placed in the /tmp directory, for which Function Compute has read and write permissions.
    $app->useStoragePath(env('STORAGE_PATH', dirname(__DIR__) . '/storage'));
    modify-config
  4. Run the following command to run the on-premises application:
    composer install
  5. Run the fun deploy -y command to deploy the application to Function Compute.
    fun deploy -y
    The following results are returned:
    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 /Users/txd123/Desktop/demo123/mylaravel/.fun/root/etc/php/7.2/fpm/php-fpm.conf...
    Generating /Users/txd123/Desktop/demo123/mylaravel/.fun/root/etc/php/7.2/fpm/pool.d/www.conf...
    Generating /Users/txd123/Desktop/demo123/mylaravel/.fun/root/etc/nginx/nginx.conf...
    Generating /Users/txd123/Desktop/demo123/mylaravel/.fun/root/etc/logrotate.d/nginx...
    Generating /Users/txd123/Desktop/demo123/mylaravel/.fun/root/etc/logrotate.d/php7.2-fpm...
    Generating /Users/txd123/Desktop/demo123/mylaravel/.fun/root/usr/lib/php/7.2/php.ini-production...
    Generating /Users/txd123/Desktop/demo123/mylaravel/.fun/root/etc/nginx/sites-enabled/laravel.conf...
    Generating /Users/txd123/Desktop/demo123/mylaravel/.funignore...
    File /Users/txd123/Desktop/demo123/mylaravel/.funignore already exists, Fun will rename to /Users/txd123/Desktop/demo123/mylaravel/.funignore.bak
    Generating /Users/txd123/Desktop/demo123/mylaravel/laravel_bootstrap...
    Generating template.yml...
    Generate Fun project successfully!
    
    ========= Fun will use 'fun deploy' to deploy your application to Function Compute! =========
    using region: cn-beijing
    using accountId: ***********3743
    using accessKeyId: ***********Ptgk
    using timeout: 60
    
    Collecting your services information, in order to caculate devlopment changes...
    
    Resources Changes(Beta version! Only FC resources changes will be displayed):
    ...  ...  ...
    
    Waiting for service mylaravel to be deployed...
           Waiting for function mylaravel to be deployed...
                   Waiting for packaging function mylaravel code...
                   The function mylaravel has been packaged. A total of 7987 files were compressed and the final size was 32.34 MB
                   Waiting for HTTP trigger httpTrigger to be deployed...
                   triggerName: httpTrigger
                   methods: [ 'GET', 'POST', 'PUT' ]
                   trigger httpTrigger deploy success
           function mylaravel deploy success
    service mylaravel deploy success
    
    Detect 'DomainName:Auto' of custom domain 'Domain'
    Fun will reuse the temporary domain http://19247408-XXX.test.functioncompute.com, expired at 2020-05-22 09:36:48, limited by 1000 per day.
    
    Waiting for custom domain Domain to be deployed...
    custom domain Domain deploy succes

    After the application is deployed, you can check the logs to find the temporary domain name that Function Compute generated. You can use this 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. To use an application in a production environment, you must bind the application to a domain name that has obtained an Internet Content Provider (ICP) filing from Alibaba Cloud. For more information, see Bind a custom domain name.