mirror of
https://github.com/YunoHost-Apps/phpinfo_ynh.git
synced 2024-09-03 19:56:23 +02:00
To phpenv from git
This commit is contained in:
parent
6f8ec16f33
commit
2b1d498b70
3 changed files with 98 additions and 98 deletions
|
@ -47,7 +47,7 @@
|
|||
"ask": {
|
||||
"en": "Choose the version of PHP to use."
|
||||
},
|
||||
"default": "8.0.3"
|
||||
"default": "8.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ ynh_script_progression --message="Setting up source files..."
|
|||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
|
||||
mkdir -p $final_path
|
||||
cp ../sources/index.php /$final_path/.
|
||||
cp ../sources/index.php $final_path/.
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
phpenv_version=20190623
|
||||
php_build_version=20210307
|
||||
phpenv_aliases_version=20180628
|
||||
phpenv_composer_version=20160325
|
||||
|
||||
ynh_php_try_bash_extension() {
|
||||
if [ -x src/configure ]; then
|
||||
src/configure && make -C src || {
|
||||
echo "Optional bash extension failed to build, but things will still work normally."
|
||||
}
|
||||
fi
|
||||
}
|
||||
|
||||
phpenv_install_dir="/opt/phpenv"
|
||||
php_version_path="$phpenv_install_dir/versions"
|
||||
# PHPENV_ROOT is the directory of phpenv, it needs to be loaded as a environment variable.
|
||||
|
@ -12,50 +17,6 @@ export PHPENV_ROOT="$phpenv_install_dir"
|
|||
# Required dependencies
|
||||
phpenv_dependencies="autoconf2.13 autoconf2.64 autoconf bash bison build-essential ca-certificates curl findutils git libbz2-dev libcurl4-gnutls-dev libicu-dev libjpeg-dev libmcrypt-dev libonig-dev libpng-dev libreadline-dev libsqlite3-dev libssl-dev libtidy-dev libxml2-dev libxslt1-dev libzip-dev pkg-config re2c zlib1g-dev"
|
||||
|
||||
# Install PHP Version Management
|
||||
#
|
||||
# [internal]
|
||||
#
|
||||
# usage: ynh_install_phpenv
|
||||
#
|
||||
# Requires YunoHost version 2.7.12 or higher.
|
||||
ynh_install_phpenv () {
|
||||
ynh_print_info --message="Installation of phpenv - PHP Version Management - phpenv-${phpenv_version}/php-build-${php_build_version}"
|
||||
|
||||
# Build an app.src for phpenv
|
||||
mkdir -p "../conf"
|
||||
echo "SOURCE_URL=https://github.com/phpenv/phpenv/archive/9b7e4e1c0083c46be69f4c6d063f78c18654aad1.tar.gz
|
||||
SOURCE_SUM=96d8edddb2ab3f953f9ee64af8b45e7e983713e99507bba75c6b8cbaa466089a" > "../conf/phpenv.src"
|
||||
# Download and extract phpenv
|
||||
ynh_setup_source --dest_dir="$phpenv_install_dir" --source_id=phpenv
|
||||
|
||||
# Build an app.src for php-build
|
||||
mkdir -p "../conf"
|
||||
echo "SOURCE_URL=https://github.com/php-build/php-build/archive/6530e7501ccc758928d5510813dc3f5fbdc87419.tar.gz
|
||||
SOURCE_SUM=e2de1071f956033aa670e08f0fcf3317a26249b69eea7df42fa95187afa9a17f" > "../conf/php-build.src"
|
||||
# Download and extract php-build
|
||||
ynh_setup_source --dest_dir="$phpenv_install_dir/plugins/php-build" --source_id=php-build
|
||||
|
||||
# Build an app.src for phpenv-aliases
|
||||
mkdir -p "../conf"
|
||||
echo "SOURCE_URL=https://github.com/madumlao/phpenv-aliases/archive/89cbd4d4aa808f06299d903046c674139a8978fe.tar.gz
|
||||
SOURCE_SUM=ffaad964ff11a9cad8935e7e972c57cd08da203028a1573792dbbe5f15e0696a" > "../conf/phpenv-aliases.src"
|
||||
# Download and extract phpenv-aliases
|
||||
ynh_setup_source --dest_dir="$phpenv_install_dir/plugins/phpenv-aliases" --source_id=phpenv-aliases
|
||||
|
||||
# Build an app.src for phpenv-composer
|
||||
mkdir -p "../conf"
|
||||
echo "SOURCE_URL=https://github.com/ngyuki/phpenv-composer/archive/45af2a346747192aa46413f1d764fc25e177a46a.tar.gz
|
||||
SOURCE_SUM=1643fe1d49cf424c3590af6a23cef09c6050fc5b71212205b6d459debc6d063f" > "../conf/phpenv-composer.src"
|
||||
# Download and extract phpenv-composer
|
||||
ynh_setup_source --dest_dir="$phpenv_install_dir/plugins/phpenv-composer" --source_id=phpenv-composer
|
||||
|
||||
# Create shims directory if needed
|
||||
if [ ! -d $phpenv_install_dir/shims ] ; then
|
||||
mkdir $phpenv_install_dir/shims
|
||||
fi
|
||||
}
|
||||
|
||||
# Load the version of PHP for an app, and set variables.
|
||||
#
|
||||
# ynh_use_php has to be used in any app scripts before using PHP for the first time.
|
||||
|
@ -98,7 +59,7 @@ ynh_use_php () {
|
|||
php_version=$(ynh_app_setting_get --app=$app --key=php_version)
|
||||
|
||||
# Get the absolute path of this version of PHP
|
||||
php_path="$php_version_path/$YNH_APP_INSTANCE_NAME/bin"
|
||||
php_path="$php_version_path/$php_version/bin"
|
||||
|
||||
# Allow alias to be used into bash script
|
||||
shopt -s expand_aliases
|
||||
|
@ -106,15 +67,8 @@ ynh_use_php () {
|
|||
# Create an alias for the specific version of PHP and a variable as fallback
|
||||
ynh_php="$php_path/php"
|
||||
alias ynh_php="$ynh_php"
|
||||
# And gem
|
||||
ynh_gem="$php_path/gem"
|
||||
alias ynh_gem="$ynh_gem"
|
||||
|
||||
ynh_fpm_conf="$php_version_path/$YNH_APP_INSTANCE_NAME/etc/php-fpm.d/$YNH_APP_INSTANCE_NAME.conf"
|
||||
|
||||
ynh_fpm_service="$php_version_path/$YNH_APP_INSTANCE_NAME/etc/systemd/system/php-fpm.service"
|
||||
|
||||
rm -f "$php_version_path/$YNH_APP_INSTANCE_NAME/etc/php-fpm.d/www.conf"
|
||||
ynh_fpm_conf="$php_version_path/$php_version/etc/php-fpm.d/$YNH_APP_INSTANCE_NAME.conf"
|
||||
|
||||
# Load the path of this version of PHP in $PATH
|
||||
if [[ :$PATH: != *":$php_path"* ]]; then
|
||||
|
@ -124,8 +78,9 @@ ynh_use_php () {
|
|||
ynh_php_load_path="PATH=$PATH"
|
||||
|
||||
# Sets the local application-specific PHP version
|
||||
(cd $final_path
|
||||
phpenv local $php_version)
|
||||
pushd $final_path
|
||||
phpenv local $php_version
|
||||
popd
|
||||
}
|
||||
|
||||
# Install a specific version of PHP
|
||||
|
@ -155,12 +110,6 @@ ynh_install_php () {
|
|||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
# Store php_version into the config of this app
|
||||
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=php_version --value=$php_version
|
||||
|
||||
# Create $phpenv_install_dir if doesn't exist already
|
||||
mkdir -p "$phpenv_install_dir/plugins/php-build"
|
||||
|
||||
# Install required dependencies
|
||||
ynh_add_app_dependencies --package="$phpenv_dependencies"
|
||||
|
||||
|
@ -171,29 +120,80 @@ ynh_install_php () {
|
|||
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
||||
|
||||
# Move an existing PHP binary, to avoid to block phpenv
|
||||
test -x /usr/bin/PHP && mv /usr/bin/PHP /usr/bin/php_phpenv
|
||||
# test -x /usr/bin/PHP && mv /usr/bin/PHP /usr/bin/php_phpenv
|
||||
|
||||
# If phpenv is not previously setup, install it
|
||||
if ! type phpenv > /dev/null 2>&1
|
||||
then
|
||||
ynh_install_phpenv
|
||||
elif dpkg --compare-versions "$($phpenv_install_dir/bin/phpenv --version | cut -d" " -f2)" lt $phpenv_version
|
||||
then
|
||||
ynh_install_phpenv
|
||||
elif dpkg --compare-versions "$($phpenv_install_dir/plugins/php-build/bin/php-build --version | cut -d" " -f2)" lt $php_build_version
|
||||
then
|
||||
ynh_install_phpenv
|
||||
# Instal or update phpenv
|
||||
phpenv="$(command -v phpenv $phpenv_install_dir/bin/phpenv | head -1)"
|
||||
if [ -n "$phpenv" ]; then
|
||||
ynh_print_info --message="phpenv already seems installed in \`$phpenv'."
|
||||
pushd "${phpenv%/*}"
|
||||
if git remote -v 2>/dev/null | grep -q phpenv; then
|
||||
echo "Trying to update with git..."
|
||||
git pull --tags origin master
|
||||
cd ..
|
||||
ynh_php_try_bash_extension
|
||||
fi
|
||||
popd
|
||||
else
|
||||
ynh_print_info --message="Installing phpenv with git..."
|
||||
mkdir -p $phpenv_install_dir
|
||||
pushd $phpenv_install_dir
|
||||
git init
|
||||
git remote add -f -t master origin https://github.com/sptndc/phpenv.git
|
||||
git checkout -b master origin/master
|
||||
ynh_php_try_bash_extension
|
||||
phpenv=$phpenv_install_dir/bin/phpenv
|
||||
popd
|
||||
fi
|
||||
|
||||
php_build="$(command -v "$phpenv_install_dir"/plugins/*/bin/phpenv-install phpenv-install | head -1)"
|
||||
|
||||
echo
|
||||
if [ -n "$php_build" ]; then
|
||||
ynh_print_info --message="\`phpenv install' command already available in \`$php_build'."
|
||||
pushd "${php_build%/*}"
|
||||
if git remote -v 2>/dev/null | grep -q php-build; then
|
||||
ynh_print_info --message="Trying to update with git..."
|
||||
git pull origin master
|
||||
fi
|
||||
popd
|
||||
else
|
||||
ynh_print_info --message="Installing php-build with git..."
|
||||
mkdir -p "${phpenv_install_dir}/plugins"
|
||||
git clone https://github.com/php-build/php-build.git "${phpenv_install_dir}/plugins/php-build"
|
||||
fi
|
||||
|
||||
git clone --depth 1 "https://github.com/madumlao/phpenv-aliases.git" "${phpenv_install_dir}/plugins/phpenv-aliases"
|
||||
git clone --depth 1 "https://github.com/ngyuki/phpenv-composer.git" "${phpenv_install_dir}/plugins/phpenv-composer"
|
||||
git clone --depth 1 "https://github.com/momo-lab/xxenv-latest.git" "${phpenv_install_dir}/plugins/xxenv-latest"
|
||||
|
||||
# Enable caching
|
||||
mkdir -p "${phpenv_install_dir}/cache"
|
||||
|
||||
# Create shims directory if needed
|
||||
mkdir -p "${phpenv_install_dir}/shims"
|
||||
|
||||
# Restore /usr/local/bin in PATH
|
||||
PATH=$CLEAR_PATH
|
||||
|
||||
# And replace the old PHP binary
|
||||
test -x /usr/bin/php_phpenv && mv /usr/bin/php_phpenv /usr/bin/PHP
|
||||
# test -x /usr/bin/php_phpenv && mv /usr/bin/php_phpenv /usr/bin/PHP
|
||||
|
||||
# Install the requested version of PHP
|
||||
ynh_print_info --message="Installation of PHP-"$php_version
|
||||
phpenv install --skip-existing $php_version
|
||||
local final_php_version=$(phpenv latest --print $php_version)
|
||||
ynh_print_info --message="Installation of PHP-$final_php_version"
|
||||
phpenv install --skip-existing $final_php_version
|
||||
ynh_replace_string --match_string="user = nobody" --replace_string="user = www-data" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
ynh_replace_string --match_string="group = nobody" --replace_string="group = www-data" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
ynh_replace_string --match_string="listen = 127.0.0.1:9000" --replace_string="listen = /run/php/php$final_php_version-fpm.sock" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$php_version_path/$final_php_version/etc/php-fpm.d/www.conf"
|
||||
|
||||
# Store php_version into the config of this app
|
||||
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=php_version --value=$final_php_version
|
||||
|
||||
# Remove app virtualenv
|
||||
if `phpenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME" 1>/dev/null 2>&1`
|
||||
|
@ -201,14 +201,17 @@ ynh_install_php () {
|
|||
phpenv alias $YNH_APP_INSTANCE_NAME --remove
|
||||
fi
|
||||
|
||||
# Create app virtualenv
|
||||
phpenv alias $YNH_APP_INSTANCE_NAME $php_version
|
||||
|
||||
# Cleanup PHP versions
|
||||
ynh_cleanup_php
|
||||
|
||||
# Create app virtualenv
|
||||
phpenv alias $YNH_APP_INSTANCE_NAME $php_version
|
||||
# phpenv alias $YNH_APP_INSTANCE_NAME $final_php_version
|
||||
|
||||
# Install php-fpm service
|
||||
cp -f "$php_version_path/$final_php_version/etc/systemd/system/php-fpm.service" "/etc/systemd/system/php$final_php_version-fpm.service"
|
||||
systemctl enable php$final_php_version-fpm --quiet
|
||||
systemctl daemon-reload
|
||||
systemctl start php$final_php_version-fpm
|
||||
|
||||
# Set environment for PHP users
|
||||
echo "#phpenv
|
||||
|
@ -235,8 +238,6 @@ ynh_remove_php () {
|
|||
# Remove /usr/local/bin in PATH in case of PHP prior installation
|
||||
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
||||
|
||||
phpenv alias $YNH_APP_INSTANCE_NAME --remove
|
||||
|
||||
# Remove the line for this app
|
||||
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=php_version
|
||||
|
||||
|
@ -253,7 +254,7 @@ ynh_remove_php () {
|
|||
# usage: ynh_cleanup_php
|
||||
ynh_cleanup_php () {
|
||||
|
||||
# List required PHP version
|
||||
# List required PHP versions
|
||||
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
|
||||
local required_php_versions=""
|
||||
for installed_app in $installed_apps
|
||||
|
@ -265,14 +266,18 @@ ynh_cleanup_php () {
|
|||
fi
|
||||
done
|
||||
|
||||
# Remove no more needed PHP version
|
||||
# Remove no more needed PHP versions
|
||||
local installed_php_versions=$(phpenv versions --bare --skip-aliases | grep -Ev '/')
|
||||
for installed_php_version in $installed_php_versions
|
||||
do
|
||||
if ! `echo ${required_php_versions} | grep "${installed_php_version}" 1>/dev/null 2>&1`
|
||||
then
|
||||
ynh_print_info --message="Removing of PHP-"$installed_php_version
|
||||
ynh_print_info --message="Removing of PHP-$installed_php_version"
|
||||
systemctl stop php$installed_php_version-fpm
|
||||
systemctl disable php$installed_php_version-fpm --quiet
|
||||
ynh_secure_remove --file="/etc/systemd/system/php$installed_php_version-fpm.service"
|
||||
$phpenv_install_dir/bin/phpenv uninstall --force $installed_php_version
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -280,7 +285,7 @@ ynh_cleanup_php () {
|
|||
if [[ ! $required_php_versions ]]
|
||||
then
|
||||
# Remove phpenv environment configuration
|
||||
ynh_print_info --message="Removing of phpenv-"$phpenv_version
|
||||
ynh_print_info --message="Removing of phpenv"
|
||||
ynh_secure_remove --file="$phpenv_install_dir"
|
||||
rm /etc/profile.d/phpenv.sh
|
||||
fi
|
||||
|
@ -289,15 +294,10 @@ ynh_cleanup_php () {
|
|||
|
||||
ynh_add_fpm_config () {
|
||||
ynh_use_php
|
||||
|
||||
ynh_add_config --template="../conf/php-fpm.conf" --destination="$ynh_fpm_conf"
|
||||
ln -s $ynh_fpm_service /etc/systemd/system/$app.service
|
||||
service $app start
|
||||
}
|
||||
|
||||
ynh_remove_fpm_config () {
|
||||
ynh_use_php
|
||||
|
||||
ynh_remove_systemd_config
|
||||
rm /etc/systemd/system/$app.service
|
||||
ynh_secure_remove --file="$ynh_fpm_conf"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue