I think you donât. If you copy exact whole project with vendor folder it should work. However it will be much easier to manage it with composer in the future.
Aw Jeez!.. Might I suggest, uploading your web application in a folder not within the âpubic_htmlâ folderâŚ
BUT separate from the âpubic_htmlâ folder entirely. The âwebâ folder from your web application will become the âpubic_htmlâ folder by copying that data into the âpubic_htmlâ and redirecting the index.php to wherever you put the web application, for example âyii2-appâ folder.
So the directory to your web application would be:
â/shared_host/yii2_app/â
You should never expose the app root folder in public, eg. as public_html. Itâs extremely dangerous.
So on the server, we need to transfer the basic folder in the public_html folder
No. If your app is based on basic Yii template, your public folder should be basic/web and it should be the one and only visible from the outside.
Analyze @ricksmort example config, it is a good way to go.
So all the contents from web folder (which is inside the basic folder of localserver) should be transferred to the public_html or only index.php?
When we login to the cpanel of any other hosting panel and click on the File Manager, then we see only public_html. So should I create a new folder say yii2-app and put all the files and folder other than web inside it?
If we transefer all the contents of the web folder inside the public_html, then will it cause any issue for the js files, css which we use in the application?
Can you tell why it is not good to tranfer all the files of the basic folder into the public_html?
If we transefer the basic folder into the public_html and if we use the .htaccess file inside the web folder and the basic folder with the following code, will it still cause security issues?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Options -Indexes
This is my file manager⌠My yii2 web application isnât in the public_html folder, expect for the âwebâ folder⌠The âwebâ folder is the âpublic_htmlâ folder.
I use the code for index.php that I posted up top and this for my .htaccess file that is in the âpublic_htmlâ folder.
##################################################
## Shared webhosting
# @url https://www.yiiframework.com/doc/guide/2.0/en/tutorial-shared-hosting#add-extras-for-webserver
#
<IfModule mod_rewrite.c>
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
What if I want to host the application on the subdomain?
As web folder contains js and css folders with their files, which is getting accessed in the application. So if we move the web folder only in the public_html and rest all other outside the public_html, all the js files, css files and plugins files which are being accessed in the application will work correctly or whether I need to make some more changes or settings in the application configuration or any other code files?
We will be using Hostinger.in shared hosting server. So when we create a subdomain what are the necessary steps that need to make. The subdomain folder will get created in the public_html?
We will create a subdomain like sub-domain.my-domain.in
So whenever user tries to visit www.my-domain.in then they should see Access fobidden messag and whenever the user tries to visit sub-domain.my-domain.in then our yii2 application should be started.
Check using ftp if you can create a subdir under my-domain (one level above public_html)
You can have a web directory and a parallel directory for the protected files
Then try creating the sub-domain (try using âCustom folder for subdomainâ )
To create a subdomain, open Websites â Manage, search for Subdomains on the sidebar and click on it:
You may need to store the content of âwebâ in âsub-domainâ
Modify paths in index.php accordingly
(I would start with simple html scripts to try it out)
Ok thank you. So the sub-domain folder will get created in the public_html folder.
So i need to move the web folder contents in the public_html/sub-domain/
Do I need to create a folder outside the public_html with the name sub-domain and move all the application files except web folder inside it?
Now I need to change the path in the index.php of the web folder inside the public_html/sub-domain/ to point to the sub-domain folder outside the public_html
Question
Will it affect the js, css files and any other files in the application?
because in the assets folder, I have the file Asset.php which links the js, css, plugins files which are in the web folder.
Will I need to change that as well?
<?php
namespace app\assets;
use yii\web\AssetBundle;
class DashboardAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/bootstrap.min.css',
];
public $js = [
'plugins/raphael/raphael.min.js',
'js/popupmodal.js',
'js/result.js',
];
}
Also do i need to change the paths in the config/web.php
(Perhaps there is a file manager you can use from the control panel)
I think most questions are already answered.
If itâs not possible to do what I quoted above, all the files will be placed under public_html.
On the other hand, if itâs possible, point the subdomain to âŚ/âŚ/my-domain/web and change the paths in index.php to âŚ/âŚ/my-domain/somefolder (e.g. âŚ/somefolder)
You can see online in the control panel what âŚ/âŚ/ will be.
If itâs only possible to have subdomain under public_html move the âwebâ directory there and point the subdomain to it, keep the rest of the files one level above (âŚ/âŚ/somefolder)
Then add âRedirectMatch 404 /webâ to .htaccess in public_html
I think you can also create âsomefolderâ under public_html and add a RedirectMatch.
Files should still be accessable from php.
I donât know if this solution guarantee security in all situations.