Lenverge v1

This commit is contained in:
marito 2025-06-17 14:45:38 +08:00
parent ad23896e5f
commit 3f1fe7ef5c
10 changed files with 59 additions and 57 deletions

View File

@ -1,5 +1,5 @@
# ------------------------------------------------------------------
# Lenvi: Central Configuration for Your Development Environment
# Lenverge: Central Configuration for Your Development Environment
# ------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
@ -8,13 +8,13 @@
# utilities:
# phpmyadmin:
# enabled: false
# domain: "pma.lenvi.local" # Local domain (can be customized)
# domain: "pma.lenverge.local" # Local domain (can be customized)
# php_version: "8.3" # Must match one of your project's PHP versions
# redis:
# enabled: false
# db_engine:
# Choose between mariadb, mysql, or postgresql. Lenvi will install and manage the correct service.
# Choose between mariadb, mysql, or postgresql. Lenverge will install and manage the correct service.
# db_credentials:
# Used for all auto-provisioned databases.
@ -34,7 +34,7 @@
utilities:
phpmyadmin:
enabled: false
domain: "pma.lenvi.local"
domain: "pma.lenverge.local"
php_version: "8.3"
redis:
enabled: false
@ -44,7 +44,7 @@ db_engine: "mariadb"
# 🔐 Database Credentials
db_credentials:
user: "Lenvi"
user: "Lenverge"
password: "secret"
# 🌐 Project Sites
@ -55,18 +55,18 @@ db_credentials:
sites:
- domain: mylaravelapp.local
project_root: /home/lenvi/projects/laravel
document_root: /home/lenvi/projects/laravel/public
project_root: /home/lenverge/projects/laravel
document_root: /home/lenverge/projects/laravel/public
php_version: "8.2"
database: "laravel_db"
- domain: mylegacyapp.local
project_root: /home/lenvi/projects/legacy-site
document_root: /home/lenvi/projects/legacy-site
project_root: /home/lenverge/projects/legacy-site
document_root: /home/lenverge/projects/legacy-site
php_version: "8.0"
database: "legacy_db"
- domain: simple.local
project_root: /home/lenvi/projects/simple
document_root: /home/lenvi/projects/simple
project_root: /home/lenverge/projects/simple
document_root: /home/lenverge/projects/simple
php_version: "8.3"

View File

