Can I safely move the composer-generated Laravel project to a different directory?

I accidentally installed my Laravel project in user/name

via Composer instead of a folder htdocs


  • Can I just copy / paste the project into a folder htdocs

  • Or do I need to delete the project first and then add the new application again via Composer?

source to share

3 answers

In general, projects built with Composer are self-contained and independent of its location in the file system (I'm not familiar with Laravel in ad hoc, but I have no reason to suspect any other behavior here). You can move / copy them without any problem.

As for your worries about plugins not loading after moving the directory: watch how Composer generates its autoloader classmaps (below is just a short excerpt):


// autoload_classmap.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'File_Iterator' => $vendorDir . '/phpunit/php-file-iterator/src/Iterator.php',
    'File_Iterator_Facade' => $vendorDir . '/phpunit/php-file-iterator/src/Facade.php',
    'File_Iterator_Factory' => $vendorDir . '/phpunit/php-file-iterator/src/Factory.php',
    'PHPUnit_Exception' => $vendorDir . '/phpunit/phpunit/src/Exception.php',
    // ...


As you can see, the autoloader is not attached to any pipes on the fixed filesystem, so even the classloader files that are automatically generated by Composer can be easily moved around the filesystem.



I moved mine and it accidentally broke, unable to access any data via endpoints. Fix , in a new project;

  • Make sure all files from the previous project folder are copied to the new folder. Especially in the file .env

  • In the new folder, run composer install

    in terminal.
  • Then run php artisan key:generate

    to generate a new key in the .env

    new folder file .

This worked for me.



As mentioned, be sure to move all files including hidden files (ex: .env)

I had to clear the config caches:

 php artisan config:cache


And in order to be safe, the rest of the caches

 php artisan cache:clear




All Articles