Search code examples
phplaravelfilepathautoloader

Starting Laravel App


I have seen a lot of similar tutorials and questions to my problem, but none seem to cover what is going on here. Being new to Laravel I'm having some difficulty with the index.php. It looks like the __DIR__ ."path/here" doesn't accept ../ like one would expect. It's appending to the file path instead of moving up directories. As can be seen below in the warning/error:

Warning: require(/home/user1/public_html/blog/../vendor/autoload.php): 
failed to open stream: No such file or directory in 
/home/user1/public_htm/blog/index.php on line 27

Fatal error: require(): Failed opening required 
'/home/user/public_html/blog/../vendor/autoload.php' 
(include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') 
in /home/user1/public_html/blog/index.php on line 27 

I have also tried this, but I don't think that's the problem,

$app->bind('path.public', function ()
{
    return base_path() . '/public_html';
});

It's the directory path that's wrong, but I can't get the right path. Typically I would just ../ as many times as needed, but that won't work here. Any thoughts on how to get my path changed to /home/user1/vendor/autoload.php instead of what it is in the warning and error? Spent too many hours on this now, so any help would be greatly appreciated.

UPDATE

composer install -d /home/user1/ 

Is needed to run globally installed composer. Both install and update have been run and no change was made. The dependencies are not an issue it would seem. At least not with the paths needing a change.


Solution

  • Make sure to make public folder of your Laravel project as ROOT if you are trying to run on server

    Or

    you need to add .htaccess file in your ROOT directory with below syntax.

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [L]
    RewriteRule    (.*) public/$1    [L]
    </IfModule>
    

    Also run below command from your server if allowed

    composer update