本文介绍如何将Laravel应用部署到函数计算。与传统的部署方法相比,您可以跳过购买机器等步骤,将传统的Laravel应用一键部署至云端直接用于生产,并且拥有弹性伸缩、按量付费及免运维等特性。
您已完成以下操作:
安装Funcraft。更多信息,请参见
安装Funcraft
。
配置Funcraft。更多信息,请参见
配置Funcraft
。
安装Composer。详细信息,请参见
Composer
。
本文介绍的如何使用Funcraft迁移传统框架的相关内容,后期将不再维护,建议您使用Serverless Devs迁移相关框架到
函数计算
。关于如何将函数计算的相关资源从Funcraft迁移到Serverless Devs进行管理的详细操作,请参见
从Funcraft迁移到Serverless Devs
。
关于如何使用Serverless Devs迁移Web框架的详细操作,请参见
使用Serverless Devs迁移Web框架
。
由此带来的不便,敬请谅解!
通过以下不同的方案创建Laravel项目。详细信息,请参见
官方文档
。若已有Laravel项目则跳过该步骤。
-
方案一
composer create-project "laravel/laravel=5.8.*" --prefer-dist mylaravel
-
方案二
composer create-project laravel/laravel --prefer-dist mylaravel "5.8.*"
-
方案三
composer create-project "laravel/laravel:5.8.*" --prefer-dist mylaravel
-
执行以下命令进入刚创建的示例项目或您已有的项目。
-
在本地打开
bootstrap
目录下的
app.php
文件,添加以下代码,实现将Laravel项目中的
storage
目录放到具有读写权限的
/tmp
目录下,以获取读写权限。
$app->useStoragePath(env('STORAGE_PATH', dirname(__DIR__) . '/storage'));
-
执行以下命令运行本地项目。
-
执行
fun deploy -y
命令将项目部署至函数计算。
fun deploy -y
预期输出。
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
-
查看.
/mylaravel/.fun/root/etc/nginx/sites-enabled
路径下的
laravel.conf文件中是否存在
keepalive_timeout
字段。