Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/php/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "php",
"version": "1.1.1",
"version": "1.1.2",
"name": "PHP",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/php",
"options": {
Expand All @@ -10,7 +10,8 @@
"latest",
"8",
"8.2",
"8.2.0"
"8.2.0",
"none"
],
"default": "latest",
"description": "Select or enter a PHP version"
Expand Down
110 changes: 60 additions & 50 deletions src/php/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,38 +123,13 @@ find_version_from_git_tags() {

# Install PHP Composer
addcomposer() {
"${PHP_INSTALL_DIR}/bin/php" -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
"${PHP_SRC}" -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
"${PHP_INSTALL_DIR}/bin/php" -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
"${PHP_INSTALL_DIR}/bin/php" composer-setup.php
"${PHP_INSTALL_DIR}/bin/php" -r "unlink('composer-setup.php');"

mv composer.phar "${PHP_INSTALL_DIR}/bin/composer"
"${PHP_SRC}" -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
"${PHP_SRC}" composer-setup.php --install-dir="/usr/local/bin" --filename=composer
"${PHP_SRC}" -r "unlink('composer-setup.php');"
}

# Install PHP if it's missing


# Persistent / runtime dependencies
RUNTIME_DEPS="wget ca-certificates git build-essential xz-utils"

# PHP dependencies
PHP_DEPS="libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"

. /etc/os-release

if [ "${VERSION_CODENAME}" = "bionic" ]; then
PHP_DEPS="${PHP_DEPS} libargon2-0-dev"
else
PHP_DEPS="${PHP_DEPS} libargon2-dev"
fi

# Dependencies required for running "phpize"
PHPIZE_DEPS="autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"

# Install dependencies
check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS

install_php() {
PHP_VERSION="$1"
PHP_INSTALL_DIR="${PHP_DIR}/${PHP_VERSION}"
Expand Down Expand Up @@ -216,30 +191,48 @@ install_php() {
echo "xdebug.mode = debug" >> "${XDEBUG_INI}"
echo "xdebug.start_with_request = yes" >> "${XDEBUG_INI}"
echo "xdebug.client_port = 9003" >> "${XDEBUG_INI}"
}

# Install PHP Composer if needed
if [[ "${INSTALL_COMPOSER}" = "true" ]] || [[ $(composer --version) = "" ]]; then
addcomposer
fi
if [ "${PHP_VERSION}" != "none" ]; then
# Persistent / runtime dependencies
RUNTIME_DEPS="wget ca-certificates git build-essential xz-utils"

CURRENT_DIR="${PHP_DIR}/current"
if [[ ! -d "${CURRENT_DIR}" ]]; then
ln -s -r "${PHP_INSTALL_DIR}" ${CURRENT_DIR}
fi
# PHP dependencies
PHP_DEPS="libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"

if [ "${OVERRIDE_DEFAULT_VERSION}" = "true" ]; then
if [[ $(ls -l ${CURRENT_DIR}) != *"-> ${PHP_INSTALL_DIR}"* ]] ; then
rm "${CURRENT_DIR}"
ln -s -r "${PHP_INSTALL_DIR}" "${CURRENT_DIR}"
fi
. /etc/os-release

if [ "${VERSION_CODENAME}" = "bionic" ]; then
PHP_DEPS="${PHP_DEPS} libargon2-0-dev"
else
PHP_DEPS="${PHP_DEPS} libargon2-dev"
fi

rm -rf "${PHP_SRC_DIR}"
updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; fi"
}
# Dependencies required for running "phpize"
PHPIZE_DEPS="autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"

find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
install_php "${PHP_VERSION}"
# Install dependencies
check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS

find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
install_php "${PHP_VERSION}"

PHP_SRC="${PHP_INSTALL_DIR}/bin/php"
else
set +e
PHP_SRC=$(which php)
set -e
fi

# Install PHP Composer if needed
if [[ "${INSTALL_COMPOSER}" = "true" ]]; then
if [ -z "${PHP_SRC}" ]; then
echo "(!) Could not install Composer. PHP not found."
exit 1
fi

addcomposer
fi

# Additional php versions to be installed but not be set as default.
if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
Expand All @@ -253,9 +246,26 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
IFS=$OLDIFS
fi

chown -R "${USERNAME}:php" "${PHP_DIR}"
chmod -R g+r+w "${PHP_DIR}"
find "${PHP_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s
if [ "${PHP_VERSION}" != "none" ]; then
CURRENT_DIR="${PHP_DIR}/current"
if [[ ! -d "${CURRENT_DIR}" ]]; then
ln -s -r "${PHP_INSTALL_DIR}" ${CURRENT_DIR}
fi

if [ "${OVERRIDE_DEFAULT_VERSION}" = "true" ]; then
if [[ $(ls -l ${CURRENT_DIR}) != *"-> ${PHP_INSTALL_DIR}"* ]] ; then
rm "${CURRENT_DIR}"
ln -s -r "${PHP_INSTALL_DIR}" "${CURRENT_DIR}"
fi
fi

rm -rf "${PHP_SRC_DIR}"
updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; fi"

chown -R "${USERNAME}:php" "${PHP_DIR}"
chmod -R g+r+w "${PHP_DIR}"
find "${PHP_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s
fi

# Clean up
rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 2 additions & 0 deletions test/php/install_additional_php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ check "php version 8.1.4 installed as default" php --version | grep 8.1.4
check "php version 8.0.17 installed" ls -l /usr/local/php | grep 8.0.17
check "php version 8.0.3 installed" ls -l /usr/local/php | grep 8.0.3

check "composer-version" composer --version

# Report result
reportResults
10 changes: 10 additions & 0 deletions test/php/install_only_composer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

# Optional: Import test library
source dev-container-features-test-lib

check "composer-version" composer --version

# Report result
reportResults
1 change: 1 addition & 0 deletions test/php/install_php_8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib

check "php-version-8-is-installed" bash -c "php --version | grep '8.'"
check "composer-version" composer --version

# Report result
reportResults
1 change: 1 addition & 0 deletions test/php/install_php_8_2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib

check "php-version-8.2-is-installed" bash -c "php --version | grep '8.2'"
check "composer-version" composer --version

# Report result
reportResults
9 changes: 9 additions & 0 deletions test/php/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@
"version": "8.2"
}
}
},
"install_only_composer": {
"image": "mcr.microsoft.com/devcontainers/php:latest",
"features": {
"php": {
"version": "none",
"installComposer": true
}
}
}
}
2 changes: 1 addition & 1 deletion test/php/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source dev-container-features-test-lib

check "PHP version" php --version
check "Mbstring loaded" php -r "extension_loaded('mbstring') || throw new Error('Extension Mbstring is not loaded');"
check "Composer version" composer --version
check "composer-version" composer --version

# Report result
reportResults