This document describes how to use a web function to quickly migrate a local Laravel service to the cloud.
This document mainly describes how to deploy in the console. You can also complete the deployment on the command line. For more information, please see Deploying Framework on Command Line.
WebFunc in the search box to filter all web function templates, select Laravel Framework Template, and click Next as shown below:
http://0.0.0.0:9000 in a browser, and you can access the sample Laravel project locally as shown below:
Add the following content to the file (which is used to configure environment variables and start services. Here is only a sample. Please adjust the specific operations according to your actual business scenario):
Next, perform the following steps to make simple modifications to the initialized project, so that it can be quickly deployed through a web function. The steps of project transformation are as follows:
scf_bootstrap bootstrap file
scf_bootstrap bootstrap file in the project root directory. This file is used to configure environment variables, specify service bootstrap commands, and make sure that your service can be started normally through this file.
scf_bootstrapmust have the executable permission of
- If you want to output environment variables in the log, you need to add the
-uparameter before the bootstrap command, such as
python -u app.py.
Modify the file read/write path
In the SCF environment, only files in the
/tmp directory are readable/writable. If you select other directories, write will fail due to the lack of permissions. Therefore, you need to inject environment variables in the
scf_bootstrap file to adjust the output directory of the Laravel framework:
# Inject the SERVERLESS flag
# Modify the template compilation cache path, as only `/tmp` is readable/writable in SCF
# Modify `session` to store it in the memory (array type)
# Output logs to `stderr`
# Modify the application storage path
# Initialize the template cache directory
mkdir -p /tmp/storage/framework/views
Modify the listening address and port
The listening port in the web function must be
9000, so you need to specify the listening port in
scf_bootstrap through the following command:
/var/lang/php7/bin/php artisan serve --host 0.0.0.0 --port 9000
The content of
scf_bootstrap is as follows:
Deploy in the cloud
After the local configuration is completed, run the bootstrap file and make sure that your service can be normally started locally. Then, perform the following steps to deploy Laravel:
After the deployment is completed, you can quickly access and test your web service in the SCF console and try out various features of SCF, such as layer binding and log management. In this way, you can enjoy the advantages of low cost and flexible scaling brought by the serverless architecture.