Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
systems:yii2:setup_and_configuration [2018/05/03 16:31]
smayr [Initial Configuration]
systems:yii2:setup_and_configuration [2020/05/20 16:22] (current)
ajdavis [Upgrade Yii]
Line 121: Line 121:
 </code> </code>
  
-Rename ''bower'' references to ''bower-asset''.  In ''@app\vendor\yiisoft\yii2\base\Application.php'':+Yii2 expects Bower and NPM packages to be installed to vendor/bower and vendor/npm folders respectively. So, to use asset-packagist it's necessary to add aliases in web.php: 
 <code php> <code php>
-//... +$config = [ 
-public function setVendorPath($path) +    ... 
-{ +    'aliases=[ 
-    $this->_vendorPath = Yii::getAlias($path); +        '@bower' => '@vendor/bower-asset', 
-    Yii::setAlias('@vendor', $this->_vendorPath); +        '@npm'   => '@vendor/npm-asset'
-    Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower-asset');  // rename bower to bower-asset +    ], 
-    Yii::setAlias('@npm', $this->_vendorPath . DIRECTORY_SEPARATOR . 'npm'); +    ... 
-}+];
 </code> </code>
 == Initial Configuration == == Initial Configuration ==
Line 144: Line 145:
   * ''params.php'' would need ''params-local.php''   * ''params.php'' would need ''params-local.php''
   * ''web.php'' would need ''web-local.php''   * ''web.php'' would need ''web-local.php''
 +
 +The local versions would be empty, but you can add parameters to override the respective settings:
 +<code php>
 +<?php
 +return [
 +];
 +</code>
  
 For basic app only: Edit the following to support local copies. For basic app only: Edit the following to support local copies.
Line 190: Line 198:
 </code> </code>
  
 +==== Database Config ====
 Edit the following configuration files. Edit the following configuration files.
  
Line 204: Line 213:
 </code> </code>
  
 +==== Params Config ====
 ''/[app]/config/params.php'' or ''/[app]/common/config/params.php'' ''/[app]/config/params.php'' or ''/[app]/common/config/params.php''
 <code php> <code php>
Line 226: Line 236:
     'urlSocialTwitter'              => 'https://twitter.com/acme',     'urlSocialTwitter'              => 'https://twitter.com/acme',
     'user.passwordResetTokenExpire' => 3600,     'user.passwordResetTokenExpire' => 3600,
-    'isSignupApprovalRequired'      => false,+    'isSignupApprovalRequired'      => false, // allows user to signup and login right away 
 +    //'isSignupApprovalRequired'    => true,  // requires sending email to admin to request signup approval 
 +    'timezone'                      => 'America/New_York',  // Must be a valid PHP timezone.  See: http://php.net/manual/en/timezones.php
     'siteLayout'                    => 'default',  // ['full', 'default_white', 'default_gray', 'default']     'siteLayout'                    => 'default',  // ['full', 'default_white', 'default_gray', 'default']
     'authorizenetAPILoginId'        => "YOURLOGIN",     'authorizenetAPILoginId'        => "YOURLOGIN",
