multi-php update
This commit is contained in:
parent
113a60078f
commit
bcc77ad88e
@ -1,6 +1,6 @@
|
|||||||
# Lenvi: Laravel & Legacy Environment Simplified
|
# 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.
|
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
|
## Prerequisites
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ This playbook is built for Laravel development but can also run legacy PHP apps,
|
|||||||
Clone the repository and go to the project directory.
|
Clone the repository and go to the project directory.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.marmattheo.com/marito/Lenvi.git && cd Lenvi
|
git clone https://git.marmattheo.com/marito/Lenvi.git ~/Lenvi && cd ~/Lenvi
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2\. Configure: Define Your Projects
|
### 2\. Configure: Define Your Projects
|
||||||
|
@ -1,25 +1,18 @@
|
|||||||
---
|
---
|
||||||
- name: "Install yq (YAML processor) for the smart composer script"
|
- name: "Install yq (YAML processor for our smart wrappers)"
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64"
|
url: "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64"
|
||||||
dest: /usr/local/bin/yq
|
dest: /usr/local/bin/yq
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
|
|
||||||
- name: "Download the Composer installer"
|
- name: "Download the Composer installer script"
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: https://getcomposer.org/installer
|
url: https://getcomposer.org/installer
|
||||||
dest: /tmp/composer-installer.php
|
dest: /tmp/composer-setup.php
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
|
|
||||||
- name: "Install Composer globally (as composer.phar)"
|
- name: "Install Composer executable globally"
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: php /tmp/composer-installer.php --install-dir=/usr/local/bin --filename=composer.phar
|
cmd: php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||||||
creates: /usr/local/bin/composer.phar
|
args:
|
||||||
|
creates: /usr/local/bin/composer
|
||||||
- name: "Deploy the smart Composer wrapper script"
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: composer-wrapper.sh.j2
|
|
||||||
dest: /usr/local/bin/composer
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: '0755'
|
|
@ -1,36 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Lenvi Smart Composer Wrapper (v2)
|
|
||||||
#
|
|
||||||
# This script automatically detects the required PHP version for a project
|
|
||||||
# by reading a central Lenvi.yaml file and uses the correct PHP binary.
|
|
||||||
|
|
||||||
# --- The real composer binary and default PHP ---
|
|
||||||
COMPOSER_PHAR="/usr/local/bin/composer.phar"
|
|
||||||
DEFAULT_PHP_BINARY="/usr/bin/php"
|
|
||||||
PHP_BINARY=""
|
|
||||||
|
|
||||||
# --- The EXACT path to the configuration file, baked in by Ansible ---
|
|
||||||
LENVI_CONFIG_FILE="{{ playbook_dir }}/Lenvi.yaml"
|
|
||||||
|
|
||||||
# Check if the central config file actually exists
|
|
||||||
if [[ -f "$LENVI_CONFIG_FILE" ]]; then
|
|
||||||
# We have the config file, now find the PHP version for the current project directory
|
|
||||||
CURRENT_PROJECT_ROOT=$(pwd)
|
|
||||||
PHP_VERSION=$(yq eval '.sites[] | select(.project_root == "'"$CURRENT_PROJECT_ROOT"'") | .php_version' "$LENVI_CONFIG_FILE")
|
|
||||||
|
|
||||||
if [[ -n "$PHP_VERSION" && -x "/usr/bin/php$PHP_VERSION" ]]; then
|
|
||||||
# Version found and the corresponding PHP binary exists
|
|
||||||
PHP_BINARY="/usr/bin/php$PHP_VERSION"
|
|
||||||
echo "Lenvi: Project configuration found. Using PHP $PHP_VERSION..." >&2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If no specific PHP binary was found after checking, use the system default
|
|
||||||
if [[ -z "$PHP_BINARY" ]]; then
|
|
||||||
echo "Lenvi: No specific project configuration found for this directory. Using default system PHP." >&2
|
|
||||||
PHP_BINARY="$DEFAULT_PHP_BINARY"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Execute the real Composer with the determined PHP version and pass all arguments
|
|
||||||
exec "$PHP_BINARY" "$COMPOSER_PHAR" "$@"
|
|
@ -23,4 +23,20 @@
|
|||||||
enabled: yes
|
enabled: yes
|
||||||
state: started
|
state: started
|
||||||
loop: "{{ php_versions_to_install }}"
|
loop: "{{ php_versions_to_install }}"
|
||||||
when: php_versions_to_install is defined and php_versions_to_install | length > 0
|
when: php_versions_to_install is defined and php_versions_to_install | length > 0
|
||||||
|
|
||||||
|
- name: "Deploy the smart PHP wrapper script"
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: php-wrapper.sh.j2
|
||||||
|
dest: /usr/local/bin/php
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0755'
|
||||||
|
|
||||||
|
- name: "Deploy the smart Artisan wrapper script"
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: artisan-wrapper.sh.j2
|
||||||
|
dest: /usr/local/bin/artisan
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0755'
|
14
roles/php/templates/artisan-wrapper.sh.j2
Normal file
14
roles/php/templates/artisan-wrapper.sh.j2
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Lenvi Smart Artisan Wrapper
|
||||||
|
# This script executes 'artisan' with the project-specific PHP version.
|
||||||
|
|
||||||
|
# Find the php wrapper script which contains all the logic.
|
||||||
|
PHP_WRAPPER="/usr/local/bin/php"
|
||||||
|
|
||||||
|
# Check if an artisan file exists in the current directory before trying to run it.
|
||||||
|
if [ -f "artisan" ]; then
|
||||||
|
exec "$PHP_WRAPPER" "artisan" "$@"
|
||||||
|
else
|
||||||
|
echo "Error: 'artisan' file not found in the current directory." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
22
roles/php/templates/php-wrapper.sh.j2
Normal file
22
roles/php/templates/php-wrapper.sh.j2
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Lenvi 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"
|
||||||
|
|
||||||
|
if [[ -f "$LENVI_CONFIG_FILE" ]]; then
|
||||||
|
CURRENT_PROJECT_ROOT=$(pwd)
|
||||||
|
PHP_VERSION=$(yq eval '.sites[] | select(.project_root == "'"$CURRENT_PROJECT_ROOT"'") | .php_version' "$LENVI_CONFIG_FILE")
|
||||||
|
|
||||||
|
if [[ -n "$PHP_VERSION" && -x "/usr/bin/php$PHP_VERSION" ]]; then
|
||||||
|
PHP_BINARY="/usr/bin/php$PHP_VERSION"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$PHP_BINARY" ]]; then
|
||||||
|
PHP_BINARY="$DEFAULT_PHP_BINARY"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$PHP_BINARY" "$@"
|
Loading…
x
Reference in New Issue
Block a user