Laravel5: chdir (): No such file or directory (errno 2)

I have a problem while deploying a website on laravel 5 on a VPS server, but on a local machine it works fine.

My page http://easyway.vn/ current page appears blank with error

Failed to load resource: the server responded with a status of 500 (Internal server error)

When I ran

php artisan serve --host = 0.0.0.0

I have an error

[ErrorException]
  chdir (): No such file or directory (errno 2)



Server information

OS: Linux 2.6
Server version: Apache / 2.2.29 (Unix)
PHP 5.4.41 (cli) (built: June 4, 2015 13:27:02) Copyright (c) 1997-2014 PHP Zend Engine v2.4.0 Team, Copyright (c) 1998-2014 Zend Technologies

Help me please!

+5


source to share


8 answers


Renaming the shared folder name causes this issue.

Touching the files in the vendor directory is something you can never do.

Here is an alternative way of working that I tested and used on my active project.

Create app / Console / Commands / Serve.php files and set the following content:

<?php

namespace App\Console\Commands;

use Exception;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\ProcessUtils;

class Serve extends Command {
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'serve';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Serve the application on the PHP development server';

    /**
     * Execute the console command.
     *
     * @return void
     *
     * @throws \Exception
     */
    public function fire() {
        chdir('/');

        $host = $this->input->getOption('host');

        $port = $this->input->getOption('port');

        $base = ProcessUtils::escapeArgument($this->laravel->basePath());

        $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));

        $this->info("Laravel development server started on http://{$host}:{$port}/");

        if (defined('HHVM_VERSION')) {
            if (version_compare(HHVM_VERSION, '3.8.0') >= 0) {
                passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php");
            } else {
                throw new Exception("HHVM built-in server requires HHVM >= 3.8.0.");
            }
        } else {
            passthru("{$binary} -S {$host}:{$port} {$base}/server.php");
        }
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions() {
        return [
            ['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', 'localhost'],

            ['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 8000],
        ];
    }
}

      

Update the app / Console / Kernel.php file with the following content:



<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel {
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        // Commands\Inspire::class,
        Commands\Serve::class,
    ];

    /**
     * Define the application command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule) {
        // $schedule->command('inspire')
        //  ->hourly();
    }
}

      

All this!

Now run the feed command:

$ php artisan serve

      

Server started:

Laravel development server started on http://localhost:8000/

      

+13


source


this means your Laravel application cannot find the shared folder.

I got it to work

changes:

chdir($this->laravel->publicPath());

      



in:

vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php

To whom:

chdir('/');

      

+12


source


  • Step one To vendor /laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php
`chdir($this->laravel->publicPath());`

      

change to 

      

chdir('/');

2. Step two Modify these two paths in your_public_folder / index.php

require __DIR__.'/../your_app/bootstrap/autoload.php';

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

3. Step Three Change the public path in your_app / server.php file

    if ($uri !== '/' && file_exists(__DIR__.'/../public_html/'.$uri)) {
    return false;
}

require_once __DIR__.'/../public_html/index.php';

      

Note . Change this path to match the structure of your new application folder.

+5


source


+ Change

ChDir (public_path ());

to

ChDir ('/');

From: provider /laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php

+5


source


this error appears when renaming a folder public

.

Never edit files in the vendor folder. After updating composer or fresh installation, you will lose your changes.

The best solution is to edit bootstrap / app.php and put this snippet before the return statement.

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

      

+2


source


go to server.php in root folder and rename public

toany name you have

+1


source


Usually when this type of error occurs, it means that Laravel is looking for a shared folder and it cannot be found. It depends on how you configured the application and using the php artisan service --host=0.0.0.0

will not work in this case. The best way to handle this is to host the app on your server (htdocs) and access it in your url.

The vendor directory contains your dependencies in Composer. For more information visit Laravel Documentation . Never edit anything in the vendor because it can cause problems when updating composer.

+1


source


I know you asked this question a very long time ago, but for anyone looking for the easiest and most efficient way to solve this problem:

This error means laravel cannot find the public folder. You have to add this piece of code to the Providers / AppServiceProvider.php registration method :

public function register()
{
        $this->app->bind('path.public', function() {
          return base_path('PATH TO PUBLIC FOLDER');
        });
}

      

This way laravel knows where to look for the shared folder path.

0


source







All Articles