Line 232: Line 244:
     'authorizenetTestMode'          => true,     'authorizenetTestMode'          => true,
     'authorizenetSandbox'           => true,     'authorizenetSandbox'           => true,
 +    
 +    //-----------------------------------
 +    // Site Message of the Day (MOTD)
 +    //-----------------------------------
 +    // --- Hurricane mesg ---
 +    //'appMOTD'                       => '<div class="col-md-6">
 +    //    <h3>NOTE<h3> Due to a hurricane hitting our area, 
 +    //    the office will be closed  We apologize for the inconvenience. </div>
 +    //    <div class="col-md-6">
 +    //    <h3>NOTA</h3> Debido al huracán afectando nuestra área, la oficina estará cerrada.  
 +    //    Nuestras disculpas por este inconveniente.</div>',  
 +    //  --- Phone Line Down message ---
 +    //'appMOTD'                       => '<h3>NOTE</h3> Our phone lines are not available due 
 +    //    to a nationwide phone provider outage.  We apologize for the inconvenience.', 
 +    //  --- Memorial Day message ---
 +    //'appMOTD'                        => '<h3>Memorial Day Closure</h3> Our offices will be 
 +    //    closed in observance of the Memorial Day holiday. We will resume normal hours on Monday. ',
 +    //  --- US Independence/4th July message
 +    //'appMOTD'                        => '<h3>US Independence Day Closure</h3> Our offices 
 +    //  will be closed July 4, in observance of the US Independence Day holiday. 
 +    //  We will resume normal hours on July 5. ',  // site Message of the Day
 +    //  --- Labor Day message ---
 +    //'appMOTD'                        => '<h3>Labor Day Closure</h3> Our offices will be 
 +    //   closed in observance of the Labor Day holiday. We will resume normal hours on Tuesday. ',
 +    //  --- Thanksgiving message ---
 +    //'appMOTD'                        => '<h3>Thanksgiving Holiday</h3> Due to the 
 +    //  Thanksgiving Day holiday, the office will be closed.  We apologize for the inconvenience. <br/>
 +    //  Debido a la celebración del Día de Acción de Gracias, la oficina estará cerrada. 
 +    //  Nuestras disculpas por cualquier molestia.',  // site Message of the Day
 +    //  --- Xmas/NewYear message ---
 +    //'appMOTD'                        => '<h3>Christmas / New Year Holiday Closure</h3> 
 +    //  Our offices will be closed December 25, and January 1, in observance of the Christmas 
 +    //  and New Year holidays. We will resume normal hours the next day. Happy Holidays!', 
 +    //  --- NewYear message ---
 +    //'appMOTD'                        => '<h3>New Year Holiday Closure</h3> Our offices will be 
 +    // closed January 1, in observance of the New Year holidays. We will resume normal hours 
 +    // the next day. Happy Holidays!',  // site Message of the Day
 +    
 +    // Test Site
 +    //'appMOTD'                       => '<h3>TEST SITE</h3> This site is for testing only.', 
 +    
 +    // --- MOTD Date Range (comment lines to display permanently) ---
 +    //'appMOTDStartDate'              => '2017-09-07',  // Start date (YYYY-MM-DD)
 +    //'appMOTDStopDate'               => '2017-09-11',  // Stop date (YYYY-MM-DD)
 ]; ];
 </code> </code>
  
 +==== Main/Web Config ====
 ''/frontend/config/main-local.php'' and ''/backend/config/main-local.php'' (advanced), or ''/[app]/config/web.php'' (basic) ''/frontend/config/main-local.php'' and ''/backend/config/main-local.php'' (advanced), or ''/[app]/config/web.php'' (basic)
 <code php> <code php>
Line 248: Line 305:
             // Preferably, add to local config:             // Preferably, add to local config:
             // $config['components']['request']['cookieValidationKey'] = 'my@s3cr3tk3y_myapp';             // $config['components']['request']['cookieValidationKey'] = 'my@s3cr3tk3y_myapp';
-            'cookieValidationKey' => 'my secret key goes here (or in web-local.php or main-local.php)_' . $params['appNameShort'],+            'cookieValidationKey' => 'my secret key goes here (or in web-local.php or main-local.php)_' . $params['appId'],
                          
             // Use a custom name per app for csrf cookie to avoid clashes with other Yii apps             // Use a custom name per app for csrf cookie to avoid clashes with other Yii apps
-            'csrfParam' => 'csrf_' . $params['appNameShort'],+            'csrfParam' => 'csrf_' . $params['appId'],
             'csrfCookie' => [             'csrfCookie' => [
                 'httpOnly' => true,                 'httpOnly' => true,
Line 277: Line 334:
             'enableAutoLogin' => true,             'enableAutoLogin' => true,
             'identityCookie'  => [             'identityCookie'  => [
-                'name' => $params['appNameShort'] . '_User', // unique for app+                'name' => $params['appId'] . '_User', // unique for app
                 //'path' => '/backend/web'  // correct path for the app web folder.                 //'path' => '/backend/web'  // correct path for the app web folder.
             ],             ],
         ],         ],
         'session' => [         'session' => [
-            'name'     => $params['appNameShort'] . '_SessionId', // unique for app+            'name'     => $params['appId'] . '_SessionId', // unique for app
             'savePath' => __DIR__ . '/../runtime', // a temporary folder for app             'savePath' => __DIR__ . '/../runtime', // a temporary folder for app
         ],         ],
Line 316: Line 373:
 </code> </code>
  
 +==== htaccess File ====
 <WRAP round tip> <WRAP round tip>
 For ''urlManager'' component to work correctly using PrettyUrls, you must do this: For ''urlManager'' component to work correctly using PrettyUrls, you must do this:
