Docker Environment
Docker provides a consistent environment for building, shipping, and running applications. Prisma PHP leverages Docker to create a seamless development workflow, ensuring reliable execution across different environments.
Setting Up
Install Docker
Ensure you have Docker and Docker Compose installed. Download them from Docker Desktop.
Initialize Configuration
If you didn't select Docker during project creation, run the update command to scaffold the files:
npx php update project
Start Containers
Start the environment. This will build containers and download images (may take time on first run).
npm run dev
Access Application
App running at http://localhost:3000.
- External:
localhost:3306 - Internal:
db:3306
Configuration Files
Detailed breakdown of the configuration files used to orchestrate the environment.
.dockerignore
Specifies files excluded from the build context to keep images light.
node_modules/
vendor/
apache.conf
Configures the virtual host, document root, and enables .htaccess overrides.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
docker-compose.yml
Orchestrates the web (Apache/PHP) and db (MySQL) services.
version: "3.8"
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
volumes:
- .:/var/www/html
depends_on:
- db
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: prisma_php
MYSQL_DATABASE: prisma_php
ports:
- "3306:3306"
Dockerfile
Builds the PHP image, installs extensions (PDO MySQL, Zip), enables mod_rewrite, and sets up Composer.
# Use an official PHP image with the version you need
FROM php:8.1-apache
# Install system dependencies for Composer and PHP extensions
RUN apt-get update && apt-get install -y \
git \
unzip \
libzip-dev \
zip \
&& docker-php-ext-install pdo_mysql zip
# Enable Apache mods
RUN a2enmod rewrite headers
# Install Composer globally
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# Set the working directory in the container
WORKDIR /var/www/html
# Copy the application's composer.json and lock file
COPY composer.json composer.lock ./
# Install PHP dependencies
RUN composer install --no-scripts --no-autoloader
# Copy the rest of the application
COPY . .
# Finish composer
RUN composer dump-autoload --optimize
# Apache config
COPY ./apache.conf /etc/apache2/sites-available/000-default.conf
# Expose port 80 to access the container
EXPOSE 80
# Command to run when starting the container
CMD ["apache2-foreground"]