diff --git a/Dockerfile b/Dockerfile index 62457018..6f05543d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.4-fpm +FROM php:8.2-fpm LABEL org.opencontainers.image.authors="stephen@stephenneal.net" # Update OS && install utilities @@ -37,4 +37,40 @@ RUN docker-php-ext-configure intl \ # Copy PHP configuration files COPY local.ini /usr/local/etc/php/conf.d/local.ini -COPY www.conf /usr/local/etc/php-fpm.d/www.conf \ No newline at end of file +COPY www.conf /usr/local/etc/php-fpm.d/www.conf + +# Set working directory +WORKDIR /var/www/html + +# Install Nginx +RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/* + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# Copy application skeleton (respects .dockerignore) +# Ensure .dockerignore is set up to exclude vendor, node_modules, .env etc. +COPY . . + +# Install PHP dependencies +RUN composer install --optimize-autoloader --no-dev --no-interaction --no-progress + +# Set permissions for Laravel +RUN chown -R www-data:www-data storage bootstrap/cache \ + && chmod -R 775 storage bootstrap/cache + +# Copy Nginx site configuration +# This assumes nginx-site.conf is for Nginx and configured for Laravel +COPY nginx-site.conf /etc/nginx/sites-available/default +RUN ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default || true \ + && rm /etc/nginx/sites-enabled/default.conf || true # Remove default Nginx config if it exists with this name + +# Copy deploy script (which handles migrations, caching) +COPY deploy.sh /usr/local/bin/deploy.sh +RUN chmod +x /usr/local/bin/deploy.sh + +# Expose port 80 for Nginx +EXPOSE 80 + +# CMD / ENTRYPOINT to start supervisor (which then starts nginx and php-fpm) will be added later. +# Frontend asset compilation (Node.js multi-stage build) will also be added later. diff --git a/local.ini b/local.ini new file mode 100644 index 00000000..c9d7a804 --- /dev/null +++ b/local.ini @@ -0,0 +1,25 @@ +; Custom PHP settings for production + +; Error reporting +display_errors = Off +log_errors = On +error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT + +; Performance and Security +expose_php = Off +max_execution_time = 60 ; Increased for potentially longer scripts +memory_limit = 256M ; Adjust based on your application's needs +post_max_size = 32M ; Max size for POST requests +upload_max_filesize = 32M ; Max upload file size +date.timezone = "UTC" ; Set your preferred timezone + +; Opcache (ensure opcache extension is enabled in Dockerfile) +opcache.enable=1 +opcache.enable_cli=1 +opcache.memory_consumption=128 +opcache.interned_strings_buffer=8 +opcache.max_accelerated_files=10000 +opcache.revalidate_freq=0 ; Set to 0 for production (validate on every request if timestamp changed) or a higher value +opcache.validate_timestamps=1 ; Check timestamps in production +opcache.save_comments=1 +opcache.fast_shutdown=1 diff --git a/www.conf b/www.conf new file mode 100644 index 00000000..a4e8c04a --- /dev/null +++ b/www.conf @@ -0,0 +1,22 @@ +[www] +user = www-data +group = www-data +listen = /var/run/php-fpm.sock +;listen = 127.0.0.1:9000 +listen.owner = www-data +listen.group = www-data +listen.mode = 0660 + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +pm.max_requests = 500 + +chdir = /var/www/html + +catch_workers_output = yes +php_flag[display_errors] = off +php_admin_value[error_log] = /var/log/fpm-php.www.log +php_admin_flag[log_errors] = on