Line 328: Line 386:
  
 # HTTPS redirect for pages users input sensitive data (eg. password) # HTTPS redirect for pages users input sensitive data (eg. password)
 +# NOTE: Disable these in localhost or other server without HTTPS.
 #RewriteCond %{HTTPS} off #RewriteCond %{HTTPS} off
 #RewriteCond %{REQUEST_URI} /(login) [NC] #RewriteCond %{REQUEST_URI} /(login) [NC]
Line 340: Line 399:
 </code> </code>
  
 +==== System Variables ====
 Setup application name in ''[app]/vendor/yiisoft/yii2/base/Application.php'': Setup application name in ''[app]/vendor/yiisoft/yii2/base/Application.php'':
 <code php> <code php>
Line 348: Line 408:
 </code> </code>
  
 +==== Debugging ====
 Yii2-debug module needs permission to trace and log in case application is installed on a server other than ''localhost'' Edit file ''[app]/vendor/yiisoft/yii2-debug/Module.php'': Yii2-debug module needs permission to trace and log in case application is installed on a server other than ''localhost'' Edit file ''[app]/vendor/yiisoft/yii2-debug/Module.php'':
 <code php> <code php>
Line 384: Line 445:
 Main template: Edit ''/app/views/layouts/main.php'': Main template: Edit ''/app/views/layouts/main.php'':
 <code php> <code php>
 +<head>
 +  ...
 +  <link rel="shortcut icon" href="<?= Yii::$app->homeUrl; ?>favicon.ico" type="image/x-icon" />
 +</head>
 ... ...
   <?php   <?php
