Skip to content

Composer: PATH Issues when updating #6543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions misc/tools.func
Original file line number Diff line number Diff line change
Expand Up @@ -492,39 +492,50 @@ function setup_php() {
fi
fi
}

# ------------------------------------------------------------------------------
# Installs or updates Composer globally.
# Installs or updates Composer globally (robust, idempotent).
#
# Description:
# - Downloads latest version from getcomposer.org
# - Installs to /usr/local/bin/composer
# - Installs to /usr/local/bin/composer
# - Removes old binaries/symlinks in /usr/bin, /bin, /root/.composer, etc.
# - Ensures /usr/local/bin is in PATH (permanent)
# ------------------------------------------------------------------------------

function setup_composer() {
local COMPOSER_BIN="/usr/local/bin/composer"
export COMPOSER_ALLOW_SUPERUSER=1

# Clean up old Composer binaries/symlinks (if any)
for old in /usr/bin/composer /bin/composer /root/.composer/vendor/bin/composer; do
[[ -e "$old" && "$old" != "$COMPOSER_BIN" ]] && rm -f "$old"
done

# Ensure /usr/local/bin is in PATH for future logins (and current shell)
ensure_usr_local_bin_persist
export PATH="/usr/local/bin:$PATH"

# Check if composer is already installed
if [[ -x "$COMPOSER_BIN" ]]; then
local CURRENT_VERSION
CURRENT_VERSION=$("$COMPOSER_BIN" --version | awk '{print $3}')
$STD msg_info "Old Composer $CURRENT_VERSION found, updating to latest"
else
msg_info "Setup Composer"
msg_info "Installing Composer"
fi

# Download and install latest composer
# Download and install latest Composer
curl -fsSL https://getcomposer.org/installer -o /tmp/composer-setup.php
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer >/dev/null 2>&1

if [[ $? -ne 0 ]]; then
msg_error "Failed to install Composer"
if [[ ! -x "$COMPOSER_BIN" ]]; then
msg_error "Composer was not successfully installed (no binary at $COMPOSER_BIN)"
return 1
fi

chmod +x "$COMPOSER_BIN"
$STD composer diagnose
msg_ok "Setup Composer"
$STD "$COMPOSER_BIN" self-update --no-interaction || true # safe if already latest
$STD "$COMPOSER_BIN" diagnose
msg_ok "Composer is ready at $COMPOSER_BIN"
}

# ------------------------------------------------------------------------------
Expand Down