skip to Main Content

I have tried to search for tutorial to move the public folder, but from all the guide it seems like the code is different than version 11. The folder structure I want to move will be like:

  • public (public folder is here)
  • program (all the other files to be stored inside this folder)

I have modified the public/index.php file to be:

<?php

use IlluminateHttpRequest;

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

// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../program/storage/framework/maintenance.php')) {
    require $maintenance;
}

// Register the Composer autoloader...
require __DIR__.'/../program/vendor/autoload.php';

// Bootstrap Laravel and handle the request...
(require_once __DIR__.'/../program/bootstrap/app.php')
    ->handleRequest(Request::capture());

However, when I try to run php artisan serve, I get the error

   SymfonyComponentProcessExceptionRuntimeException

  The provided cwd "C:wamp64wwwmy-projectprogrampublic" does not exist.

What are the things needed to modify to get it works?

2

Answers


  1. You must take care of how you load your project. Laravel has its own functions for path handling.
    If you want change the public Path used by public_path() function as the default app entry. You should register a new path in the AppProvidersAppServiceProvider.php class.

    // edit the register method
    public function register()
    {
        $this->app->bind('path.public', function() {
            return base_path() . '/program/public';
        });
    }
    

    After that, your HTTP entry file will be C:wamp64wwwmy-projectprogrampublicindex.php

    Login or Signup to reply.
  2. To make artisan use a custom public folder, you can edit the artisan script to call the usePublicPath() method on the application object.

    Change these lines:

    $status = (require_once __DIR__.'/bootstrap/app.php')
        ->handleCommand(new ArgvInput);
    

    to:

    $status = (require_once __DIR__.'/bootstrap/app.php')
        ->usePublicPath('/your/public/folder')
        ->handleCommand(new ArgvInput);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search