laravel-shared-hosting-builder
v1.4.0
Published
A CLI tool to prepare Laravel projects for shared hosting deployment (Hostinger/cPanel)
Maintainers
Readme
Laravel Shared Hosting Builder
A CLI tool to prepare Laravel projects for deployment on shared hosting platforms like Hostinger, cPanel, and other PHP-based hosting services.
Features
- Automatically packages Laravel projects for shared hosting
- Runs
php artisan optimize:clearto reset caches before packaging - Creates
dist/directory with all deployment files - Generates optimized
index.phpthat loads Laravel from a subdirectory - Copies all necessary Laravel core files with correct .htaccess configuration
- Cleans storage folders (logs, sessions, cache) while preserving
.gitignore - Produces
uplod.zipfor quick upload (extracts directly without dist folder wrapper) - Keeps
dist/folder for inspection after building - Supports maintenance mode
- Cross-platform support (Linux, macOS, Windows)
Installation
Global Installation
npm install -g laravel-shared-hosting-builderLocal Installation
npm install laravel-shared-hosting-builderUsing npx (No Installation Required)
npx laravel-shb buildUsage
Basic Usage
Navigate to your Laravel project root directory and run:
npx laravel-shb buildOr if installed globally:
laravel-shb buildOptions
npx laravel-shb build [options]Options:
-c, --clean- Clean thedist/folder before building-h, --help- Display help information-V, --version- Display version number
Example with Clean Build
npx laravel-shb build --cleanWhat Gets Built
The tool creates a dist/ folder in your Laravel project root with the following structure:
dist/
├── .htaccess (copied from public/.htaccess if exists)
├── index.php (new entry point for shared hosting)
├── [all public files] (copied from public/)
└── laravel/
├── app/
├── bootstrap/
├── config/
├── database/
├── resources/
├── routes/
├── storage/ (cleaned: logs, cache, sessions)
├── vendor/
├── artisan
├── composer.json
├── composer.lock
└── .env.example (from .env.production_example if available)Additional Output:
uplod.zip- Zip archive containing all files fromdist/folder- When extracted, files are placed directly at the extraction location (no
dist/wrapper folder) - Ready to upload to shared hosting root directory
- When extracted, files are placed directly at the extraction location (no
dist/folder - Remains in your project for inspection and manual deployment if needed
Deployment to Shared Hosting
For Hostinger / cPanel
Run the build command in your local Laravel project:
npx laravel-shb buildUpload the contents of the
dist/folder (or the generateddrac_upload.zip) to your hosting'spublic_htmldirectory using:- FTP client (FileZilla, etc.)
- File Manager in cPanel
- Git deployment (if available)
Configure your
.envfile:- Copy
.env.exampleto.envin thelaravel/directory - Update database credentials
- Set
APP_URLto your domain - Update any other environment variables
- Copy
Generate application key:
php laravel/artisan key:generateRun database migrations:
php laravel/artisan migrateSet proper permissions:
- Make
laravel/storageand its subdirectories writable (755) - Make
laravel/bootstrap/cachewritable (755)
- Make
Directory Structure After Upload
public_html/
├── .htaccess
├── index.php
├── [public assets: css, js, images]
└── laravel/
├── app/
├── bootstrap/
├── config/
├── database/
├── resources/
├── routes/
├── storage/
├── vendor/
├── artisan
├── composer.json
├── composer.lock
├── .env
└── .env.exampleRequirements
- Node.js 14.0.0 or higher
- Laravel project (tested with Laravel 8.x, 9.x, 10.x, 11.x)
How It Works
- Public Files: Copies all files from
public/todist/(except originalindex.php) - HTAccess: Copies
.htaccessfrompublic/.htaccessif it exists - Entry Point: Creates a new
dist/index.phpthat:- Loads Laravel from the
dist/laravelsubdirectory - Sets the public path to
dist/ - Supports Laravel's maintenance mode
- Loads Laravel from the
- Laravel Core: Copies core Laravel folders into
dist/laravel/ - Composer Files: Copies
artisan,composer.json, andcomposer.lock - Storage Cleanup: Cleans storage folders (logs, sessions, cache, uploaded files) while preserving
.gitignore - Environment: Optionally copies
.env.production_exampleto.env.example
Troubleshooting
"public folder not found" Error
Ensure you're running the command from the Laravel project root directory (where public/, app/, etc. are located).
Permission Issues
After uploading, make sure these directories are writable:
laravel/storage/and all subdirectorieslaravel/bootstrap/cache/
Typically, permissions should be set to 755 for directories and 644 for files.
Maintenance Mode
To enable maintenance mode on shared hosting:
php laravel/artisan downTo disable maintenance mode:
php laravel/artisan upDevelopment
BY MD. SHAZAN MAHMUD ARPON
Building the Package Locally
npm linkThis allows you to test the package locally before publishing.
Running Tests
npm testPublishing to NPM
Update version in
package.json:npm version patch # or minor, or majorLogin to npm (if not already logged in):
npm loginPublish the package:
npm publishVerify publication:
npm view laravel-shared-hosting-builder
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Clone the Repository
git clone https://github.com/arpondark/laravel-shared-hosting-builder.git
cd laravel-shared-hosting-builderSetup for Development
npm install
npm link # to test locallyRepository
- GitHub: https://github.com/arpondark/laravel-shared-hosting-builder
- NPM Package: laravel-shared-hosting-builder
Support
If you encounter any issues or have questions, please open an issue on the GitHub repository.
