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 operations such as purchasing a server. The deployed Laravel application can use the auto scaling, pay-as-you-go, and O&M-free features of Function Compute.
- Run the following command in the specified directory to initialize a project:
s init devsapp/start-laravel -d start-laravelThe -d parameter specifies the project name. In this example, the project name is start-laravel.Sample command output:Note Skip this step if the item exists.
Serverless Awesome: https://github.com/Serverless-Devs/package-awesome email@example.com file decompression completed .__ .__ | | _____ ____________ ___ __ ____ | | | | \__ \\_ __ \__ \\ \/ // __ \| | | |__/ __ \| | \// __ \\ /\ ___/| |__ |____(____ /__| (____ /\_/ \___ >____/ \/ \/ \/ Welcome to the start-laravel application This application requires to open these services: FC : https://fc.console.aliyun.com/ ACR: https://cr.console.aliyun.com/ This application can help you quickly deploy the Laravel project: Full yaml configuration: https://github.com/devsapp/laravel#%E5%AE%8C%E6%95%B4yaml Laravel development docs : https://learnku.com/docs/laravel/8.x This application homepage: https://github.com/devsapp/start-laravel Thanks for using Serverless-Devs You could [cd /test/start-laravel] and enjoy your serverless journey! If you need help for this example, you can use [s -h] after you enter folder. Document Star: https://github.com/Serverless-Devs/Serverless-Devs
- Run the following command to go to the project directory:
- Edit the s.yaml file. In this example, the project is deployed by using a container. The project code and the runtime environment, such as NGINX and PHP-FPM, are built to an image from which the container is created. Therefore, before you deploy the project, you must modify the name field in the s.yaml file to the name of your namespace. For example, if the name of your namespace is serverlessdevs188077086902****, modify the name field to
- Run the following command to deploy the project:
Sample command output:
[2021-09-03T15:07:58.647] [INFO ] [S-CLI] - Start ... Run: docker build -t fc-example/serverless-devs-laravel.laravel:LATEST-1630652880499 -f Dockerfile . Run: docker push registry.cn-shenzhen.aliyuncs.com/fc-example/serverless-devs-laravel.laravel:LATEST-1630652880499 [2021-09-03T15:08:03.610] [INFO ] [WEB-FRAMEWORK] - The configuration of the domain name is not detected, and a temporary domain name is generated. (node:12020) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) End of request Deployed. End of request [2021-09-03T15:08:07.710] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen [2021-09-03T15:08:07.710] [INFO ] [FC-DEPLOY] - Using access alias: default [2021-09-03T15:08:07.710] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902**** [2021-09-03T15:08:07.711] [INFO ] [FC-DEPLOY] - Using accessKeySecret: KdcUEJLoGto**** Using fc deploy type: sdk, If you want to deploy with pulumi, you can [s cli fc-default set deploy-type pulumi] to switch. [2021-09-03T15:08:08.237] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-laravel exists [2021-09-03T15:08:08.390] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole [2021-09-03T15:08:08.719] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists [2021-09-03T15:08:08.951] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole [2021-09-03T15:08:09.076] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists [2021-09-03T15:08:09.205] [INFO ] [FC-DEPLOY] - Checking Function laravel exists [2021-09-03T15:08:09.388] [INFO ] [FC-DEPLOY] - Using image registry: registry.cn-shenzhen.aliyuncs.com [2021-09-03T15:08:09.548] [INFO ] [FC-DEPLOY] - Try to use a temporary token for docker login WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login to registry: registry.cn-shenzhen.aliyuncs.com with user: cr_temp_user Pushing docker image: registry.cn-shenzhen.aliyuncs.com/fc-example/serverless-devs-laravel.laravel:LATEST-1630652880499... The push refers to repository [registry.cn-shenzhen.aliyuncs.com/fc-example/serverless-devs-laravel.laravel] 525f007fda01: Layer already exists 4fd11e800920: Layer already exists 176b3d17b74f: Layer already exists d2f0f5772b2e: Layer already exists a1a00fb53fe2: Layer already exists 878012e6ca96: Layer already exists a2d3463119d7: Layer already exists 9dfc54546eb9: Layer already exists 38d27ebecaac: Layer already exists 052274e6c62b: Layer already exists 58eed48d658d: Layer already exists c9b07fcdb99d: Layer already exists f3e7cafd1d54: Layer already exists b6c4e5a72df7: Layer already exists 53b44c8b01cc: Layer already exists 0768b5d062c4: Layer already exists 27a0adc0a8a6: Layer already exists 92c354d70bb1: Layer already exists 14a1ca976738: Layer already exists LATEST-1630652880499: digest: sha256:906f1776e0eabd7cb46a16cac57f39e1a2900fbdb9f02208efc799467f1a018d size: 4291 [2021-09-03T15:08:11.276] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-laravel exists [2021-09-03T15:08:11.330] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-laravel exists [2021-09-03T15:08:11.413] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-laravel [2021-09-03T15:08:11.414] [INFO ] [FC-DEPLOY] - Creating function: laravel [2021-09-03T15:08:11.414] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-laravel"] Make service serverless-devs-laravel success. Make function serverless-devs-laravel/laravel success. Make trigger serverless-devs-laravel/laravel/serverless-devs-laravel success. [2021-09-03T15:08:12.043] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-laravel exists [2021-09-03T15:08:12.148] [INFO ] [FC-DEPLOY] - Checking Function laravel exists [2021-09-03T15:08:12.318] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-laravel exists [2021-09-03T15:08:12.559] [INFO ] [FC-DEPLOY] - Creating custom domain: laravel.serverless-devs-laravel. 188077086902****.cn-shenzhen.fc.devsapp.net [2021-09-03T15:08:13.520] [INFO ] [FC-DOMAIN] - Creating custom domain: laravel.serverless-devs-laravel. 188077086902****.cn-shenzhen.fc.devsapp.net There is auto config in the service: serverless-devs-laravel Try container acceleration laravelExample: region: cn-shenzhen serviceName: serverless-devs-laravel functionName: laravel customDomains: - >- http://laravel.serverless-devs-laravel. 188077086902****.cn-shenzhen.fc.devsapp.net
After the project is deployed, you can view the temporary domain name generated by Function Compute in the execution output. The temporary domain name can be used to access the newly deployed application. For example, run the following command to access the application: