skip to Main Content

I have been working on deploying my Laravel app on a shared hosting using cpanel. However, I an getting this error:

[08-Sep-2018 07:38:43 UTC] PHP Fatal error:  require(): Failed opening required '/home/daankraa/public_html/../../supersax/vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /home/daankraa/public_html/index.php on line 24

From what I can see here is that it doesn’t want to switch to the root directory, but keeps looking for:

/home/daankraa/public_html/../../supersax/vendor/autoload.php in public_html.

I have tried the dots to move up a directory, but it doesn’t want to. How can I fix this?

Thanks in advance!

Daan

4

Answers


  1. 1) Copy
    .htaccess from public folder to root

    2)
    rename server.php to index.php

    server.php file would be in root

    Simple 🙂

    Login or Signup to reply.
  2. Move you all content from public to root directory and index.php file of public folder modified according like:

        require __DIR__.'/vendor/autoload.php';
    
        $app = require_once __DIR__.'/bootstrap/app.php';
    
    Login or Signup to reply.
  3. index.php

    <?php
    
    /**
     * Laravel - A PHP Framework For Web Artisans
     *
     * @package  Laravel
     * @author   Taylor Otwell <[email protected]>
     */
    
    $uri = urldecode(
        parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
    );
    
    // This file allows us to emulate Apache's "mod_rewrite" functionality from the
    // built-in PHP web server. This provides a convenient way to test a Laravel
    // application without having installed a "real" web server software here.
    if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
        return false;
    }
    
    require_once __DIR__.'/public/index.php';
    
    Login or Signup to reply.
  4. Here is a very simple method that worked for for me:

    1. create a .htaccess file in the public_html folder (the file is same level with .env file)

    2. copy and paste the following code in the .htaccess file

       <IfModule mod_rewrite.c>
         <IfModule mod_negotiation.c>
             Options -MultiViews -Indexes
         </IfModule>
       RewriteEngine on
       # serve existing files in the /public folder as if they were in /
       RewriteCond %{DOCUMENT_ROOT}public%{REQUEST_URI} -f
       RewriteRule (.+) /public/$1 [L]
       # route everything else to /public/index.php
       RewriteRule ^ /public/index.php [L]
       </IfModule>
      
    3. Save the file. That’s All you can now visit your site http://www.example.com

    Note: for some reason if it does not work the your document root might be different the you will have to use the full path to the public folder you will replace: {DOCUMENT_ROOT} with the full path /var/www/example.com/web, you can get the full path by creating a file in the public folder of laravel called get_doc_root.php and inside of that file paste the code

    <?php
    echo getcwd();
    

    the you can see your path by going to http://www.example.com/public/get_doc_root.php after getting the path just copy it and replace {DOCUMENT_ROOT} in your .htaccess created.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search