Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
systems:yii2:setup_and_configuration [2018/05/04 09:17] smayr [Shared Hosting] |
systems:yii2:setup_and_configuration [2020/05/20 16:22] (current) ajdavis [Upgrade Yii] |
</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 == |
| |
# 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] |
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 |
* 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]] |
* [[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: |
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> |
| |
# Deny accessing dot files | # Deny accessing dot files |
RewriteRule (^\.|/\.) - [F] | RewriteRule (^\.|/\.) - [F] |
| |
</code> | </code> |
| |
</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 |
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 a baseUrl specified | // Activate urlManager. Must have baseUrl specified. |
'urlManager' => [ | 'urlManager' => [ |
'baseUrl' => $baseUrl, | 'baseUrl' => $baseUrl, |
], | ], |
| |
... | //... |
], | ], |
'params' => $params, | 'params' => $params, |
'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 |
], | ], |
'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 |
], | ], |