From 113a60078f4b39730344bbdf27ad1135c0c37131 Mon Sep 17 00:00:00 2001 From: marito Date: Sun, 15 Jun 2025 12:28:10 +0800 Subject: [PATCH] wsl support --- Lenvi.yaml | 26 +++++----- README.md | 150 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 125 insertions(+), 51 deletions(-) diff --git a/Lenvi.yaml b/Lenvi.yaml index 4b5c3e6..d33f4a5 100644 --- a/Lenvi.yaml +++ b/Lenvi.yaml @@ -8,26 +8,28 @@ db_engine: "mariadb" # 2. Define the global database credentials. db_credentials: user: "Lenvi" - password: "password" + password: "secret" # 3. Define all your web sites below. +# WSL users: Ensure these paths are correct for your WSL environment. +# For WSL, you might need to use paths like /home/lenvi/projects/laravel instead of /mnt/c/Users/YourUser/projects/laravel sites: # Example for a standard Laravel project - - domain: myapp.local - project_root: /home/mar/projects/myapp # For Composer - document_root: /home/mar/projects/myapp/public # For Nginx + - domain: mylaravelapp.local + project_root: /home/lenvi/projects/laravel # For Composer + document_root: /home/lenvi/projects/laravel/public # For Nginx php_version: "8.2" - database: "myapp_db" + database: "laravel_db" # Example for a legacy project or a non-Laravel PHP project - - domain: legacy-site.local - project_root: /home/mar/projects/legacy-site # For Composer - document_root: /home/mar/projects/legacy-site # Nginx serves from the root + - domain: local-api.domain.com + project_root: /home/lenvi/projects/legacy-site # For Composer + document_root: /home/lenvi/projects/legacy-site # Nginx serves from the root php_version: "8.0" database: "legacy_db" # Example for a simple static HTML site (no PHP or DB) - - domain: portfolio.local - project_root: /home/mar/projects/portfolio # Directory for management - document_root: /home/mar/projects/portfolio # Nginx serves from the root - php_version: "8.2" # Still needed for Nginx config, but can be any installed version \ No newline at end of file + - domain: phpmyadmin.local + project_root: /home/lenvi/projects/phpmyadmin # Directory for management + document_root: /home/lenvi/projects/phpmyadmin # Nginx serves from the root + php_version: "8.3" \ No newline at end of file diff --git a/README.md b/README.md index 579cc12..f6e617e 100644 --- a/README.md +++ b/README.md @@ -1,55 +1,127 @@ -# 🧰 Lenvi - Ansible-Powered Development Environment -Lenvi is a framework-agnostic development environment powered by Ansible. It installs and configures Nginx, multiple PHP versions, your choice of database, **per-project databases**, a global database user, and a smart Composer wrapper that automatically uses the correct PHP version for each project. -## Features -- **Framework Agnostic**: By specifying a `document_root` for Nginx and a `project_root` for Composer, you can support Laravel, WordPress, legacy PHP apps, or even static HTML sites. -- **Robust Validation**: Automatically checks that your configured directories and index files exist before attempting setup, preventing common Nginx errors. -- **Per-Project Databases**: Each site defined in `Lenvi.yaml` can have its own isolated database, created automatically. -- **Seamless Composer Workflow**: `cd` into your project directory and run `composer install`. Lenvi automatically uses the correct PHP version for that project. -- **Centralized Configuration**: Manage your entire environment from a single, clean `Lenvi.yaml` file. +# Lenvi: Laravel & Legacy Environment Simplified + +This playbook is built for Laravel development but can also run legacy PHP apps, offering a powerful, centralized environment on Debian, Ubuntu, or WSL2—similar to Homestead but without the virtual machine overhead. + ## Prerequisites -- **Ansible & Git:** Must be installed. `sudo apt update && sudo apt install ansible git -y` -- **Sudo Access:** Your user must have `sudo` privileges. -- **Debian-based OS:** Required for `apt` (includes Ubuntu, WSL distributions, etc.). + +- **Ansible & Git:** Must be installed on the machine where you are running the playbook. + + ```bash + sudo apt update && sudo apt install ansible git -y + ``` + +- **Sudo Access:** Your user must have `sudo` privileges to run the playbook. + ## How to Run -### 1. Get the Code + +### 1\. Setup: Get the Code + +Clone the repository and go to the project directory. + ```bash -git clone https://git.marmattheo.com/marito/Lenvi.git lenvi-ansible && cd lenvi-ansible +git clone https://git.marmattheo.com/marito/Lenvi.git && cd Lenvi ``` -### 2. Configure Lenvi -Open **`Lenvi.yaml`** and define your sites. This is the key to Lenvi's flexibility: -- **`project_root`**: The base directory of your project. This is where you would run `git` or `composer` commands. -- **`document_root`**: The directory that Nginx will serve files from. For Laravel, this is the `public` sub-directory. For many other projects, it might be the same as the `project_root`. -**Example `Lenvi.yaml`:** + +### 2\. Configure: Define Your Projects + +This is the most important step. Open the `Lenvi.yaml` file and define your entire environment. + +- `project_root`: The base directory of your project. This is where you would run `git` or `composer` commands. +- `document_root`: The directory that Nginx will serve files from. For Laravel, this is the `public` sub-directory. + **Example** `Lenvi.yaml`**:** + ```yaml -db_engine: "mariadb" -db_credentials: { user: "lenvi", password: "password" } +db_engine: "mariadb" #mariadb, mysql post +db_credentials: +  user: "Lenvi" + password: "secret" + sites: - - domain: my-laravel-app.local + - domain: local-api.laravel.com project_root: /home/user/projects/my-laravel-app document_root: /home/user/projects/my-laravel-app/public php_version: "8.2" database: "laravel_db" - - domain: my-static-site.local - project_root: /home/user/projects/my-static-site - document_root: /home/user/projects/my-static-site - php_version: "8.2" # Required for Nginx config, can be any installed version + + - domain: local.phpmyadmin.com + project_root: /home/user/projects/phpmyadmin + document_root: /home/user/projects/phpmyadmin + php_version: "8.3" # Required for Nginx config ``` -### 3. Execute the Playbook + +### 3\. Execute: Run the Playbook + +Run the following command from the `lenvi-ansible` directory. It will prompt you for your `sudo` password to perform the administrative tasks. + ```bash ansible-playbook playbook.yml -i inventory --ask-become-pass ``` -## 🚀 Post-Installation -### Database Access -For each project, use the global user credentials with the project-specific database name from `Lenvi.yaml`. -### Update Your Hosts File -Map your domains to `127.0.0.1`. -#### On Linux -`sudo nano /etc/hosts` -#### On Windows (for WSL Users) -Open Notepad as Administrator and edit `C:\Windows\System32\drivers\etc\hosts`. -**Example entries:** + +> **\--ask-become-pass:** This flag tells Ansible to prompt for the password needed for privilege escalation (`sudo`). + +## Post-Installation Steps + +After the playbook completes successfully, follow these steps to start using your environment. + +### 1\. Finalize Host Access + +For your browser to resolve local domains like `my-laravel-app.local`, you must map them to `127.0.0.1`. + +- **On Linux:** + + ```bash + sudo nano /etc/hosts + ``` + +- **On Windows (for WSL Users):** + Open **Notepad** as an **Administrator** and edit the file `C:\Windows\System32\drivers\etc\hosts`. + **Add entries for each of your sites:** + ``` -127.0.0.1 my-laravel-app.local -127.0.0.1 my-static-site.local +127.0.0.1 local-api.laravel.com +127.0.0.1 local.phpmyadmin.com ``` -✅ **You're all set!** Your flexible, multi-project environment is ready. \ No newline at end of file + +### 2\. Configure Your Application + +Update your application's `.env` file to connect to the database. Use the global credentials and the specific database name you defined in `Lenvi.yaml`. +**Example** `.env` **for** `my-laravel-app.local`**:** + +```env +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laravel_db +DB_USERNAME=lenvi +DB_PASSWORD=password +``` + +### 3\. Verify Your Setup + +- **Web Access:** Open your browser and navigate to `http://my-laravel-app.local`. You should see your application. +- **Composer:** `cd` into your project's `project_root` and run `composer --version`. The "smart" wrapper will automatically use the correct PHP version for that project. + + ```bash + cd /home/user/projects/my-laravel-app + sudo composer install + ``` + > you must run `sudo` when using composer install and type `yes` when prompted. + +## Daily Workflow + +### Adding a New Site + +1. Add a new project block to the `sites` list in `Lenvi.yaml`. +2. Add the new domain to your hosts file. +3. Re-run the playbook. + +### Changing a Site's PHP Version + +1. In `Lenvi.yaml`, change the `php_version` for the desired site. +2. Re-run the playbook. + +### Removing a Site + +1. Delete the project's block from `Lenvi.yaml`. +2. Manually delete the site's Nginx configuration file (e.g., `sudo rm /etc/nginx/conf.d/local-api.laravel.com.conf`). +3. Re-run the playbook and remove the entry from your hosts file. \ No newline at end of file