When I first used Grav, “a modern open source flat-file CMS,” to host this site, I setup a local development environment using macOS’s built-in Apache and PHP. But this is getting harder with each macOS release, so it’s time to use a Docker container instead.
For example with macOS Catalina, first we need to Enable PHP in Apache. Then, after installing Grav locally, we have to workaround PHP ZIP Extension and fix the Grav Admin Panel URL redirect. That is a lot of work for every macOS release, so I’m not even got going to try this on Big Sur moving forward!
With the release of Grav v1.7 three days ago (19 Jan 21), I thought it would be easier to use a container to test this version, because there are some major changes including the requirement for PHP 7.3.6+. Well... it wasn’t so easy.
I backed up my entire Grav site (running an older version). I replaced
.htacess with the default version from the latest Grav Core + Admin plugin package, and deleted customized
Next, I created a container from the Docker Official PHP + Apache Image and,
COPY-ied my Grav files to
On first run - I got a Grav page like this with three issues:
- PHP GD Image Manipulation Library
gdand PHP Zip extension are both not installed.
mod_rewriteis not installed.
Figured that I needed to
docker-php-ext-install the extensions, but got compile errors...libraries missing too. After a bit of Googling, figured out which
-dev libraries had to be installed first.
Tried again, and the missing dependencies are resolved! But, this time, I got a Grav error
TypeError: abs():Argument #1 ($num) must be of type int|float, string given. I turned on the Grav setting to show more detailed errors by editing
/var/www/html/user/config/system.yaml and enabling:
errors: display: true
What’s this? Well it turns out the container
php:apache uses PHP v8 and there must be some issue the Grav code, because when I reverted to the required PHP v7.3.26... then, everything worked as expected! Huh.
FROM php:7.3.26-apache RUN apt update \ && apt install -y libpng-dev libzip-dev \ && docker-php-ext-install gd zip \ && a2enmod rewrite \ && cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" COPY grav/ /var/www/html
With this, I managed to log in to my Grav instance (
http://127.0.0.1:8080), and update the core to v1.7.x and all plugins successfully.
You might get into a loop trying to login to the admin page with
http://localhost:8080/admin because Apache complains that it
Could not reliably determine the server's fully qualified domain name... Set the 'ServerName' directive globally to suppress this message.
Don’t feel like being so verbose today, so:
- To build the image:
docker build -t grav .
- To start the container in the background:
docker run -d --name grav -p 8080:80 grav
- To get to a
bashshell in the running container:
docker exec -it grav bash
- To stop it:
docker stop grav
- To delete it
docker rm grav