# This file is part of: PHP Development Template Stack 
# Copyright (c) 2024 Nico Jan Eelhart
#
# This source code is licensed under the MIT License found in the  'LICENSE.md' file in the root directory of this source tree.
#


# Base image Apache 
# Debian 12 with Apache 2.4 supporting PHP 8.2 by default
FROM httpd:bookworm		

# 1) INSTALL PHP and other required software
RUN apt-get update && \
    apt-get install -y software-properties-common curl git wget && \
    apt-get update && \
    apt-get install -y php8.2 php8.2-fpm php8.2-mbstring php8.2-xml php8.2-curl php8.2-dom php8.2-cli php8.2-mysql php8.2-xdebug nano net-tools iputils-ping && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 2) Add PHP repository (if not already added)
RUN wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add - && \
    echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list && \
    apt-get update

# 3) Explicitly Install PHP 8.2 (to prevent fetching PHP 8.3 if available)
RUN apt-get install -y php8.2 php8.2-fpm php8.2-mbstring php8.2-xml php8.2-curl php8.2-dom php8.2-cli php8.2-mysql php8.2-xdebug && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 3) Copy configuration files
COPY shared-container-files/start.* /usr/local/apache2/
COPY shared-container-files/httpd.conf /usr/local/apache2/conf/
COPY shared-container-files/httpd-vhosts.conf /usr/local/apache2/conf/extra/

# 4) Add Composer
RUN wget -O composer-setup.php https://getcomposer.org/installer
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer

# 5) Install Symfony
RUN curl -sS https://get.Symfony.com/cli/installer | bash \
    && mv /root/.symfony5/bin/symfony /usr/local/bin/symfony

# 6) see WARNING 1 in compose file!   Docker using mount bind is horrible Slow in symfony!! 
# 6.1) Symfony App
COPY app-symfony /usr/local/apache2/htdocs

# 6.2 Raw-app)
COPY app-raw /usr/local/apache2/htdocs

#6.3 Update file owner and user rights
RUN chown -R www-data  /usr/local/apache2/htdocs
RUN chmod 755 -R /usr/local/apache2/htdocs

# 6.4 Install composer libraries for Symfony project
WORKDIR /usr/local/apache2/htdocs/symfony-apps/wiki-store
RUN composer install

# Reset to general project dir
WORKDIR /usr/local/apache2/htdocs

# Expose ports
EXPOSE 8071
EXPOSE 9000
EXPOSE 9003

						#End Docker file 



# SAMPLES
# 1)	Search and replacesample 
# 		RUN sed -i 's/^#LoadModule\ mpm_prefork_module/LoadModule\ mpm_prefork_module/' /usr/local/apache2/conf/httpd.conf-
# 2)	Commit the image under new name
# 		exit
# 		docker commit my_container compose_apache_php_cont_php7:latest
#
# HANDY. To find out if package exists, and related packages, use something like this:
# CMD:	'apt-cache search php7.4' Or
#		'apt-cache search php5.*'

