Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to quickly create CMS content Management system with Laravel + Serverless Framework

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how Laravel + Serverless Framework can quickly create a CMS content management system. The content is concise and easy to understand, and it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

First of all, let me introduce the main local environment:

Git: not much, as long as you know how to type the code.

Node.js: since the main programming language of Tencent Cloud Serverless Framework is Node.js, please create one locally.

NPM:NPM is a package management tool installed with Node.js, which can solve many problems in Node.js code deployment. Our sls is also downloaded through this tool.

PHP: don't say much, the best language

Composer, the package management tool of the Composer:PHP world, similar to npm

Laravel:Laravel is a concise and elegant PHP Web development framework (PHP Web Framework).

It seems to be a little too much. Let's look down step by step.

1. Install Serverless$ npm install-g serverless

Our most important and simplest step is done.

two。 Configure Composer

There are two ways, and we use the first one here to demonstrate for you.

The first way to download the phar file is:

$wget https://getcomposer.org/download/1.9.1/composer.phar

The second type of direct installation:

Php-r "copy ('https://getcomposer.org/installer',' composer-setup.php');" php-r "if (hash_file ('sha384',' composer-setup.php') = = 'baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') {echo' Installer verified';} else {echo 'Installer corrupt'; unlink (' composer-setup.php');} echo PHP_EOL;" php composer-setup.phpphp-r "unlink ('composer-setup.php');"

For convenience, I downloaded the composer.phar file directly here. The specific usage is as follows:

$php composer.phar

3. Create coastercms$php composer.phar create-project web-feet/coastercms

First of all, we use the installed composer to create our project. If you install composer directly in the environment variable, please replace the php composer.phar yourself. Then we need to modify the Laravel project

Since only / tmp can be read and written when the cloud function is executed, we need to write the storage directory of laravel framework runtime to this directory. To do this, we need to modify the bootstrap/app.php file and add after $app = new Illuminate\ Foundation\ Application:

$app- > useStoragePath ($_ ENV ['APP_STORAGE']? $app- > storagePath ())

Complete the style:

/ * |-- | Create The Application |-- -| | The first thing we will do is create a new Laravel application instance | which serves as the "glue" for all the components of Laravel And is | the IoC container for the system binding all of the various parts. | * / $app = new Illuminate\ Foundation\ Application (realpath (_ _ DIR__.'/../')) $app- > useStoragePath ($_ ENV ['APP_STORAGE']? $app- > storagePath ()) / * / * |-- | Create The Application |-- -| | The first thing we will do is create a new Laravel application instance | which serves as the "glue" for all the components of Laravel And is | the IoC container for the system binding all of the various parts. | * / $app = new Illuminate\ Foundation\ Application (realpath (_ _ DIR__.'/../')) $app- > useStoragePath ($_ ENV ['APP_STORAGE']? $app- > storagePath ()) / * # View file compilation path VIEW_COMPILED_PATH=/tmp/storage/framework/views# cannot store session on the hard disk because it is a non-service function. If you do not need sessions, you can use array#. If you need to, you can store session in cookie or database SESSION_DRIVER=array# recommends that you output the error log to the console. It is convenient for the cloud to view the storage directory of the LOG_CHANNEL=stderr# application must compile the path for the / tmpAPP_STORAGE=/tmp# view file VIEW_COMPILED_PATH=/tmp/storage/framework/views # because it is a non-service function, it is impossible to store session on the hard disk, if you do not need sessions, you can use array# if you need to store session in cookie or database SESSION_DRIVER=array # it is recommended to output the error log to the console To facilitate the cloud to view LOG_CHANNEL=stderr # applications, the storage directory must be / tmpAPP_STORAGE=/tmp4. Configure the MySQL database

Here, we recommend using Tencent Cloud's CDB cloud database:

DB_CONNECTION= "mysql" DB_HOST= "gz-cdb-qla00XXX.sql.tencentcdb.com" DB_PORT=639XXDB_DATABASE= "coaster_db" DB_USERNAME= "coaster_usr" DB_PASSWORD= "secret" DB_PREFIX=

Then rename .env.example to .env. At this point, our Laravel configuration is complete.

5. Deploy Serverless

Next, we create the serverless.yml file in the project root directory and configure it as follows

Touch serverless.yml# serverless.ymlMyComponent:component: "@ serverless/tencent-laravel" inputs:region: ap-guangzhou functionName: laravel-functioncode:. / functionConf:timeout: 10memorySize: 128environment:variables:TEST: valevpcConfig:subnetId:''vpcId:' 'apigatewayConf:protocol: httpsenvironment: release

When we are done, we run it in the current directory:

Serverless-debug

After booting the installation, you can go to the administrative background:

The above content is Laravel + Serverless Framework how to quickly create CMS content management system, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report