Write a Dockerfile for php-8 apache that runs wordpress and laravel

  docker, laravel, php

I want to integrate WordPress with Laravel. I am building a Dockerfile FROM php:8.0-apache as below:

FROM php:8.0-apache

RUN apt-get update && apt-get install -y  
    libfreetype6-dev 
    libjpeg-dev 
    libpng-dev 
    libwebp-dev 
    --no-install-recommends 
    && docker-php-ext-enable opcache 
    && docker-php-ext-configure gd --with-freetype --with-jpeg 
    && docker-php-ext-install pdo_mysql -j$(nproc) gd 
    && apt-get autoclean -y 
    && rm -rf /var/lib/apt/lists/* 

# Update apache conf to point to application public directory
ENV APACHE_DOCUMENT_ROOT=/var/www/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Update uploads config
RUN echo "file_uploads = Onn" 
         "memory_limit = 1024Mn" 
         "upload_max_filesize = 512Mn" 
         "post_max_size = 512Mn" 
         "max_execution_time = 1200n" 
         > /usr/local/etc/php/conf.d/uploads.ini

# Enable headers module
RUN a2enmod rewrite headers 

docker-compose.yml

version: '3.8'

services:

    mycontainer:
        build:
            context: .
        working_dir: /var/www
        image: myimg
        container_name: mycontainer
        ports:
            - 8005:80
        volumes:
            - ./:/var/www
            

Here is what I see on http://localhost:8005

Forbidden
You don't have permission to access this resource.

Apache/2.4.51 (Debian) Server at localhost Port 8005

Here is the structure of my files and folders

 - laravel   # folder
 - wordpress # folder
 - .htaccess
 - docker-compose.yml
 - Dockerfile
 - index.php
 - .htaccess

Source: Laravel

Leave a Reply