playerro / yii2-azure-template

A a starting point to easily deploy projects on azure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yii 2 Basic Azure Template

This template eases the process of installing Yii2 Basic template on Azure.

REQUIREMENTS

  • PHP 5.4.0 +
  • Composer

INSTALLATION

  • If you didn't already, install asset plugins
php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
  • Clone the repository
  • The rest is the same as Yii2 basic (migrate, e.t.c)

CONFIGURATION

Entry Script

The entry script /web/index.php was removed to allow for disabling debug modules that don't load on production. Use the following scripts accordingly

Development

Place this script inside /web/index.php

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');

(new yii\web\Application($config))->run();

On Azure

  • Go to the Kodu Debug console of your app (https://.azurewebsites.net/DebugConsole
  • Navigate to the path \home\site\wwwroot\web\ and create an index.php
  • Paste the content below into index.php and save
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');

(new yii\web\Application($config))->run();

Database

For Production

Edit the file config/db.php with real data to match the environment variables with the database credentials

// previous code here . . . 
if(containsAllKeys($_ENV, ['MY_PROJECT_DB_DSN', 'MY_PROJECT_DB_USER', 'MY_PROJECT_DB_PASSWORD'])){
    $dsn = $_ENV['MY_PROJECT_DB_DSN'];
    $username = $_ENV['MY_PROJECT_DB_USER'];
    $password = $_ENV['MY_PROJECT_DB_PASSWORD'];
}
//and so on . . . .

On your web dashboard on the azure portal, go to SETTINGS >> Application Settings and set the
values of 'MY_PROJECT_DB_DSN', 'MY_PROJECT_DB_USER', 'MY_PROJECT_DB_PASSWORD' above accordingly, under App Settings

For Development

You could as well use the approach above (set the environment variables 'MY_PROJECT_DB_DSN', 'MY_PROJECT_DB_USER', 'MY_PROJECT_DB_PASSWORD') or you could create /config/db_local.php and set your development database credentials, such as

return [
    'dsn' => 'mysql:host=localhost;dbname=yii2basic',
    'username' => 'root',
    'password' => '',
];

Azure Portal Configuration

Setting the Directory Root

  • On the web app's portal, go to SETTINGS >> Application Settings
  • Scroll down to 'Virtual applications and directories'
  • Change the physical path to 'site\wwwroot\web' and Save

Dependencies

  • Go to the debug console (https:://.scm.azurewebsites.net/DebugConsole)
  • Change directory on the console to wwwroot
  • Run the following commands
php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
php composer.phar install #will take a while
php composer.phar update #optional to make sure everything works

You might exceed your GitHub rate limit and be asked to obtain a token for the update process

About

A a starting point to easily deploy projects on azure

License:Other


Languages

Language:PHP 88.4%Language:Shell 5.7%Language:CSS 3.8%Language:Batchfile 2.1%