@ -1,9 +1,11 @@
# Lenvi
The name **Lenvi** stands for **L**aravel, **L**egacy, and **L**ightweight **Envi**ronment.
It's a fast, simple alternative to tools like Homestead that uses Ansible to provision your local Ubuntu machine (or WSL2) directly, without the overhead of a virtual machine. True to its name, Lenvi is tailored to handle modern **L**aravel applications and complex **L**egacy PHP sites with ease, all while remaining incredibly **L**ightweight.
# Lenverge
Lenverge is a lightweight, Ansible-powered environment tool built for Laravel and legacy PHP projects. It delivers fast, VM-free provisioning directly on Ubuntu or WSL2 — ideal for modern apps and legacy codebases alike.
> Lenverge comes from Laravel, Legacy, and Lightweight Environment — built for projects that sit on the verge of legacy and modern, and need a clean bridge.
### Core Features
* **No Virtual Machine:** Runs directly on Ubuntu 22.04+ (or WSL2 Ubuntu).
* **Centralized Configuration:** Define your entire stack in one simple `Lenvi.yaml` file.
* **Centralized Configuration:** Define your entire stack in one simple `Lenverge.yaml` file.
* **Multi-PHP Ready:** Run different sites on different PHP versions simultaneously.
* **Smart CLI Wrappers:** Automatically uses the correct PHP version for `php`, `composer`, and `artisan` commands based on your current project directory.
* **Developer Utilities:** Easily enable tools like phpMyAdmin and Redis.
@ -25,19 +27,19 @@ It's a fast, simple alternative to tools like Homestead that uses Ansible to pro
### 1. Get the Code
Clone the repository to a convenient location, like your home directory.
```bash
git clone https://git.marmattheo.com/marito/Lenvi.git ~/Lenvi && cd ~/Lenvi
git clone https://git.marmattheo.com/marito/Lenverge.git ~/Lenverge && cd ~/Lenverge
```
### 2. Configure Your Environment (`Lenvi.yaml`)
This is the most important step. Open `Lenvi.yaml` and define your entire environment.
### 2. Configure Your Environment (`Lenverge.yaml`)
This is the most important step. Open `Lenverge.yaml` and define your entire environment.
```yaml
# ------------------------------------------------------------------
# Lenvi: Central Configuration for Your Development Environment
# Lenverge: Central Configuration for Your Development Environment
# ------------------------------------------------------------------
# Optional developer utilities
utilities:
phpmyadmin:
enabled: false
domain: "pma.lenvi.local"
domain: "pma.lenverge.local"
php_version: "8.2"
redis:
enabled: false
@ -45,19 +47,19 @@ utilities:
db_engine: "mariadb"
# 2. Global Database Credentials
db_credentials:
user: "Lenvi"
user: "Lenverge"
password: "secret"
# 3. Your Web Projects
sites:
- domain: mylaravelapp.local
project_root: /home/lenvi/projects/laravel
document_root: /home/lenvi/projects/laravel/public
project_root: /home/lenverge/projects/laravel
document_root: /home/lenverge/projects/laravel/public
php_version: "8.2"
database: "laravel_db"
```
**Key Configuration Options:**
* **`utilities`**: Set `enabled: true` to install optional tools like `phpmyadmin` and `redis`.
* **`db_engine`**: Choose between `mariadb`, `mysql`, or `postgresql`. Lenvi will install and manage the correct service.
* **`db_engine`**: Choose between `mariadb`, `mysql`, or `postgresql`. Lenverge will install and manage the correct service.
* **`sites`**: A list of all your projects.
* `domain`: The local domain name you'll use in the browser.
* `project_root`: The base directory of your project (where `.git` or `composer.json` lives).
@ -66,16 +68,16 @@ sites:
* `database`: (Optional) The name of the database to create for this site.
> **WSL Performance Tip:** For the best performance, keep your project files inside the WSL filesystem (e.g., `/home/user/projects`) rather than on the mounted Windows filesystem (e.g., `/mnt/c/Users/...`).
### 3. Run the Provisioning Script
To set up or update your environment, use the simple `lenvi.sh` script.
To set up or update your environment, use the simple `lenverge.sh` script.
First, make the script executable (you only need to do this once):
```bash
chmod +x lenvi.sh
chmod +x lenverge.sh
```
Now, run the script. It will handle everything for you and will prompt for your `sudo` password to perform the necessary system changes.
```bash
./lenvi.sh
./lenverge.sh
```
> **WSL Users:** The very first time you run this, the script may stop and ask you to restart WSL. This is a one-time setup step to fix file permissions. Follow the on-screen instructions, and then re-run `./lenvi.sh`.
> **WSL Users:** The very first time you run this, the script may stop and ask you to restart WSL. This is a one-time setup step to fix file permissions. Follow the on-screen instructions, and then re-run `./lenverge.sh`.
## Post-Installation
### 1. Update Your `hosts` File
For your browser to access local domains, you must map them to your local machine.
@ -84,24 +86,24 @@ For your browser to access local domains, you must map them to your local machin
sudo nano /etc/hosts
```
* **On Windows (for WSL):** Open **Notepad as an Administrator** and edit `C:\Windows\System32\drivers\etc\hosts`.
Add an entry for each domain defined in `Lenvi.yaml`:
Add an entry for each domain defined in `Lenverge.yaml`:
```
127.0.0.1 mylaravelapp.local
# Add other project domains here
# Add utility domains if enabled, e.g.:
# 127.0.0.1 pma.lenvi.local
# 127.0.0.1 pma.lenverge.local
```
### 2. Configure Your Application (`.env`)
Update your application's `.env` file to use the database credentials from `Lenvi.yaml`.
Update your application's `.env` file to use the database credentials from `Lenverge.yaml`.
**Example `.env` for `mylaravelapp.local` (MariaDB/MySQL):**
```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=Lenvi
DB_USERNAME=Lenverge
DB_PASSWORD=secret
# If you enabled Redis in Lenvi.yaml
# If you enabled Redis in Lenverge.yaml
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
@ -112,20 +114,20 @@ DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel_db_pg
DB_USERNAME=Lenvi
DB_USERNAME=Lenverge
DB_PASSWORD=secret
```
### 3. Verify Your Setup
* **Web Access:** Open your browser and navigate to `http://mylaravelapp.local`.
* **Smart PHP Version:** The `php`, `composer`, and `artisan` commands are context-aware.
```bash
cd /home/lenvi/projects/laravel
cd /home/lenverge/projects/laravel
php --version # Will show the PHP version defined for this site
composer install
```
## Daily Workflow
Lenvi is designed to be declarative. To make any changes, simply edit `Lenvi.yaml` and re-run the provisioning script with `./lenvi.sh`.
* **To Add a New Site:** Add a new entry to the `sites` list, update your `hosts` file, and run `./lenvi.sh`.
* **To Remove a Site:** Delete the site's block from `Lenvi.yaml`. When you re-run `./lenvi.sh`, Lenvi will automatically remove its Nginx configuration.
* **To Change a PHP Version:** Update the `php_version` for a site and run `./lenvi.sh`.
* **To Enable a Utility:** Set `enabled: true` for `phpmyadmin` or `redis`, update your `hosts` file if needed, and run `./lenvi.sh`.
Lenverge is designed to be declarative. To make any changes, simply edit `Lenverge.yaml` and re-run the provisioning script with `./lenverge.sh`.
* **To Add a New Site:** Add a new entry to the `sites` list, update your `hosts` file, and run `./lenverge.sh`.
* **To Remove a Site:** Delete the site's block from `Lenverge.yaml`. When you re-run `./lenverge.sh`, Lenverge will automatically remove its Nginx configuration.
* **To Change a PHP Version:** Update the `php_version` for a site and run `./lenverge.sh`.
* **To Enable a Utility:** Set `enabled: true` for `phpmyadmin` or `redis`, update your `hosts` file if needed, and run `./lenverge.sh`.

