wsl support
This commit is contained in:
parent
8fb5a93b7f
commit
113a60078f
26
Lenvi.yaml
26
Lenvi.yaml
@ -8,26 +8,28 @@ db_engine: "mariadb"
|
|||||||
# 2. Define the global database credentials.
|
# 2. Define the global database credentials.
|
||||||
db_credentials:
|
db_credentials:
|
||||||
user: "Lenvi"
|
user: "Lenvi"
|
||||||
password: "password"
|
password: "secret"
|
||||||
|
|
||||||
# 3. Define all your web sites below.
|
# 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:
|
sites:
|
||||||
# Example for a standard Laravel project
|
# Example for a standard Laravel project
|
||||||
- domain: myapp.local
|
- domain: mylaravelapp.local
|
||||||
project_root: /home/mar/projects/myapp # For Composer
|
project_root: /home/lenvi/projects/laravel # For Composer
|
||||||
document_root: /home/mar/projects/myapp/public # For Nginx
|
document_root: /home/lenvi/projects/laravel/public # For Nginx
|
||||||
php_version: "8.2"
|
php_version: "8.2"
|
||||||
database: "myapp_db"
|
database: "laravel_db"
|
||||||
|
|
||||||
# Example for a legacy project or a non-Laravel PHP project
|
# Example for a legacy project or a non-Laravel PHP project
|
||||||
- domain: legacy-site.local
|
- domain: local-api.domain.com
|
||||||
project_root: /home/mar/projects/legacy-site # For Composer
|
project_root: /home/lenvi/projects/legacy-site # For Composer
|
||||||
document_root: /home/mar/projects/legacy-site # Nginx serves from the root
|
document_root: /home/lenvi/projects/legacy-site # Nginx serves from the root
|
||||||
php_version: "8.0"
|
php_version: "8.0"
|
||||||
database: "legacy_db"
|
database: "legacy_db"
|
||||||
|
|
||||||
# Example for a simple static HTML site (no PHP or DB)
|
# Example for a simple static HTML site (no PHP or DB)
|
||||||
- domain: portfolio.local
|
- domain: phpmyadmin.local
|
||||||
project_root: /home/mar/projects/portfolio # Directory for management
|
project_root: /home/lenvi/projects/phpmyadmin # Directory for management
|
||||||
document_root: /home/mar/projects/portfolio # Nginx serves from the root
|
document_root: /home/lenvi/projects/phpmyadmin # Nginx serves from the root
|
||||||
php_version: "8.2" # Still needed for Nginx config, but can be any installed version
|
php_version: "8.3"
|
150
README.md
150
README.md
@ -1,55 +1,127 @@
|
|||||||
# 🧰 Lenvi - Ansible-Powered Development Environment
|
# Lenvi: Laravel & Legacy Environment Simplified
|
||||||
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
|
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.
|
||||||
- **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.
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
- **Ansible & Git:** Must be installed. `sudo apt update && sudo apt install ansible git -y`
|
|
||||||
- **Sudo Access:** Your user must have `sudo` privileges.
|
- **Ansible & Git:** Must be installed on the machine where you are running the playbook.
|
||||||
- **Debian-based OS:** Required for `apt` (includes Ubuntu, WSL distributions, etc.).
|
|
||||||
|
```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
|
## How to Run
|
||||||
### 1. Get the Code
|
|
||||||
|
### 1\. Setup: Get the Code
|
||||||
|
|
||||||
|
Clone the repository and go to the project directory.
|
||||||
|
|
||||||
```bash
|
```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:
|
### 2\. Configure: Define Your Projects
|
||||||
- **`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`.
|
This is the most important step. Open the `Lenvi.yaml` file and define your entire environment.
|
||||||
**Example `Lenvi.yaml`:**
|
|
||||||
|
- `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
|
```yaml
|
||||||
db_engine: "mariadb"
|
db_engine: "mariadb" #mariadb, mysql post
|
||||||
db_credentials: { user: "lenvi", password: "password" }
|
db_credentials:
|
||||||
|
user: "Lenvi"
|
||||||
|
password: "secret"
|
||||||
|
|
||||||
sites:
|
sites:
|
||||||
- domain: my-laravel-app.local
|
- domain: local-api.laravel.com
|
||||||
project_root: /home/user/projects/my-laravel-app
|
project_root: /home/user/projects/my-laravel-app
|
||||||
document_root: /home/user/projects/my-laravel-app/public
|
document_root: /home/user/projects/my-laravel-app/public
|
||||||
php_version: "8.2"
|
php_version: "8.2"
|
||||||
database: "laravel_db"
|
database: "laravel_db"
|
||||||
- domain: my-static-site.local
|
|
||||||
project_root: /home/user/projects/my-static-site
|
- domain: local.phpmyadmin.com
|
||||||
document_root: /home/user/projects/my-static-site
|
project_root: /home/user/projects/phpmyadmin
|
||||||
php_version: "8.2" # Required for Nginx config, can be any installed version
|
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
|
```bash
|
||||||
ansible-playbook playbook.yml -i inventory --ask-become-pass
|
ansible-playbook playbook.yml -i inventory --ask-become-pass
|
||||||
```
|
```
|
||||||
## 🚀 Post-Installation
|
|
||||||
### Database Access
|
> **\--ask-become-pass:** This flag tells Ansible to prompt for the password needed for privilege escalation (`sudo`).
|
||||||
For each project, use the global user credentials with the project-specific database name from `Lenvi.yaml`.
|
|
||||||
### Update Your Hosts File
|
## Post-Installation Steps
|
||||||
Map your domains to `127.0.0.1`.
|
|
||||||
#### On Linux
|
After the playbook completes successfully, follow these steps to start using your environment.
|
||||||
`sudo nano /etc/hosts`
|
|
||||||
#### On Windows (for WSL Users)
|
### 1\. Finalize Host Access
|
||||||
Open Notepad as Administrator and edit `C:\Windows\System32\drivers\etc\hosts`.
|
|
||||||
**Example entries:**
|
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 local-api.laravel.com
|
||||||
127.0.0.1 my-static-site.local
|
127.0.0.1 local.phpmyadmin.com
|
||||||
```
|
```
|
||||||
✅ **You're all set!** Your flexible, multi-project environment is ready.
|
|
||||||
|
### 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.
|
Loading…
x
Reference in New Issue
Block a user