PHPackages                             mohammadsafiabdullah/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. mohammadsafiabdullah/laravel-env-switcher

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

mohammadsafiabdullah/laravel-env-switcher
=========================================

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

20PHP

Since Jun 18Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

laravel-hostkit
===============

[](#laravel-hostkit)

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 everything inside `public/` — `index.php`, `.htaccess`, assets, everything — needs to live at the **project root** instead. This package moves all `public/` contents back and forth safely, including automatically patching `index.php` paths and securing sensitive files via `.htaccess`.

---

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

[](#the-problem)

```
Local dev               Shared hosting
───────────            ───────────────
project/               project/
├── public/            ├── index.php     ← moved from public/
│   ├── index.php      ├── .htaccess    ← security rules added
│   ├── .htaccess      ├── favicon.ico
│   ├── favicon.ico    ├── build/
│   ├── build/         ├── css/
│   └── css/           ├── public/       ← empty
└── ...                └── ...

```

You don't want to manually move files and patch paths every time you switch environments. This package automates that — with backups, rollback, conflict detection, and automatic `.htaccess` security.

---

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

[](#installation)

```
composer require saficodes/laravel-hostkit
```

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

---

Commands
--------

[](#commands)

CommandWhat it does`php artisan env:status`Show current mode and what's in public/ vs root`php artisan env:productionise`Move all `public/` contents → project root (for shared hosting)`php artisan env:localise`Move everything back → `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=pre-deploy  # restore any named 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)

**Everything** inside `public/` is moved to the project root, including:

- `index.php` (paths are automatically patched — `__DIR__.'/../'` becomes `__DIR__.'/'`)
- `.htaccess` (security rules are automatically added to block sensitive files)
- `favicon.ico`, `robots.txt`
- `build/`, `css/`, `js/`, `images/` — any asset folders
- Any other files or directories you've added

**Skipped automatically:**

- Symlinks (e.g. `storage/` → `../storage/app/public`)
- `.gitignore`

---

Security
--------

[](#security)

When you run `env:productionise`, the package automatically adds rules to `.htaccess` that block web access to sensitive files and directories:

**Blocked files:** `.env`, `artisan`, `composer.json`, `composer.lock`, `package.json`, `phpunit.xml`, `vite.config.js/ts`

**Blocked directories:** `app/`, `bootstrap/`, `config/`, `database/`, `lang/`, `resources/`, `routes/`, `storage/`, `tests/`, `vendor/`

These rules are automatically removed when you run `env:localise`.

---

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

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

The package uses a state file (`.hostkit.json`) to track the current mode and which items were moved. If no state file exists, it falls back to checking where `index.php` lives.

StateCondition`local``public/index.php` exists (standard Laravel)`production``index.php` at project root (moved from public/)`conflict``index.php` found in BOTH locations`unknown``index.php` not found anywhere---

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 `.hostkit-backups/` at the project root. Add this to `.gitignore`.

---

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-item rollback** — if a move fails mid-way, already-moved items are moved back automatically.
- **Automatic path patching** — `index.php` relative paths are updated so the app works in both locations.
- **Automatic `.htaccess` security** — sensitive files and directories are blocked from web access in production mode.
- **State tracking** — `.hostkit.json` records exactly which items were moved, so `localise` knows what to move back.
- **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 `index.php` ends up in both locations, the package detects this and refuses to switch until you resolve it.

---

Add to `.gitignore`
-------------------

[](#add-to-gitignore)

```
.hostkit-backups/
.hostkit-tmp-restore-*

```

---

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

[](#requirements)

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

---

License
-------

[](#license)

MIT © M Safi Abdullah

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance60

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### 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 (13 commits)")

### Embed Badge

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

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

###  Alternatives

[php-unit-conversion/php-unit-conversion

A fully PSR-4 compatible PHP library for converting between standard units of measure.

691.3M2](/packages/php-unit-conversion-php-unit-conversion)[arokettu/composer-license-manager

License management plugin for Composer

62226.9k](/packages/arokettu-composer-license-manager)[wyrihaximus/react-child-process-messenger

Messenger decorator for react/child-process

32287.9k4](/packages/wyrihaximus-react-child-process-messenger)[born05/craft-assetusage

Adds a column to see which assets are used or unused.

32133.1k](/packages/born05-craft-assetusage)[rekurzia/slovak-holidays

Simple PHP library/helper for getting Slovak holidays

114.5k](/packages/rekurzia-slovak-holidays)

PHPackages © 2026

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