部署含Per-project Homestead的Laravel项目至共享主机:文件复制与排除咨询
Hey there! Let's break down exactly what you need to upload to your shared host, and what you can safely leave behind when deploying your per-project Homestead Laravel app.
These are the core files and folders your Laravel app needs to run in production:
app/: Your entire application logic (controllers, models, middleware, etc.) lives here—don't skip this.bootstrap/: Contains framework bootstrapping files and cached config/routes. Even if some cache folders are empty, the base structure is required.config/: Your app's base configuration files (production-specific values will come from your.envfile, but these base files are still needed).database/: Migration files (critical if you need to run database setup on the host) and seed files (optional but useful for populating default data).public/: This is your web server's document root—it includes theindex.phpentry point, compiled frontend assets (CSS/JS/images), and any static files your app serves.resources/: View templates, language files, and raw frontend assets (if you haven't compiled them locally). At minimum, theviews/andlang/subfolders are mandatory.routes/: All your app's route definitions (web, API, console)—core to how your app handles requests.storage/: Stores logs, cached data, user uploads, and framework-generated files. Make sure to set proper write permissions on this folder (and its subfolders) on your shared host—Laravel needs to write here.vendor/: All Composer-installed dependencies. Unless your host allows runningcomposer install(most shared hosts don't), you'll need to install these locally and upload the entire folder..env: Your production-specific configuration file (create a new one for production—don't use your local.env.example). SetAPP_ENV=productionandAPP_DEBUG=falsehere for security.artisan: Laravel's command-line tool—useful for running migrations, clearing caches, or other maintenance tasks on the host.composer.json&composer.lock: These help track dependencies; useful if you ever need to update packages on the host (if allowed).
What You Can Safely Exclude
These files/folders are only for local development (Homestead/Vagrant/Git/testing) and have no place on your production server:
.vagrant/: Local Vagrant VM state files—completely irrelevant to production.tests/: All your unit/feature test code—production doesn't need to run tests..env.example: A template for local environment configs; production uses your custom.env..gitattributes&.gitignore: Git repository configuration files—only needed if you're using Git locally.after.sh,Homestead.yaml,Vagrantfile: Homestead/Vagrant-specific setup files—these are for your local dev environment only..git/: Your local Git repository folder—never upload this to production.node_modules/: Frontend development dependencies (like npm packages). Once you've compiled your frontend assets topublic/, this folder is redundant.package.json,package-lock.json,webpack.mix.js: If you've already compiled frontend assets locally, these can be excluded. Only keep them if you need to compile assets on the host (unlikely on shared hosts).phpunit.xml: PHPUnit test configuration—useless in production.server.php: Local development server entry point—your shared host usespublic/index.phpinstead.
Quick Deployment Tips
- Double-check permissions on
storage/andbootstrap/cache/—most shared hosts require these folders to be writable (usually chmod 755 or 775, depending on the host's setup). - After uploading, run
php artisan config:cacheandphp artisan route:cachevia SSH (if your host allows) to optimize performance for production. - Never expose your
.envfile to the web—most shared hosts configure the document root to point topublic/, which keeps.envsafe by default.
内容的提问来源于stack exchange,提问作者LowLevel
相关产品推荐
相关产品推荐

