I did some testing at my host provider and I guess I was wrong.
/web will be “non-existent” even from the subdomain.
It probably should work for virtual hosts.
Something like this should work (it seems so in my case):
The composer files are of no use unless you have command line access.
No. You can empty the runtime and the assets folder under “web” (NOT the one under “app”).
Keep the directories, at least for assets you will get “directory not found” if it’s not present.
I transfered all the necessary files and folders on the server app folder which is at the public_html level.
public_html folder contains all the contents of the web folder.
Now I tried to access the subdomin.my-domin.in, then the login page is displayed but not in a correct structure and proper alignment. Most propbably the css, js, and plugins files are not getting linked correctly.
Where should I make the changes now?
Is there any thing needed to change in the config/web.php or the assets file?
Also when I enter correct username and password and click on the Login button, then still the login page is displayed. I have imported the database and also set the host, database name , username, password in the config/db.php
As the structure is
app (This folder contains all the application files and folders except web folder)
public_html
subdomain (subdomain folder contains all the things inside the web folder as shown)
assets
css
js
plugins
index.php
.htaccess
Check what is being published under web/assets. You can remove everything, update and check again.
The web/css is already web accessible (basePath set, should not be copied) .
Check the page source in your browser for the actual paths being used.
Check the browser log, for assets not found?
I have checked the borwser console. There are many css and js files for which 403 error is shown.
Below is the login page code which finds the css, js and plugins files. May be there should I need to change the paths
<?php
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\LoginForm */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.6 -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
<!-- iCheck -->
<link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
<!-- Morris chart -->
<link rel="stylesheet" href="plugins/morris/morris.css">
<!-- jvectormap -->
<link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
<!-- Date Picker -->
<link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
<!-- Daterange picker -->
<link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css">
<!-- bootstrap wysihtml5 - text editor -->
<link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<div class="site-login">
<!--<h1><?= Html::encode($this->title) ?></h1>!-->
<body class="hold-transition login-page">
<div class="login-box">
<h2><?= Html::encode($this->title) ?></h2>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Please fill out the following fields to login:</p>
<?php $form = ActiveForm::begin(['id' => 'login-form', 'layout' => 'horizontal','options' => ['class' => 'disable-submit-buttons','enctype'=>'multipart/form-data'],
'fieldConfig' => [
//'template' => "{label}\n<div class=\"col-sm-5\">{input}</div>\n<div class=\"col-sm-7\">{error}</div>",
'horizontalCssClasses' => [
'label' => 'col-sm-4',
//'offset' => 'col-sm-offset-2',
//'wrapper' => 'col-sm-7',
// 'error' => '',
//'hint' => '',
],
],]);?>
<div class="form-group has-feedback">
<?= $form->field($model, 'username')->textInput(['autofocus' => false]) ?>
</div>
<div class="form-group has-feedback">
<?= $form->field($model, 'password')->passwordInput() ?>
</div>
<div class="row">
</div>
<div class="row">
<div class="col-lg-offset-7 col-lg-4">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary btn-block btn-flat', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
<!-- /.social-auth-links -->
</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<!-- jQuery 2.2.3 -->
<script src="../../plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="../../bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="../../plugins/iCheck/icheck.min.js"></script>
<script>
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
});
</script>
</body>
</html>
There are many files which are not loaded and when clicked on them from browser console 403 error is shown.
For example there is .ico file stored in public_html/subdomain/ which is needed on the title bar to be displayed, but not displayed and if I click on the that file link then 403 error is displayed.
Use this as a test case. Try to put the url in the browsers adress field (sub-domain.domain.ico-file). Still 403? If not check the page (raw) source in the browser for the actual path used.
So far I have hosted the Yii 2 application on the hostinger’s shared hosting server.
Now I have another application same as the previous one. I need to host that as well.
I will create another sub domain. For example the subdomain with the name lwa.
So it would look like
public_html
lwa
I will transfer all the web/ contents inside the lwa folder. Now outside the public_html folder I will transfer all the contents in a folder say app2 other than web folder.
The question I need to ask here is that whether should I transfer the vendor folder as well in app2, or should I use the vendor folder of the previous yii2 application, so that the index.php of the second yii2 application would like as below
<?php
declare(strict_types=1);
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'prod');
require __DIR__ . '/../../app1/vendor/autoload.php'; // link app1 vendor
require __DIR__ . '/../../app1/vendor/yiisoft/yii2/Yii.php'; // link app1 vendor
$config = require __DIR__ . '/../../app2/config/web.php';
(new yii\web\Application($config))->run();
Why I do not want to transfer the vendor folder, because it is the same as the previous yii2 application hosted. It will unnecessary consume the disk space.
In Yii1 it was easy to reuse the framework folder.
In Yii2 I think it’s not recommended to reuse the vendor folder.
Even if it’s doable (I don’t know) there may become differences over time e.g. added components and more, so it’s better to keep them separate e.g. so they can be maintaned locally by composer and uploaded.