Installation and deployment of Laravel 5.1 and database connection examples of Sina SAE

Source: Internet
Author: User
Tags commit event listener goto mysql host php and phpmyadmin

1. Create an SAE application

First enter Sina Cloud SAE interface http://sae.sina.com.cn /:

 

 

Click "create new application", fill in the form on the Create application page, select PHP 5.6 as the development language, select "empty application", and then click "Create application ":

 

 

In this way, a "Laravel SAE" application is added to the management application list:

 

 

Next, click "Laravel SAE" to go to the application management page, and select the "code management" link on the left to upload the application code:

 

 

We choose to use Git to manage the code and click the "Git" button to go to the Git installation guide page:

 

On this page, we know that the code repository isHttps://git.sinacloud.com/laravelsae/Next, we can upload the code to SAE according to the deployment instructions.

2. Upload The Laravel project code to SAE


Here we chose a ready-made project laravel5-on-sae on Github, which made specific changes to Laravel 5.1 code for SAE, and we downloaded its project package and decompressed it locally. Go to the unzipped laravel5-on-sae Directory, delete the hidden folder. git, create a new config. yaml, and edit it as follows:

Handle:
-Rewrite: if (path ~ "^/$") Goto "public/index. php"
-Rewrite: if (! Is_dir ()&&! Is_file () & path ~ "^ (. *) $") Goto "public/index. php/$1"
Edit the. gitignore file and remove the first line/vendor (otherwise, ignore the directory by using the Git command, and an error is returned if/vendor/autoload. php is not found ).

Edit config/app. php and remove the following line from the providers array:

App \ Providers \ ViewComponentServiceProvider: class,
EDIT app/Providers/EventServiceProvider. php as follows:

<? Php

Namespace App \ Providers;

Use Illuminate \ Contracts \ Events \ Dispatcher as DispatcherContract;
Use Illuminate \ Foundation \ Support \ Providers \ EventServiceProvider as ServiceProvider;

Class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
     *
* @ Var array
*/
Protected $ listen = [

];

/**
* Register any other events for your application.
     *
* @ Param \ Illuminate \ Contracts \ Events \ Dispatcher $ events
* @ Return void
*/
Public function boot (DispatcherContract $ events)
    {
Parent: boot ($ events );
    }
}
Then execute the following command in the laravel5-on-sae Directory:

Git init
Git remote add sae https://git.sinacloud.com/laravelsae/
Git add.
Git commit-am 'laravelsae'
Git push sae master: 1
The username and password required for the last command are the secure mailbox and security password, instead of the Weibo account and password. If the dynamic password of Alibaba Cloud Security is enabled, the password should be "security password" + "dynamic password of Alibaba Cloud Security ".

In this way, we can successfully submit the code to the Laravel SAE application.

Before you start, you also need to initialize Memcache in SAE and create a new domain name laravel in Storage.

Next, visit http://laravelsae.sinaapp.com/laravelin the browser. The page is shown as below:

Laravel SAE test page

Indicates that the code is successfully deployed!

3. Test database connection


To connect to the database on SAE, first click MySQL on the left to initialize the database:

 


 

Select "shared MySQL ":

 

 

Currently, InnoDB is only developed for enterprises. Therefore, we select the MyISAM engine and click initialize database. After successful initialization, the page will jump to the MySQL management page:

 

 

MySQL host, port, user name, and password in SAE are represented by constants. We also need to use these constants in the code to set the database. Of course Laravel5-on-saeThis project has been set for us, and even configured with read/write splitting:

 

 

Here I will PrefixSet ''That is, no data table prefix is used.

 

Next, we will test the database, or click "Manage MySQL" on the MySQL management page. The page will jump to the MySQL database management page, which is actually a phpMyAdmin page:

 

 

Create a data table in phpMyAdmin. PostsInsert two records:

 

 

In the project codeRoutes. phpAdd a route entry:

Route: get ('database/test', 'dbcontroller @ test ');
Then create the controller DbController and edit the content as follows:

<? Php
Namespace App \ Http \ Controllers;

Use DB;

Class DbController extends Controller {

Public function test (){
$ Posts = DB: table ('posts')-> get ();
Dd ($ posts );
    }

}
Then, submit the code to the SAE project:

Git add.
Git commit-m'test'
Git push sae master: 1
Visit http://laravelsae.sinaapp.com/database/testin the browser. The page is shown as below:

Laravel SAE MySQL database test

Today I wrote this, but I have to mention that the laravel5-on-sae project needs to be improved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.