View File

@ -1,2 +1,2 @@
[lenvi_dev]
[lenverge_dev]
localhost ansible_connection=local

View File

@ -1,6 +1,6 @@
#!/bin/bash
# --- Lenvi Provisioning Script ---
# --- Lenverge Provisioning Script ---
# This script simplifies running the Ansible playbook, making it accessible
# for users who are not familiar with Ansible.
@ -10,8 +10,8 @@ chmod +x /home/$(whoami)
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR"
echo "▶️ Starting Lenvi Provisioning..."
echo " This will install/update services based on your Lenvi.yaml configuration."
echo "▶️ Starting Lenverge Provisioning..."
echo " This will install/update services based on your Lenverge.yaml configuration."
echo " You will be prompted for your sudo password to make system changes."
echo ""
@ -19,12 +19,12 @@ echo ""
# The `if` statement checks the command's exit code to provide a clear success/failure message.
if ansible-playbook playbook.yml -i inventory --ask-become-pass; then
echo ""
echo "✅ Success! Your Lenvi environment has been provisioned."
echo "✅ Success! Your Lenverge environment has been provisioned."
echo " Don't forget to update your hosts file if you added or changed site domains."
echo ""
else
echo ""
echo "❌ Error: Lenvi provisioning failed." >&2
echo "❌ Error: Lenverge provisioning failed." >&2
echo " Please review the Ansible output above to diagnose the issue." >&2
exit 1
fi

View File

