Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App doesn't work from subfolder #11

Closed
alexkart opened this issue Jul 19, 2019 · 10 comments
Closed

App doesn't work from subfolder #11

alexkart opened this issue Jul 19, 2019 · 10 comments
Labels

Comments

@alexkart
Copy link

@alexkart alexkart commented Jul 19, 2019

The documentation says

The application installed according to the above instructions should work out of the box with either an Apache HTTP server or an Nginx HTTP server

What steps will reproduce the problem?

Steps from the guide (https://github.com/yiisoft/docs/blob/master/guide/en/start/installation.md):

cd /var/www/html
composer create-project --prefer-dist --stability=dev yiisoft/yii-demo yii3-app

Apache virtualhost DocumentRoot is /var/www/html

Go to http://server-name.test/yii3-app/public/

You will see We were unable to find the page /yii3-app/public/.

What is the expected result?

Work out of the box

What do you get instead?

We were unable to find the page /yii3-app/public/.

Additional info

If a separate virtual host is configured for the app as explained further in the documentation it works as expected.

Q A
Version dev
PHP version 7.3
Operating system Ubuntu 18.04
@alexkart alexkart changed the title App don't work from subfolder App doesn't work from subfolder Jul 19, 2019
@samdark

This comment has been minimized.

Copy link
Member

@samdark samdark commented Jul 19, 2019

Is it typical to run the app via subfolder?

@alexkart

This comment has been minimized.

Copy link
Author

@alexkart alexkart commented Jul 19, 2019

In productions, of course not, but for testing and development purposes (like it's said in the docs "if you are just-test driving Yii") maybe yes.
I don't know what was the design decision and whether it is a bug or not. If it's correct behavior, so the documentation needs to be adjusted. "The application installed according to the above instructions should work out of the box" phrase should be removed or moved after "Configuring Web Servers" section and it should be mentioned that configuring a separate virtual host for the app is necessary (now it's said that it's optional).

@samdark

This comment has been minimized.

Copy link
Member

@samdark samdark commented Jul 19, 2019

Well, since Yii 2 worked well with this setup, I think we can consider it being a bug.

@samdark samdark added the help wanted label Aug 29, 2019
@samdark samdark pinned this issue Aug 29, 2019
@SOHELAHMED7

This comment has been minimized.

Copy link

@SOHELAHMED7 SOHELAHMED7 commented Oct 31, 2019

I tried to fix this issue but found that third arg in https://github.com/yiisoft/yii-demo/blob/master/src/Factory/MiddlewareDispatcherFactory.php#L22 is not present and hence

https://github.com/yiisoft/yii-web/blob/master/src/MiddlewareDispatcher.php#L51 will always set to NotFoundHandler

and also https://github.com/yiisoft/yii-web/blob/master/src/MiddlewareDispatcher.php#L72 will always be true when all middleware are added.

As the docs and framework is in WIP state, I was not able to completely fix the issue but my thought are (that might be incorrect):

@samdark

This comment has been minimized.

Copy link
Member

@samdark samdark commented Oct 31, 2019

third arg in https://github.com/yiisoft/yii-demo/blob/master/src/Factory/MiddlewareDispatcherFactory.php#L22 is not present and hence

https://github.com/yiisoft/yii-web/blob/master/src/MiddlewareDispatcher.php#L51 will always set to NotFoundHandler

That's intended. We don't want to change this default.

https://github.com/yiisoft/yii-web/blob/master/src/MiddlewareDispatcher.php#L72 will always be true when all middleware are added.

If you mean "processed", not "added" then it's true and it's intended. If you mean "added" then no, it will be false until all middlware are processed.

I was not able to completely fix the issue but my thought are (that might be incorrect)

So it helped in your case? If so, that's very interesting because I don't see how not working from a sub-directory is connected to middleware stack processing and default handler that is executed when there are no middleware left to process.

@SOHELAHMED7

This comment has been minimized.

Copy link

@SOHELAHMED7 SOHELAHMED7 commented Oct 31, 2019

So it helped in your case?

Sorry. I am unable to understand what are you trying to ask. Can you please elaborate?

If so, that's very interesting because I don't see how not working from a sub-directory is connected to middleware stack processing and default handler that is executed when there are no middleware left to process.

that is exactly I am confused about. Initially I thought it's the apache issue. But later found that https://github.com/yiisoft/yii-web/blob/master/src/NotFoundHandler.php#L35 send the 404 response

Question: Once all middleware are added a response should be sent but why in this case https://github.com/yiisoft/yii-web/blob/master/src/NotFoundHandler.php#L31 404 is sent?

@samdark

This comment has been minimized.

Copy link
Member

@samdark samdark commented Oct 31, 2019

Sorry. I am unable to understand what are you trying to ask. Can you please elaborate?

Sure. I've meant to ask if you have tried to fix these two things you are pointing to and if yes, did it result in an application working from sub-directory?

@SOHELAHMED7

This comment has been minimized.

Copy link

@SOHELAHMED7 SOHELAHMED7 commented Oct 31, 2019

I tried both

For 1st one :

Add 3rd argument to https://github.com/yiisoft/yii-demo/blob/master/src/Factory/MiddlewareDispatcherFactory.php#L22

I got no relavant class which I can put as third agr

I did find/search

implements(.*)RequestHandlerInterface using regex in Sublime text

in entire folder including vendor dir, but didn't get relavant class. Somewhat relavant stuff found is

vendor/yiisoft/yii-web/src/Middleware/Chain.php:
   35      private function wrap(MiddlewareInterface $middleware, RequestHandlerInterface $handler): RequestHandlerInterface
   36      {
   37:         return new class($middleware, $handler) implements RequestHandlerInterface {
   38              private $middleware;
   39              private $handler;

For 2nd one :

Change the logic of isLastMiddlewareCalled

got no success

tried few ways (trial and error)
instead got

php error about too many recurring/nested function calls (something about max limit is 256) in one of the attempt

@samdark

This comment has been minimized.

Copy link
Member

@samdark samdark commented Oct 31, 2019

OK. These two are very unlikely the reason for this issue.

@samdark

This comment has been minimized.

Copy link
Member

@samdark samdark commented Nov 28, 2019

@roxblnfk is on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.