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.
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.
Procedure
- Run one of the following commands to create a Laravel project. For more information,
see Installation. If a Laravel project already exists, 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
- Open the sample project or an existing project.
- 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 Laravel project is placed in the /tmp directory. Function Compute has read and write permissions on the /tmp directory.
$app->useStoragePath(env('STORAGE_PATH', dirname(__DIR__) . '/storage'));
- Run the on-premises project.
- Run the
fun deploy -y
command to deploy the application to Function Compute.fun deploy -y
The 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_timeout
field 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
Configure a custom domain name.