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 one of the following commands to create a Laravel application. For more information,
see Installation. If you have created a Laravel application, skip this step.
- Command 1
composer create-project "laravel/laravel=5.8.*" --prefer-dist mylaravel
- Command 2
composer create-project laravel/laravel --prefer-dist mylaravel "5.8.*"
- Command 3
composer create-project "laravel/laravel:5.8.*" --prefer-dist mylaravel
- Command 1
- Run the following command to open the sample application or an existing application:
- In the bootstrap directory on your on-premises machine, open the app.php file and add the following code. This way, the storage directory of the application is placed in the /tmp directory, on which Function Compute has read and write permissions.
$app->useStoragePath(env('STORAGE_PATH', dirname(__DIR__) . '/storage'));
- Run the following command to run the on-premises application:
- Run the
fun deploy -ycommand to deploy the application to Function Compute.
fun deploy -yThe following sample code shows the 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 /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
- Check whether the
keepalive_timeoutfield exists in the laravel.conf file in the /mylaravel/.fun/root/etc/nginx/sites-enabled directory.
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 Bind a custom domain name.
- If the field does not exist, check the expected output provided in Step 5 to find the temporary domain name that is generated by the system. Then, use the temporary domain name to visit the deployed application.
- If the field exists, delete the field from the file and run the following command:
fun deploy -y
After you deploy the application again, you can find the temporary domain name that is generated by the system in the output. You can use the temporary domain name to visit the deployed application.