nenad-zivkovic/yii2-advanced-template

Problem with shared hosting?

Closed this issue · 7 comments

Hi,

I've developed an application which I have just uploaded to a public shared host - problems I've had there i discussed in this post: http://www.yiiframework.com/forum/index.php/topic/62789-problems-hosting-advanced-improved-template-on-shared-host/page__gopid__277469#entry277469

As a result of this I downloaded a completely fresh install of the advanced template and have uploaded that to another server. The front end now displays fine, but the backend url is just blank ....

I'm sure there's a simple explanation - any ideas? I've just seen that the problem with the backend index.php file relates to the call to _protected/vendor/autoload.php - the same problem as I had originally. This file isnt being loaded - the require statement fails. I see now that the code is calling /home/sites/somedomain.co.uk/public_html/backend/../_protected/vendor/autoload.php - which clearly is wrong !!!! How can I fix that?

Addition: I've changed the backend index.php file to use this 👍

$dir = str_replace('/public_html','',$_SERVER['DOCUMENT_ROOT']);

and then done eg

require($dir.'/_protected/vendor/autoload.php'); to replace require(DIR . '/_protected/vendor/autoload.php');

It seems to be work but is a bit of a hack ! Is there a better way?

Going back to the original site I mentioned in the forum, the problem relates the composer files - please see last comments - any ideas on that?

Many thanks for the template - it's very good!

Hi,

I had everything working on a revised site - with a fresh template install. I was using the composer packages that come with the template.

I then had to install the font awesome package.

Now the front end is not working again - getting a blank screen !!!!! but on viewing the source I get

<!DOCTYPE html>
<html lang="en">
<head>
...
<title>Error (#1)</title>
<![CDATA[YII-BLOCK-HEAD]]></head>
<body id="">
 <![CDATA[YII-BLOCK-BODY-BEGIN]]>

???

You just have to move whole _protected folder outside the web root. then inside index.php and backend/index.php change paths to one level up or so...

Hi,

This is what I have done.

The paths are correct - it's composer that's the problem.

When I did a fresh install of the template everything was ok - with the paths adjusted to the _protected folder being placed outside of the webroot (backend/index.php) and index.php (for the front end).

I then needed to download the font awesome package, which I have to do on my localhost. I then uploaded the files to the vendor directory (under _protected) on the server - and that's when the site breaks. I am currently still able to access the backend (the font awesome package isnt used there) but the front end is blank ... On the YII2 forum I was told

"You can't use composer and then change the location of the 'vendor' directory after installation.
Not only is it unnecessary to upload all the vendor files by FTP, it also breaking in your case.
What you need to do is run composer install on the server after changing the path to _protected/vendor in the composer script."

I'm not an expert using Composer - only used it for the first time using Yii2 so am at a loss here!

Hi,

I was advised on the forum to move the vendor folder out of the site structure - in my case putting it on c:/wamp/vendor and running composer from there - which I've done.

In my index.php file for the front end I changed the paths to reference the vendor folder in this location but this caused more problems with asset publishing ......

Am I doing something wrong here? Has anyone else had the same problems running the template and then moving to a shared host with composer in this way ? There must be an easy solution to this?

You can download this project if you want:
https://jumpshare.com/v/MxbLSbJszoetV3zv5Dtw?b=jAcuI5U4kTY24sdsCMKd

It is just application initialized from improved advanced template. When you unzip the folder you can see that _protected folder is outside the application ( advanced ) folder. They are in same level. If you put them in you wamp www folder, you can run localhost/advanced and localhost/advanced/backend. You can do the same in shared hosting. You can move _protected folder up if you want... outside the www folder... just update the index.php and backend/index.php files. It is that simple. I really do not know how to help you further, it is very simple and it works. Good luck

All that story about Composer is just crap... just do it like I did it. It cant be simpler. Look at advanced/index.php and advanced/backed/index.php files. Everything should be clear to you, it's damn simple. If you move _protected folder outside of www folder you just add /../ at the start of each require.

For example, this line:

require(__DIR__ . '/../_protected/vendor/autoload.php');

will become:

require(__DIR__ . '/../../_protected/vendor/autoload.php');

That is all, really...

Hi,
Many thanks for getting back - it would be good if the Guide gave some more explanation as to how to deal with a shared host and moving the protected folder including vendor outside of the webroot - would save a lot of time ! Many thanks for this - I'll check it out when I can.