@@ -8,6 +8,12 @@ NC='\033[0m'
88
99echo -e " ${GREEN} Starting container setup...${NC} "
1010
11+ # Create necessary Caddy directories with proper permissions
12+ echo -e " ${YELLOW} Creating Caddy directories...${NC} "
13+ mkdir -p /data/caddy/locks /config/caddy
14+ chown -R www-data:www-data /data /config
15+ chmod -R 755 /data /config
16+
1117# Create necessary Yii2 directories if they don't exist
1218echo -e " ${YELLOW} Creating Yii2 directories...${NC} "
1319mkdir -p /app/runtime/cache
@@ -48,29 +54,34 @@ echo -e "${GREEN}Setup completed.${NC}"
4854if [ -f " /app/composer.json" ] && [ ! -d " /app/vendor" ]; then
4955 echo -e " ${YELLOW} Installing Composer dependencies...${NC} "
5056
51- # Install dependencies based on environment
57+ # Give www-data write access without exposing the tree to everyone
58+ chown -R www-data:www-data /app && \
59+ chmod -R u+rwX,g+rwX /app
60+
61+ # Create and configure npm cache directory for www-data
62+ mkdir -p /var/www/.npm
63+ chown -R www-data:www-data /var/www/.npm
64+
65+ # Install dependencies with proper environment variables
5266 if [ " $YII_ENV " = " prod" ]; then
5367 # Production: exclude dev dependencies and optimize autoloader
54- composer install --no-dev --optimize-autoloader --no-interaction
68+ gosu www-data env \
69+ HOME=/var/www \
70+ COMPOSER_HOME=/var/www/.composer \
71+ COMPOSER_CACHE_DIR=/var/www/.composer/cache \
72+ npm_config_cache=/var/www/.npm \
73+ composer install --no-dev --optimize-autoloader --no-interaction
5574 else
5675 # Development: include dev dependencies
57- composer install --optimize-autoloader --no-interaction
58- fi
59-
60- # Set proper ownership for vendor directory if possible
61- if chown -R www-data:www-data /app/vendor 2> /dev/null ; then
62- echo -e " ${GREEN} ✓ Vendor directory ownership set ${NC} "
76+ gosu www-data env \
77+ HOME=/var/www \
78+ COMPOSER_HOME=/var/www/.composer \
79+ COMPOSER_CACHE_DIR=/var/www/.composer/cache \
80+ npm_config_cache=/var/www/.npm \
81+ composer install --optimize-autoloader --no-interaction
6382 fi
6483
65- echo -e " ${GREEN} ✓ Composer dependencies installed successfully.${NC} "
66- fi
67-
68- # Set permissions for node_modules directory if it exists
69- if chown -R www-data:www-data /app/node_modules 2> /dev/null; then
70- chmod -R 775 /app/node_modules
71- echo -e " ${GREEN} ✓ Node modules directory ownership set${NC} "
72- else
73- echo -e " ${YELLOW} ⚠ Node modules directory ownership could not be set (mounted volume?)${NC} "
84+ echo -e " ${GREEN} ✓ Composer dependencies installed successfully${NC} "
7485fi
7586
7687echo -e " ${GREEN} Starting supervisord...${NC} "
0 commit comments