@ -1,10 +1,10 @@
---
- name: "Provision Lenvi Development Environment"
hosts: lenvi_dev
- name: "Provision Lenverge Development Environment"
hosts: lenverge_dev
become: yes
vars_files:
- Lenvi.yaml
- Lenverge.yaml
pre_tasks:
- name: "Gather a unique list of required PHP versions from sites"

View File

@ -47,5 +47,5 @@
- name: "FOR WSL USER: This error is safe and intentional. Follow instructions below."
ansible.builtin.fail:
msg: |
✅ ACTION REQUIRED: WSL Configuration was Updated! Lenvi has configured /etc/wsl.conf to fix file permissions. You MUST restart WSL for this change to take effect. Please perform the following steps: 1. Type 'logout' or 'exit' to exit WSL. 2. Run the command: wsl --shutdown 3. Wait a few seconds, then re-open your WSL terminal. 4. cd ~/Lenvi and Re-run ./lenvi.sh
✅ ACTION REQUIRED: WSL Configuration was Updated! Lenverge has configured /etc/wsl.conf to fix file permissions. You MUST restart WSL for this change to take effect. Please perform the following steps: 1. Type 'logout' or 'exit' to exit WSL. 2. Run the command: wsl --shutdown 3. Wait a few seconds, then re-open your WSL terminal. 4. cd ~/Lenverge and Re-run ./lenverge.sh
when: wsl_conf_result.changed

View File

@ -80,7 +80,7 @@
- db_engine != 'postgres'
- "'postgresql' in ansible_facts.services"
- name: "Create the global Lenvi PostgreSQL user"
- name: "Create the global Lenverge PostgreSQL user"
community.postgresql.postgresql_user:
name: "{{ db_credentials.user }}"
password: "{{ db_credentials.password }}"
@ -98,7 +98,7 @@
state: present
when: db_engine == 'mariadb' or db_engine == 'mysql'
- name: "Create the global Lenvi database user"
- name: "Create the global Lenverge database user"
community.mysql.mysql_user:
name: "{{ db_credentials.user }}"
password: "{{ db_credentials.password }}"

View File

@ -1,5 +1,5 @@
#!/bin/bash
# Lenvi Smart Artisan Wrapper
# Lenverge Smart Artisan Wrapper
# This script executes 'artisan' with the project-specific PHP version.
# Find the php wrapper script which contains all the logic.

View File

@ -1,10 +1,10 @@
#!/bin/bash
# Lenvi Smart PHP Wrapper
# Lenverge Smart PHP Wrapper
# This script executes any 'php' command with the project-specific PHP version.
DEFAULT_PHP_BINARY="/usr/bin/php"
PHP_BINARY=""
LENVI_CONFIG_FILE="{{ playbook_dir }}/Lenvi.yaml"
LENVI_CONFIG_FILE="{{ playbook_dir }}/Lenverge.yaml"
if [[ -f "$LENVI_CONFIG_FILE" ]]; then
CURRENT_PROJECT_ROOT=$(pwd)

View File

@ -11,7 +11,7 @@
msg: |
VALIDATION FAILED for site '{{ project.domain }}':
The project_root directory '{{ project.project_root }}' does not exist.
This path is required for Composer. Please create it or correct the path in Lenvi.yaml.
This path is required for Composer. Please create it or correct the path in Lenverge.yaml.
when: not project_root_stat.stat.exists or not project_root_stat.stat.isdir
- name: "Validate that document root '{{ project.document_root }}' exists"
@ -24,7 +24,7 @@
msg: |
VALIDATION FAILED for site '{{ project.domain }}':
The document_root directory '{{ project.document_root }}' does not exist.
This path is required for Nginx. Please create it or correct the path in Lenvi.yaml.
This path is required for Nginx. Please create it or correct the path in Lenverge.yaml.
when: not document_root_stat.stat.exists or not document_root_stat.stat.isdir
- name: "Check for an index file (index.php or index.html) in the document root"