# Use PHP 8.4 FPM
FROM php:8.4-fpm

# --------------------------
# Install system dependencies
# --------------------------
RUN apt-get update && apt-get install -y \
    git \
    curl \
    zip \
    unzip \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    libzip-dev \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# --------------------------
# Install PHP extensions
# --------------------------
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip

# --------------------------
# Install Composer globally
# --------------------------
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# --------------------------
# Setup temporary directory permissions
# --------------------------
RUN chmod 1777 /tmp

# --------------------------
# Set working directory
# --------------------------
WORKDIR /var/www

# প্রথমে ফোল্ডারগুলো তৈরি করুন এবং তারপর পারমিশন দিন
RUN mkdir -p /var/www/storage /var/www/bootstrap/cache && \
    chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache && \
    chmod -R 775 /var/www/storage /var/www/bootstrap/cache

# We do this at runtime or via the Dockerfile if the files exist
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache

# Switch to the non-root user provided by the PHP image
USER www-data

# --------------------------
# Default command
# --------------------------
CMD ["php-fpm"]