0

I'm trying to develop Laravel project on hosting server, but I have a problem with public_html/index.php

Structure of files is:

/laravel/(all laravel files except /public)
/public_html/(all files from laravel /public folder)

File /public_html/index.php (without comments):

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

if (file_exists(__DIR__.'/../laravel/storage/framework/maintenance.php')) {
    require __DIR__.'/../laravel/storage/framework/maintenance.php';
}

require __DIR__.'/../laravel/vendor/autoload.php';

$app = require_once __DIR__.'/../laravel/bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);

And I'm receiving following problem:

Warning: PHP Startup: failed to open stream: No such file or directory in /index.php on line 34

Fatal error: PHP Startup: Failed opening required '//../laravel/vendor/autoload.php' (include_path='.:/:/usr/local/php74/lib/pear') in /index.php on line 34

I'm accessing website by https://my_domain.com.

ouflak
  • 2,458
  • 10
  • 44
  • 49
szymon
  • 51
  • 1
  • 8
  • Why have you put Laravel in `/laravel`? Just put it outside of `public_html` so you only need to change the `public` path: https://stackoverflow.com/questions/67328616/how-to-change-public-folder-to-public-html-in-laravel-8 – M. Eriksson Feb 12 '22 at 20:32
  • I have other files outside ```public_html``` and I want to keep it clean – szymon Feb 12 '22 at 20:34
  • You should check what `__DIR__` actually returns (do a `var_dump(__DIR__)` in your index file) since `//../laravel/vendor/autoload.php` looks very strange. However, that error is on like 34, while in the code you've posted, it's on line 12. Have you removed some code, or do you have it in multiple places? Also make sure that the server allows you to reference files outside of `public_html`. – M. Eriksson Feb 12 '22 at 20:37
  • I'm not sure how to check is server allows to reference outside ```public_html```. How to check that? I removed comments from code. – szymon Feb 12 '22 at 20:41
  • Check what `var_dump(__DIR__);` in your index.php file outputs. If it only gives you `/`, then it seems like you can't. Then you need to contact your hosting company and ask how to solve it. – M. Eriksson Feb 12 '22 at 20:42
  • ```var_dump(__DIR__)``` return ```/```. If hosting company will tell me that it is impossible to reference outside ```public_html```, is any other way to develop laraval's app? – szymon Feb 12 '22 at 20:45
  • If they don't support it, then you should change hosting. When choosing hosting, you should choose one that fits your requirements, not hack your app to fit theirs. – M. Eriksson Feb 12 '22 at 20:47
  • Okey, thanks for help! – szymon Feb 12 '22 at 20:48

0 Answers0