Lenvi: Laravel & Legacy Environment Simplified
This playbook is built for Laravel development but can also run legacy PHP apps, offering a powerful, centralized environment with multi-php support on Debian, Ubuntu, or WSL2; similar to Homestead but without the virtual machine overhead.
Prerequisites
- 
Ansible & Git: Must be installed on the machine where you are running the playbook.
sudo apt update && sudo apt install ansible git -y - 
Sudo Access: Your user must have
sudoprivileges to run the playbook. 
How to Run
1. Setup: Get the Code
Clone the repository and go to the project directory.
git clone https://git.marmattheo.com/marito/Lenvi.git ~/Lenvi && cd ~/Lenvi
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 rungitorcomposercommands.document_root: The directory that Nginx will serve files from. For Laravel, this is thepublicsub-directory.
ExampleLenvi.yaml:
db_engine: "mariadb" #mariadb, mysql post
db_credentials:
  user: "Lenvi"
  password: "secret"
sites:
  - 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: 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: 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.
ansible-playbook playbook.yml -i inventory --ask-become-pass
--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:
sudo nano /etc/hosts - 
On Windows (for WSL Users):
Open Notepad as an Administrator and edit the fileC:\Windows\System32\drivers\etc\hosts.
Add entries for each of your sites: 
127.0.0.1   local-api.laravel.com
127.0.0.1   local.phpmyadmin.com
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:
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:
cdinto your project'sproject_rootand runcomposer --version. The "smart" wrapper will automatically use the correct PHP version for that project.cd /home/user/projects/my-laravel-app sudo composer installyou must run
sudowhen using composer install and typeyeswhen prompted. 
Daily Workflow
Adding a New Site
- Add a new project block to the 
siteslist inLenvi.yaml. - Add the new domain to your hosts file.
 - Re-run the playbook.
 
Changing a Site's PHP Version
- In 
Lenvi.yaml, change thephp_versionfor the desired site. - Re-run the playbook.
 
Removing a Site
- Delete the project's block from 
Lenvi.yaml. - Manually delete the site's Nginx configuration file (e.g., 
sudo rm /etc/nginx/conf.d/local-api.laravel.com.conf). - Re-run the playbook and remove the entry from your hosts file.