I am using laravel in a project. On my local machine the server I have to access is just
laraveltest.dev
. When I open this URL the project works fine and without problems.
However, when I upload this on a testing server, where the stuff is located in a sub-foder, like this: laraveltest.de/test2/
. The public folder is at laraveltest.de/test2/public/
, but when calling laraveltest.de/test2/public
the application always returns an 404 error.
I thought this might be because of the base path, so I did the following in the bootstrap/app.php
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../') . env('APP_BASE_PATH')
);
where env('APP_BASE_PATH')
is the subfolder.
So app->basePath()
returns /var/www/laraveltest/test2/public
. However, when now opening
laraveltest.de/test2/public
I'm always getting the 404 error and I don't know why. What am I doing wrong?
PHP Laravel\Lumen Application::basePath - 2 examples found. These are the top rated real world PHP examples of Laravel\Lumen\Application::basePath extracted from open source projects. You can rate examples to help us improve the quality of examples.
Lumen is micro-framework based on laravel, lumen have same foundation as laravel and also have many same component. But it is faster and leaner than the full application. Of course, i used Laravel for my major project but prefer lumen and slim framework for my api project that need to be faster.
In a Laravel application, a facade is a class that provides access to an object from the container. The machinery that makes this work is in the Facade class. Laravel's facades, and any custom facades you create, will extend the base Illuminate\Support\Facades\Facade class.
What you want to use is the path helper. The URL helper is for generating HTTP URLs. or the public_path () function in Laravel 4. Show activity on this post.
You don't need to change basePath
, except if you use custom folder application structure. Kinda like this:
bootstrap
├── app.php
└── autoload.php
config
├── app.php
├── auth.php
├── cache.php
├── compile.php
[...]
src
└── Traviola
├── Application.php
├── Commands
│ └── Command.php
├── Console
│ ├── Commands
[...]
So, in your case, all you have to do is:
Check .htaccess configuration. Does server allow .htaccess
file to override specific path configuration?
Check your public/index.php
file. Change this line:
/*
|---------------------
| Run The Application
|---------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$app->run();
// into something like this
$app->run($app['request']);
Hope this helps.
If you wonder how Lumen does not work in subfolder. You may see Laravel\Lumen\Application::getPathInfo()
line 1359
. To make Lumen works in subfolder, change this method, just make a class that extends Laravel\Lumen\Application
.
<?php namespace App;
use Laravel\Lumen\Application as BaseApplication;
class Application extends BaseApplication
{
/**
* Get the current HTTP path info.
*
* @return string
*/
public function getPathInfo()
{
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
return '/'.ltrim(
str_replace(
'?'.$query,
'',
str_replace(
rtrim(
str_replace(
last(explode('/', $_SERVER['PHP_SELF'])),
'',
$_SERVER['SCRIPT_NAME']
),
'/'),
'',
$_SERVER['REQUEST_URI']
)
),
'/');
}
}
Then, in you bootstrap/app.php
, change this:
/*
|------------------------
| Create The Application
|------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new App\Application(
realpath(__DIR__.'/../')
);
After this, you don't need to change public/index.php
file, just let it default:
/*
|---------------------
| Run The Application
|---------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$app->run();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With