Maybe are suffering like me, trying to run you PHP application that uses a .htaccess file to overwrite some URL on official PHP Docker image, in my case was using Laravel.
The problem? Well, I have to add some feature to and old app made in Laravel some year ago and I did using xampp, we are living in the future so now we have containers. I don’t be very good using Docker yet I think I have a lot to learn but I try my best.
I have a repository with a Docker configuration to run a PHP server with a mysql services that fit with my need to run the old app and work in the new features. The first problem that I have was to enable the directory where the Laravel app is, I solved this adding the volume to the docker-compose file
Great, now the app is available in the PHP server container, but there one thing left to fix, the mod_rewrite. This module doesn’t come enabled by default in php:x.x-apache image thus is have to be added to the Dockerfile configuration. So the Docker file it can look like this:
RUN docker-php-ext-install mysqli
RUN a2enmod rewrite
RUN service apache2 restart
We have to add the a2enmod to enable the mod_rewrite and restart the Apache server.
If you work with the image of Worpress for Docker and need to do something “out of the box” like connecting to the database that uses the WordPress image from a script that is not part of the WordPress theme it will not be possible because you need to install the MySQL pdo library in WordPress container.
To solve this we only need only two commands:
A command to install the pdo library that we need
A command to restart the WordPress container to load the new installed library
For some time I have wanted to leave MAMP to work on WordPress projects and use Docker, luckily this week I came across a tweet from Fran Piaggio where he shares a repository of Jared Palmer with a basic configuration of Docker to work on WordPress in 2019. In addition to the WordPress configuration Jared added a Webpack what is a very useful.
The repository of Jared encouraged me to take up my idea of having a WordPress configuration for my projects, so with that base I can be guided to create my own configuration that I call Dockerpress.
Unlike the Jared repository, it does not have Webpack configuration, since I use another configuration that you can find in Webpack Boilerplate repository, what I have added to it is a Mailhog as a service to catch test emails and an file for enviroment values.
I hope it is useful or a basis for your own configuration.