Line 554: Line 619:
     'request' => [     'request' => [
         // Use a custom name per app for csrf cookie to avoid clashes with other Yii apps         // Use a custom name per app for csrf cookie to avoid clashes with other Yii apps
-        'csrfParam' => '_csrf-backend_' . $params['appNameShort'],+        'csrfParam' => '_csrf-backend_' . $params['appId'],
         'csrfCookie' => [         'csrfCookie' => [
             'httpOnly' => true,             'httpOnly' => true,
Line 649: Line 714:
   * Backend: http://admin.example.com    * Backend: http://admin.example.com 
  
-== Rewrite Base URL /frontend/web ==+== Rewrite Base URL (/basic/web or /frontend/web==
 References:  References: 
-  * [[http://git.yiisoft.com/wiki/755/how-to-hide-frontend-web-in-url-addresses-on-apache/|Hide Frontend web in URL]] 
   * [[http://mrcoles.com/blog/simple-way-understand-mod-rewrite/|Simple mod_rewrite]]   * [[http://mrcoles.com/blog/simple-way-understand-mod-rewrite/|Simple mod_rewrite]]
   * [[http://vadimg.com/2009/08/mod_rewrite-tips-and-tricks-are-lot-of-htaccess-rewrite-examples/|mod_rewrite Tips and Trips]]   * [[http://vadimg.com/2009/08/mod_rewrite-tips-and-tricks-are-lot-of-htaccess-rewrite-examples/|mod_rewrite Tips and Trips]]
Line 657: Line 721:
   * [[https://httpd.apache.org/docs/2.4/rewrite/intro.html|Apache 2.4 mod_rewrite Introduction]]   * [[https://httpd.apache.org/docs/2.4/rewrite/intro.html|Apache 2.4 mod_rewrite Introduction]]
   * [[https://httpd.apache.org/docs/2.4/rewrite/flags.html|Apache 2.4 mod_rewrite Flags]]   * [[https://httpd.apache.org/docs/2.4/rewrite/flags.html|Apache 2.4 mod_rewrite Flags]]
 +  * [[https://mod-rewrite-cheatsheet.com|mod_rewrite Cheat Sheet]]
   * [[http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html|mod_rewrite Variables Cheatsheet]]   * [[http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html|mod_rewrite Variables Cheatsheet]]
   * [[https://qualysguard.qualys.com/qwebhelp/fo_help/module_pc/policies/regular_expression_symbols.htm|Regex Symbols]]   * [[https://qualysguard.qualys.com/qwebhelp/fo_help/module_pc/policies/regular_expression_symbols.htm|Regex Symbols]]
   * [[http://aaronfrancis.com/blog/2014/1/9/hosting-an-advanced-yii2-application-on-heroku|Hosting Advanced Yii2 App]]   * [[http://aaronfrancis.com/blog/2014/1/9/hosting-an-advanced-yii2-application-on-heroku|Hosting Advanced Yii2 App]]
 +
 === Basic App === === Basic App ===
 Create ''.htaccess'' file in ''[yiiroot]'' folder: Create ''.htaccess'' file in ''[yiiroot]'' folder:
Line 679: Line 745:
   RewriteCond %{REQUEST_FILENAME} !-f   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d   RewriteCond %{REQUEST_FILENAME} !-d
-  RewriteRule . /web/index.php +  #RewriteRule . /web/index.php  
 +  RewriteRule . index.php 
 </IfModule> </IfModule>
  
Line 690: Line 757:
 # Deny accessing dot files # Deny accessing dot files
 RewriteRule (^\.|/\.) - [F] RewriteRule (^\.|/\.) - [F]
- 
 </code> </code>
  
Line 704: Line 770:
 </code> </code>
  
-Edit ''[yiiroot]/config/web.php'' file to include the following:+Hide the ''web'' folder.  Edit ''[yiiroot]/config/web.php'' file to include the following:
 <code php> <code php>
 <?php <?php
Line 711: Line 777:
 use \yii\web\Request; use \yii\web\Request;
  
-// Use current location as root, i.e. '/web' becomes '/' +// Set current location to be root directory, i.e. '/web' becomes '/' 
-// The Rewrite procedure to send traffic to '/' if files are in '/var/www/html'+// Mod_Rewrite procedure will send traffic to '/' if files are in '/var/www/html'
 $baseUrl = str_replace('/web', '', (new \yii\web\Request)->getBaseUrl()); $baseUrl = str_replace('/web', '', (new \yii\web\Request)->getBaseUrl());
    
 return [ return [
-    'id' => 'app-frontend', +    //...
-    ...+
    
     'components' => [     'components' => [
-        // Define request. Must have a baseUrl specified 
         'request' => [         'request' => [
-            'baseUrl'   => $baseUrl,+            // Define request. Must have a baseUrl specified. 
 +            // Required if wanting to hide 'web' folder from url. 
 +            'baseUrl' => $baseUrl, 
 +             
 +            //...
         ],         ],
-        // Define urlManager. Must have baseUrl specified+        // Activate urlManager. Must have baseUrl specified.
         'urlManager' => [         'urlManager' => [
             'baseUrl'         => $baseUrl,             'baseUrl'         => $baseUrl,
Line 732: Line 800:
         ],         ],
    
-        ...+        //...
     ],     ],
     'params' => $params,     'params' => $params,
Line 873: Line 941:
             'enableAutoLogin' => true,             'enableAutoLogin' => true,
             'identityCookie' => [             'identityCookie' => [
-                'name' => '_backendUser', // unique for backend+                'name' => $params['appId'] . '_backendUser', // unique for backend
                 //'path'=>'/backend/web'  // correct path for the backend app.                 //'path'=>'/backend/web'  // correct path for the backend app.
             ]             ]
         ],         ],
         'session' => [         'session' => [
-            'name' => '_backendSessionId', // unique for backend+            'name' => $params['appId'] . '_backendSessionId', // unique for backend
             'savePath' => __DIR__ . '/../runtime', // a temporary folder on backend             'savePath' => __DIR__ . '/../runtime', // a temporary folder on backend
         ],         ],
Line 895: Line 963:
             'enableAutoLogin' => true,             'enableAutoLogin' => true,
             'identityCookie' => [             'identityCookie' => [
-                'name' => '_frontendUser', // unique for frontend+                'name' => $params['appId'] . '_frontendUser', // unique for frontend
                 //'path'=>'/frontend/web'  // correct path for the frontend app.                 //'path'=>'/frontend/web'  // correct path for the frontend app.
             ]             ]
         ],         ],
         'session' => [         'session' => [
-            'name' => '_frontendSessionId', // unique for frontend+            'name' => $params['appId'] . '_frontendSessionId', // unique for frontend
             'savePath' => __DIR__ . '/../runtime', // a temporary folder on frontend             'savePath' => __DIR__ . '/../runtime', // a temporary folder on frontend
         ],         ],