node install | Install dev tools on Linux | | Search

This Dockerfile builds a PHP 7.0 Apache image with additional dependencies and configurations, including installing Composer, configuring Apache, and generating a self-signed SSL certificate. It also sets environment variables and copies web content and configuration files to the image, ultimately creating a customized PHP development environment.

Cell 2

FROM php:7.0-apache

RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN rm -rf /var/www/html/logs/* \
    && chown -R www-data:www-data /var/www/html

RUN a2enmod ssl
RUN a2enmod rewrite

RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -subj "/C=UK/ST=Warwickshire/L=Leamington/O=OrgName/OU=IT Department/CN=SCO-100001269.ad.swiftpage.com" -keyout /etc/ssl/private/mysitename.key -out /etc/ssl/private/mysitename.crt

COPY ./web /var/www/html
COPY ./site.conf.ini /etc/apache2/sites-enabled/000-default.conf

COPY chain.crt /etc/ssl/private/
COPY TrustedRoot.crt /etc/ssl/private/

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2

RUN echo "ServerName SCO-100001269.ad.swiftpage.com" >> /etc/apache2/apache2.conf
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR




What the code could have been:

bash
# Base image for PHP 7.0 with Apache
FROM php:7.0-apache

# Update and install dependencies
RUN apt-get update && apt-get install -y \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libpng12-dev \
  && docker-php-ext-install -j$(nproc) iconv mcrypt \
  && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
  && docker-php-ext-install -j$(nproc) gd \
  && apt-get clean -y

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
  && composer self-update

# Remove logs and reset ownership
RUN rm -rf /var/www/html/logs/* \
  && chown -R www-data:www-data /var/www/html

# Enable SSL and rewrite modules
RUN a2enmod ssl
RUN a2enmod rewrite

# Generate SSL certificate and key (TODO: Use a more secure method for generating the certificate)
# Note: The certificate and key are generated with default values for simplicity.
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -subj "/C=UK/ST=Warwickshire/L=Leamington/O=OrgName/OU=IT Department/CN=SCO-100001269.ad.swiftpage.com" -keyout /etc/ssl/private/mysitename.key -out /etc/ssl/private/mysitename.crt \
  && openssl x509 -in /etc/ssl/private/mysitename.crt -text -noout

# Copy application files and configuration
COPY./web /var/www/html
COPY./site.conf.ini /etc/apache2/sites-enabled/000-default.conf

# Copy SSL certificates
COPY chain.crt /etc/ssl/private/
COPY TrustedRoot.crt /etc/ssl/private/

# Set up environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2

# Configure Apache (TODO: Use a more secure method for setting the ServerName)
# Note: The ServerName is set with a default value for simplicity.
RUN echo "ServerName SCO-100001269.ad.swiftpage.com" >> /etc/apache2/apache2.conf

# Create directories for Apache
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR

Dockerfile Breakdown

The provided code is a Dockerfile that builds a PHP 7.0 Apache image with additional dependencies and configurations.

Section 1: Install Dependencies

Section 2: Install Composer

Section 3: Configure Apache

Section 4: Generate SSL Certificate

Section 5: Copy Files

Section 6: Set Environment Variables

Section 7: Configure Apache