Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

behnampmdg3's avatar

php artisan serve ErrorException : chdir(): No such file or directory (errno 2)

Hi;

Why do i get this?

The solutions I find suggest to update Kernel and server file.

Does not seem right.

php artisan serve

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

  at /Users/***/codes/goldmembers/vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php:42
    38|      * @throws \Exception
    39|      */
    40|     public function handle()
    41|     {
  > 42|         chdir(public_path());
    43| 
    44|         $this->line("Laravel development server started: <http://{$this->host()}:{$this->port()}>");
    45| 
    46|         passthru($this->serverCommand(), $status);

  Exception trace:

  1   chdir("/Users/***/codes/goldmembers/public_html")
      /Users/***/codes/goldmembers/vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php:42

  2   Illuminate\Foundation\Console\ServeCommand::handle()
      /Users/***/codes/goldmembers/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32
0 likes
13 replies
munazzil's avatar

According to this path,

   chdir(publicPath());

in vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php To change as like below :

   chdir('/');
3 likes
Snapey's avatar

Is it because you have messed with the directory layout in order to try and secure the application on a bad shared host?

behnampmdg3's avatar

@SNAPEY - I uploaded the app to the server but there are no proper instructions on how to do this.

It's recommended to keep .env and everything but the content of public out of public_html on a directory above.

That causes a whole lot of issues like this one.

I did what Munazzil said but now the assets can't be found.

Snapey's avatar

Assuming your host publishes the public_html folder then you put your public folder content in it.

You put everything else ABOVE the public_html folder (ie, in its parent)

If your host does not allow you to store content in the parent of public_html then you have to install in a folder that is at the same level (ie parallel with public_html) and adjust the two require statements in index.php to tell Laravel where to find the framework

(ps. never follow that other persons advice. He is clueless and offers the wrong answer many more times than anything approximately like the right answer. When you see his answer, just keep moving along and never reply to him.)

As an example of bad advice, you should NEVER, EVER alter anything in the vendor folder. Anyone that suggests to do so is a moron.

behnampmdg3's avatar

@SNAPEY - Hi;

It works well on the server and the issue is the local version.

I do updates on the code and I am working with Git to push.

I want to both do this locally and when updates are done, then push.

Thanks

munazzil's avatar

Have you changed the config/app.php 'env' => env('APP_ENV', 'development'), to as like below

     'env' => env('APP_ENV', 'production'),
munazzil's avatar

@behnampmdg3 Just try with below commands

    php artisan cache:clear
    php artisan view:clear

else run composer update with below code

    composer update --no-scripts

Please or to participate in this conversation.