-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Allow for mezzio to be run in a sub directory of the web server #69
Comments
Imho, this is all about webserver configuration. You can work with final class RemoveBasePathMiddleware implements MiddlewareInterface
{
private string $basePath;
public function __construct(string $basePath)
{
$this->basePath = $basePath;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return $handler->handle($this->removeBasePathFromRequest($request));
}
private function removeBasePathFromRequest(ServerRequestInterface $request): ServerRequestInterface
{
$uri = $request->getUri();
return $request->withUri(
$uri->withPath(
(string) \preg_replace(sprintf('!^%s!', $this->basePath), '', $uri->getPath())
)
);
}
} When adding this as the very first entry in your $app->pipe(new RemoveBasePathMiddleware('/laminas-mezzio/app/public')); If this middleware might be something you would like to see provided by mezzio directly, feel free to use my code and create a PR for https://github.com/mezzio/mezzio-helpers 👍🏼 The reason, why this wont work without any "configuration" (either webserver or pipeline) is, that there is absolutely no way to handle endless combinations of directory structures which might occur, so I don't think that this behavior should become a default thing for mezzio. But having a middleware available in the helpers is definitely an option. Oh, and the |
Which can be activate or deactivate during the installation process via the installer and by using mezzio-tooling / laminas-cli. |
@mosbth
You use a local environment for development and there you can follow the first two steps of the quick start guide: This uses PHP's built-in web server and it runs without further configuration on your local machine from every (sub) directory.
…and laminas-mvc. 😃
@boesing has already given important security warning: The vendor directory must not be accessible to the public. |
I've created a feature request in the |
Thanx for the responses! TLDR;
Perhaps this issue is not so trivial one could expect at a first glance, there might be several things to consider, if one want to implement this feature, including the following.
Anyway, there do exists a more simple solution to this feature requests. Here are some background on it. While I was trying out the suggestion on the I did three new installations and I selected the three different routers to try them out with the following result.
The Aura.Router did not support installation in a sub directory, the same with the FastRoute that I used initially. However, the laminas-router did support it and worked out of the box. I tried the following routes where
The following examples are for the url Aura.Router extracts the path like this.
FastRoute extracts the path like this.
The laminas-router extracts the path like this (simplified).
So, to summarize. If I use the laminas-router it will (likely) work in my setup.This router does take the baseurl into account. That is an acceptable solution for me. To my knowledge, the FastRoute only uses the concept of It looks like the Aurora router works on the PSR Request ( |
Hi, I don't recall how laminas is using aura router under the hood. But just to mention the base path is already supported in 3.x . See docs http://auraphp.com/packages/3.x/Router/other-topics.html#3-4-7-3 |
Feature Request
Allow for mezzio to be run in a sub directory of the web server, out of the box, without need of configuration.
Summary
When installing mezzio it does not work, out of the box, when running the website in a sub directory.
I found an article on "Cookbook Using Mezzio from a subdirectory", but that contains a series of actions and configurations.
My humble opinion is that it should work in a sub directory out of the box, like for example the Laravel, Symfony and Yii Framework does. Doing so would make it easier for first come users to adapt the framework since it has less restrictions on the development- and production environment in which it runs.
My reason for this opinion is mainly from an educational perspective. When doing education using Mezzio, one can not always expect the students to have their own servers. We for example are using a shared server where the students publish their websites. This can also be thought of as a usability perspective.
I can not say if this request would interfere with other existing features of mezzio. This was just my first experience of using mezzio. I did not see any notes on this requirement while I was browsing the documentation (however I might have missed it...).
How to repeat
I access the website and gets this.
I then get this response.
The text was updated successfully, but these errors were encountered: