PHPackages                             techamber/laravel-env-switcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. techamber/laravel-env-switcher

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

techamber/laravel-env-switcher
==============================

Safely switch Laravel asset folders between local (public/) and shared-hosting (root) layouts.

00PHP

Since Jun 18Pushed 1w agoCompare

[ Source](https://github.com/safi-abd/laravel-env-switcher)[ Packagist](https://packagist.org/packages/techamber/laravel-env-switcher)[ RSS](/packages/techamber-laravel-env-switcher/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

laravel-env-switcher
====================

[](#laravel-env-switcher)

A Laravel Artisan package for developers who deploy to **shared hosting** (Hostinger, Namecheap, cPanel, etc.) where the web root is the project root — not `public/`.

On shared hosting you can't point the domain to `/public`, so your compiled assets (`css/`, `js/`, `images/`, `build/`) need to live at the **project root** instead. But locally, they live inside `public/` like a normal Laravel project. This package moves them back and forth safely.

---

The Problem
-----------

[](#the-problem)

```
Local dev               Shared hosting
───────────            ───────────────
project/               project/
├── public/            ├── css/          ← assets at root
│   ├── css/           ├── js/
│   ├── js/            ├── build/
│   └── build/         ├── public/
└── ...                └── ...

```

You don't want to manually move folders every time you switch environments. This package automates that — with backups, rollback, and conflict detection.

---

Installation
------------

[](#installation)

```
composer require mohammadsafiabdullah/laravel-env-switcher
```

Auto-discovery registers the service provider. No config file needed.

---

Commands
--------

[](#commands)

CommandWhat it does`php artisan env:status`Show current mode and state of all asset folders`php artisan env:productionise`Move assets from `public/` → project root (for shared hosting)`php artisan env:localise`Move assets from project root → `public/` (for local dev)`php artisan env:backup --type=pre-deploy`Create a named backup snapshot`php artisan env:reset --to=previous`Restore from a backup### Options

[](#options)

```
php artisan env:productionise --force   # skip the confirmation prompt
php artisan env:localise --force
php artisan env:reset --to=original    # restore the very first backup ever taken
php artisan env:reset --to=manual      # restore a manually-created backup
```

---

Typical workflow
----------------

[](#typical-workflow)

### 1. Check current state

[](#1-check-current-state)

```
php artisan env:status
```

### 2. Before pushing to shared hosting

[](#2-before-pushing-to-shared-hosting)

```
php artisan env:productionise
git add -A && git push
```

### 3. Back to local dev after pulling

[](#3-back-to-local-dev-after-pulling)

```
php artisan env:localise
```

### 4. Something went wrong — roll back

[](#4-something-went-wrong--roll-back)

```
php artisan env:reset --to=previous
# or go all the way back to the original:
php artisan env:reset --to=original
```

---

What gets moved
---------------

[](#what-gets-moved)

- `css/`
- `js/`
- `images/`
- `build/` (Vite output)
- `.htaccess` (moved alongside assets)

---

Backups
-------

[](#backups)

Every switch command automatically creates a `previous` backup before making any changes. The very first switch also saves an `original` backup. You can create additional named backups at any time:

```
php artisan env:backup --type=pre-deploy
```

Backups are stored in `.env-switcher-backups/` at the project root. Add this to `.gitignore`.

---

How mode is detected
--------------------

[](#how-mode-is-detected)

The package checks whether any of the managed directories (`css`, `js`, `images`, `build`) contain files in `public/` vs the project root. This means it works with any asset pipeline — Vite, Mix, or manual.

StateCondition`local`At least one asset dir found in `public/``production`At least one asset dir found at root, none in `public/``conflict`Asset dirs found in BOTH locations`unknown`No managed asset dirs found anywhere---

Safety
------

[](#safety)

- **Pre-flight collision check** — before moving any files, the package checks for collisions at the destination. If a file already exists, the operation is aborted before touching anything.
- **Per-file rollback** — if a move fails mid-way, already-moved files are moved back automatically.
- **Atomic reset** — `env:reset` copies the backup to a temp location first, then verifies it before wiping the current state. Your backup is never at risk.
- **Conflict detection** — if assets end up in both locations (e.g. after a failed operation or manual edits), the package detects this and refuses to switch until you resolve it.

---

Add `.env-switcher-backups/` to `.gitignore`
--------------------------------------------

[](#add-env-switcher-backups-to-gitignore)

```
.env-switcher-backups/
.env-switcher-tmp-restore-*

```

---

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, or 12

---

License
-------

[](#license)

MIT © M Safi Abdullah

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

90d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5db5dfe856133364cf3abe0119cf594c1d4a7eff38da5d0359461a20693e0334?d=identicon)[safi-abd](/maintainers/safi-abd)

---

Top Contributors

[![safi-abd](https://avatars.githubusercontent.com/u/159546307?v=4)](https://github.com/safi-abd "safi-abd (6 commits)")

### Embed Badge

![Health badge](/badges/techamber-laravel-env-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/techamber-laravel-env-switcher/health.svg)](https://phpackages.com/packages/techamber-laravel-env-switcher)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[illuminate/pipeline

The Illuminate Pipeline package.

9348.3M267](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10533.5M991](/packages/illuminate-pagination)[illuminate/redis

The Illuminate Redis package.

8314.4M363](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

224.5M132](/packages/illuminate-cookie)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
