I have read the doc from Yii2 official website to deploy yii2 into share host from this : http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html, and about discussion on this : stackoverflow.
So, I decide to use sftp to upload the yii2 folder.
And this is the list of directory in my share host.
access-logs
etc
logs
public_ftp
public_html
ssl
www (this is a link folder to public_html)
You know, because the share host can hold on domains untill 5 domains,
is it possible to upload yii2basic folder into public_html folder ?
So the result like this :
access-logs
etc
logs
public_ftp
public_html
-basic
- bunch of yii folders here
ssl
www (this is a link folder to public_html)
Because now, if I want to access my web, I have to write like this : mydomain.com/basic/public_html/index.php
I need like this :
mydomain.com/index.php
Please guide me.
Yes you can upload it inside the public_html folder but the only problem that I have been facing nowadays with yii2 basic app is the pretty URLs, you can clone or upload entire contents inside the public_html folder, what I did is as follows only the difference is I have a web folder instead of www
directory structure
public_html
assets
commands
config
controller
mail
migrations
models
runtime
tests
vendor
views
web
public_html/.htaccess
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
public_html/web/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
this works but in the URL it shows /web/index.php?r=site/index and as soon as I turn the prettyUrl on in the config file urlManager it would only show default index page and every link I try to open ends up on the home page view although the URL in the address bar is correct and urlManager parses the rules correctly, this is as far as I have gone.
If you don't mind bunch of Yii 2 folders in your root folder just place all basic template folders (except web) and files in the root folder. Then place the content of web folder in the public_html folder.
It should be something like:
access-logs
assets
commands
config
controllers
etc
logs
mail
models
public_ftp
public_html
// here should be the content of web folder of Yii 2 basic app
runtime
ssl
test
views
widgets
Related
I'm using WordPress for my business site and Laravel for Project management application.
Here is my directory structure.
public_html
-mainsite (my WordPress site is in this directory)
-work (Laravel Application is in this directory)
When user visits my primary domain (e.g. www.example.com) I'm redirecting the visitor to www.example.com/mainsite using following .htaccess rules
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/mainsite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mainsite/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ mainsite/index.php [L]
</IfModule>
My project management application which is located in 'work' directory is easily accessible with this URL
www.example.com/work/public
Now I want to allow users to access my project management application with this URL
(I want to remove 'public' from URL)-
www.example.com/work
Could you please help me to resolve this issue?
(It is easy to remove 'public' from URL when Laravel is installed in the root directory and I know how to do that)
This is not a duplicate question and here is the reason-
My Laravel installation is in subdirectory of my root directory and I'm also using different site (a WordPress site) for my base URL
Move Laravel to outside of public_html
Move content of Laravel's public folder to public_html/work
Put the following code in the \App\Providers\AppServiceProvider register():
$this->app->bind('path.public', function() {
return base_path('public_html/work');
});
I have a legacy project on a server where the actual framework is in a folder above the public_html folder. So the directory structure is like this:
domainname.com
app/
framework/
public_html/
index.php
Now I want to place this on our own server. This is an application created by the hosting company. The root folder is default. So now my directory structure is like this:
default/
app/
framework/
public_html/
index.php
Now he's pointing to the default folder instead of the public_html folder. That's the only difference with the old version. So I've added a .htaccess file to the root folder default. The content of this file is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
</IfModule>
In my public_html folder I have a .htaccess file like this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule . index.php [QSA,NS]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule . /index.php [L,QSA,NS]
So when I go to my website it works. But when I click on a link I get: http://domainname.com/public_html/theclickedpage/.
But I don't want the public_html in my url. How can I fix this?
You may want to search for a way to make a virtual host. I know some of my webhost let me configure the vhost through my admin page. It will let your server consider the url without including the specified folder, but back in the stage it performs needed redirection.
You applied correct rule ,
but the problem is link for the solution of this issue you have to
remove public_html from
your all links and it will automatically redirect to your required
path without public_html.
I currently use laravel 5 for web development. And my goal is to upload the website which I made in laravel to a shared host.
But if I upload my files to the public_html folder, I'll have to navigate to mywebsite.com/public/mypage to access a route mypage. Which is not what I want.
I would have just changed the the name of public folder to public_html and then shifted all other folders to the root directory and changed some laravel config options, but that would have made my root directory unclean. So think I would have to use .htaccess for what I want. I am not familiar in using .htaccess, so how would I do this:
If the user enters mywebsite.com/mypage in the browser he gets to see the page mywebsite.com/public/mypage in the browser, but the url in the browser stays the same.
Thanks, in advance.
I also got the same problem when hosting my website in shared hosting godaddy.
I also used laravel5 frameowork and launched the site http://www.hahafunnyjokes.com
Edit the .htaccess file in the root folder where your public_html pointing
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.examplecom/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Thats it, I got my site up and running.
Replace example.com with your website name
I have hosted my new website here http://cvspforcomval.site90.net/ which is a free hosting site. The problem is that I can't see the pictures in my slide, and when I enter to the navigation links I get an error.
I have changed the default webroot/index.php to:
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS.'a3503999');
}
if (!defined('APP_DIR')) {
define('APP_DIR', 'app');
and my directory goes like this
/root/
public_html/ <---webroot
app/
lib/
I'm just wondering if using the free hosting site affects the error. Or I just missed something out.
<---EDITED Added below--->
In my shared hosting site. I have setup folder in this way
/app
/public_html <---webrooot
/lib
I have the default htaccess in my public_html which is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
My suspicious is that i need to change my .htaccess. I haven't solved it yet
i am getting page not found error which is due to the anchors. You are not using proper ctp links.You have to create the anchors as
$this->Html->link(__'My Page',array('controller'=>'Home','action'=>'name_of_action'));
I am sorry about this, but my htdocs root is wrong and I can't change that. So I have to make it work in the /public folder.
I use the normal Laravel .htaccess file with the following rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If I open http://kemtime2_neu.pr.domain.de/public I get redirected to http://kemtime2_neu.pr.domain.de/public/http://kemtime2_neu.pr.domain.de/public/login
How can I fix this?
I would love to make it work from http://kemtime2_neu.pr.domain.de/ but getting it to work with http://kemtime2_neu.pr.domain.de/public/ would be fine.
I use the 3 solution of this post and works fine:
http://web.archive.org/web/20130320184846/http://forums.laravel.io/viewtopic.php?id=1258
Solution 1 - Alternate installation path with symlink.
This is the preferred solution and in general an all-around good idea. It's possible to install your application to a folder unrelated to public_html/ and then symlink the public folder to the public_html/ path.
For example:
Install your application to /home/applications/mysite.com
Imagine that your DocumentRoot points to /var/www/vhosts/mysite.com/httpdocs
Remove the httpdocs folder from the mysite.com vhosts folder then connect the two with a symlink: ln -s /home/applications/mysite.com/public /var/www/vhosts/mysite.com/httpdocs
Solution 2 - .htaccess with mod_rewrite
This solution enables you to drop Laravel into your public folder then use a .htaccess file to redirect requests to the public folder. This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Step 1. Place Laravel in your document root folder.
Step 2. Place the following .htaccess file in your document root folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Step 3. Make sure that you manually set your 'url' configuration in application/config/application.php otherwise Laravel will generate incorrect URLs. Make sure that each of your environments have the correct application.url configuration. For more information on environment-specific configurations see: http://laravel.com/docs/install#environments
Solution 3 - merge the public folder into the installation root
This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Copy the contents of the public/ folder into your Laravel installation folder then change this line in your index.php file from:
require '../paths.php';
to
require 'paths.php';
Keep in mind that any bundles, libraries, or other types of third-party code may not be designed to be publicly accessible.
Note: It's also important to note that your bundles/ and public/bundles/ directories will now conflict. When using this approach you may want to not use artisan's bundle:publish task without knowing exactly what your bundles want to publish.
I solved it partly. If I have a .htaccess in the root instead of /public with
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php/$1 [L]
I can open http://kemtime2_neu.pr.domain.de/login but the images and css is still wrong. I need to check first if the files exist in /public. I think this is a new question.