Add PHP in Base Image List - Balena Documentation

PHP images. There isn’t any PHP variant of raspberrypi3 in balena.io bas lit
https://www.balena.io/docs/reference/base-images/base-images-ref/
Is see a way to build php from dockerhub but I’m stuck on it, re2c won’t resolve on ARM. So I use the intel-nuc image to build with and debian buster-build with php on a RaspberryPi machine.

ARG IMG_TAG
FROM library/php:${IMG_TAG:-latest} as php 
ARG DEBIAN_FRONTEND=noninteractive
FROM balenalib/intel-nuc-debian:buster-build
RUN [ "cross-build-start" ]

# prevent Debian's PHP packages from being installed
# https://github.com/docker-library/php/pull/542
RUN set -eux; \
{ \
	echo 'Package: php*'; \
	echo 'Pin: release *'; \
	echo 'Pin-Priority: -1'; \
} > /etc/apt/preferences.d/no-debian-php

# dependencies required for running "phpize"
# (see persistent deps below)
ENV PHPIZE_DEPS \
	autoconf \
	dpkg-dev \
	file \
	g++ \
	gcc \
	libc-dev \
	make \
	pkg-config \
	re2c

This is cross-build x86_64 on ARM, I would try the other way but It looks impossible due to re2c and maybe other dependencies…

Was anybody ever able to build php from balenalib images ? I wish to add basic php support to the base image pool.

I wish to add basic php support to the base image pool.

This is awesome, and I personally think it’s a good idea to support PHP.

I went a different route, and I used our Debian base-image then just apt-get install -y php7.3 ... to get a working PHP environment. Is there any reason you need to use phpize?

Without phpize, I must change my build file… Why is it sitting there, because I googled for a docker image running Apache 2 + PHP 7, which has got various extensions built-in. Apache2 is my preferred Web server, it’s easy to configure. I have to deploy a balena based image with https://www.php.net/manual/en/install.pecl.phpize.php it’s the extension installer, provided by the DockerFile: Debian php with Apache on Buster.

OK.

If re2c is not available in the ARM apt repo then I am not sure what your best course of action would be, sorry.

I looked around for some existing php Dockerfile and I finally found out Ulsmith’s Source DockerFile: PHP5 :wink: Here’s what I were able to adapt for a LAMP server on php7:

# Source DockerFile: https://github.com/ulsmith/rpi-raspbian-apache-php/blob/master/Dockerfile
#
FROM balenalib/%%BALENA_MACHINE_NAME%%:build
# RUN [ "cross-build-start" ]
ARG PHP_LIB
ENV PHP_LIB ${PHP_LIB:-7.2}

## Install base packages
RUN install_packages \
    apache2 \
    php${PHP_LIB}-dev \
    libapache2-mod-php${PHP_LIB} \
    curl \
    ca-certificates \
    php${PHP_LIB}-curl \
    php${PHP_LIB}-json \
    php${PHP_LIB}-odbc \
    php${PHP_LIB}-sqlite \
    php${PHP_LIB}-mysql

RUN install_packages \
    php${PHP_LIB}-cli \
    php${PHP_LIB}-xml \
    php-pear \
    libmcrypt-dev

RUN pecl config-set php_ini "${PHP_INI_DIR}/php.ini" \
  && mkdir -p /conf.d/ \
  && pecl install mcrypt \
  && docker-php-ext-enable mcrypt

RUN a2enmod php${PHP_LIB} && a2enmod rewrite
COPY conf/000-default.conf /etc/apache2/conf-available/000-default.conf
RUN chown -R www-data:www-data /var/www/html

# RUN [ "cross-build-end" ]
EXPOSE 80

CMD [ "apache2 -D FOREGROUND" ]

Thanks for the update. As it happens, I recently was looking to solve the same problem in a LAMP stack and put together a balena app that separates out apache, mysql and php. https://github.com/jtonello/balena-lamp. As you’ve discovered, the key appears to be embedding the version number (7.2 in your example, 5.6 in mine, which also happens to use Alpine as a base image). Were you successful with your example?

Yes, it was successful. :face_with_raised_eyebrow: I’m about fixing some secure_installation issue with the configuration script.
I find your approach very clean because of FastCGI which is essentially state-of-the-art web server. And maybe it could be made up for raspberry and ARM cloud-services. IMO, the key is balenalib/%%BALENA_MACHINE_NAME%% Base Image , populate the Dockerfile’s with httpd, php-fpm, also with mysql :money_mouth_face: and let the cloud finish the job…

Glad to hear it’s working, thanks!

Hello !
A development image’s built on a cross-compiler system, it has failed on cloud but I’m facing a little bug on starting up across Balena Cloud and docker-compose options.
It’s located on Hub that we can pull and exec on ARM hosts and a compatible Intel-NUC build release to make unit test on local i386 architectures.
That’s eventually supposed to serve a basic Apache HTTPDaemon with PHP framworks. Some tweaks on Dashboard, and the service will publish the port 80 to the web. Still coming next.
:drooling_face: