Skip to content

Commit 740885e

Browse files
committed
fix: Enhance Composer installation process by setting environment variables and ensuring /app directory is writable for www-data user.
1 parent 31b3789 commit 740885e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

docker/init.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,33 @@ echo -e "${GREEN}Setup completed.${NC}"
4848
if [ -f "/app/composer.json" ] && [ ! -d "/app/vendor" ]; then
4949
echo -e "${YELLOW}Installing Composer dependencies...${NC}"
5050

51+
# Set up composer environment variables for www-data user
52+
export HOME=/var/www
53+
export COMPOSER_HOME=/var/www/.composer
54+
export COMPOSER_CACHE_DIR=/var/www/.composer/cache
55+
56+
# Create composer cache directory and set ownership
57+
echo -e "${YELLOW}Setting up composer cache...${NC}"
58+
mkdir -p /var/www/.composer/cache
59+
chown -R www-data:www-data /var/www/.composer
60+
61+
# Make /app writable by www-data (critical for mounted volumes)
62+
echo -e "${YELLOW}Ensuring /app is writable...${NC}"
63+
chmod 777 /app
64+
5165
# Install dependencies based on environment AS www-data user
5266
if [ "$YII_ENV" = "prod" ]; then
5367
# Production: exclude dev dependencies and optimize autoloader
54-
gosu www-data composer install --no-dev --optimize-autoloader --no-interaction
68+
gosu www-data env HOME=/var/www COMPOSER_HOME=/var/www/.composer COMPOSER_CACHE_DIR=/var/www/.composer/cache \
69+
composer install --no-dev --optimize-autoloader --no-interaction
5570
else
5671
# Development: include dev dependencies
57-
gosu www-data composer install --optimize-autoloader --no-interaction
72+
gosu www-data env HOME=/var/www COMPOSER_HOME=/var/www/.composer COMPOSER_CACHE_DIR=/var/www/.composer/cache \
73+
composer install --optimize-autoloader --no-interaction
5874
fi
5975

6076
echo -e "${GREEN}✓ Composer dependencies installed successfully.${NC}"
77+
echo -e "${GREEN}✓ Both vendor/ and node_modules/ should have correct permissions.${NC}"
6178
fi
6279

6380
echo -e "${GREEN}Starting supervisord...${NC}"

0 commit comments

Comments
 (0)