# Dockerfile for PHP/Apache Backend
FROM php:8.2-apache
# Install necessary PHP extensions and tools
RUN apt-get update && apt-get install -y \
nano \
libpq-dev \
git \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libzip-dev \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd zip bcmath intl pdo pdo_pgsql pgsql
# Enable Apache rewrite module
RUN a2enmod rewrite
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Copy application code to the container
COPY ./ /var/www/html/yesware/
# Copy .env.example to .env
RUN cp /var/www/html/yesware/backend/.env.example /var/www/html/yesware/backend/.env
# Set Apache config for serving React frontend on port 8000
RUN echo "\
\
ServerAdmin webmaster@localhost \
DocumentRoot /var/www/html/yesware/frontend/build \
\
Options Indexes FollowSymLinks MultiViews \
AllowOverride All \
Require all granted \
RewriteEngine On \
RewriteCond %{REQUEST_FILENAME} !-f \
RewriteRule ^ index.html [L] \
\
ErrorLog /var/log/apache2/frontend_error.log \
CustomLog /var/log/apache2/frontend_access.log combined \
" > /etc/apache2/sites-available/frontend.conf
# Set Apache config for serving Laravel backend on port 80
RUN echo "\
\
ServerAdmin webmaster@localhost \
Alias /backend /var/www/html/yesware/backend/public \
\
Options Indexes FollowSymLinks MultiViews \
AllowOverride All \
Require all granted \
RewriteEngine On \
RewriteBase /backend \
RewriteRule ^backend/(.*)$ $1 [L,PT] \
RewriteCond %{REQUEST_FILENAME} !-d \
RewriteCond %{REQUEST_FILENAME} !-f \
RewriteRule ^ index.php [L] \
\
ErrorLog /var/log/apache2/backend_error.log \
CustomLog /var/log/apache2/backend_access.log combined \
" > /etc/apache2/sites-available/backend.conf
# Enable the virtual hosts
RUN a2ensite frontend.conf
RUN a2ensite backend.conf