#!/bin/sh

set -e

echo "Creating new Symfony project..."

# Create project
symfony new /var/www/html --version=$SYMFONY_VERSION --no-git

# Create necessary directories
mkdir -p /var/www/html/var/cache /var/www/html/var/log /var/www/html/var/sessions

# Set www-data group ownership and permissions
chgrp -R www-data /var/www/html
chmod -R 775 /var/www/html
chmod -R g+s /var/www/html/var  # Group sticky bit so new files inherit group

# Ensure public directory exists (should be created by Symfony)
if [ ! -d "/var/www/html/public" ]; then
    echo "Warning: public directory not found, creating it..."
    mkdir -p /var/www/html/public
    echo "<?php phpinfo();" > /var/www/html/public/index.php
fi

echo "Starting Apache..."
# Start Apache in foreground
apache2-foreground
