Newbie question: Trying to create an image with apache, php 8 and mssql

Hello, I’ve tried a lot of things, but was not able to create the image that I need:

  • Any Linux
  • Apache (httpd)
  • PHP 8.2 or higher
  • MS-SQL drivers version 17 or 18 (with ODBC?), this is to connect to existing Azure SQL database
  • Composer

I work with Docker Desktop (Windows)

The closest I get is with this Dockerfile, but starting this up makes it quit immediately:

FROM php:8.2-cli-bullseye

RUN apt-get update && \
    apt-get install -y \
        git \
        libpq-dev \
        libzip-dev \
        unzip \
        zip \
        wget

RUN apt-get update && \
    apt-get install -y gnupg2 curl && \
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt-get update && \
    ACCEPT_EULA=Y apt-get install -y msodbcsql17 odbcinst=2.3.7 odbcinst1debian2=2.3.7 unixodbc-dev=2.3.7 unixodbc=2.3.7 && \
    pecl install sqlsrv pdo_sqlsrv && \
    docker-php-ext-enable sqlsrv pdo_sqlsrv

WORKDIR /var/www/html

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Copy website into image
COPY ./Web /var/www/html/

# Compile composer modules
RUN composer install --no-interaction --no-plugins --no-scripts --prefer-dist

EXPOSE 80

Please help!

Hi

What errors are you getting in the logs?

2023-03-14 16:20:06 Interactive shell
2023-03-14 16:20:06 
2023-03-14T15:20:06.370672522Z php >

It just exits at once, no error I would say.

Although you are using Docker Desktop for Windows, I moved the topic to the “Docker Engine” category from Tips & HowTos as you did not have tips, but you asked about an issue which is does not seem to be related to Docker Desktop.

Since you based your image on PHP CLI, which will not run in the foreground, you will get only an interactive shell, which will not work either, unless you run the container asking for an interactive shell support:

docker run -i -t IMAGENAME

If you want to use PHP with Apache HTTPD, you should use the FPM variant of the PHP image.

FROM php:8.2-fpm-bullseye

and connect from an Apache HTTPD container to the PHP FPM port which is usually port 9000.

Thank you, but I’m still in the dark here.
I want to use it as a webserver, not cli.
So I tried FPM, and connecting to port 9000, but I do not see my website there at localhost.

All I need is PHP 8.2 with Apache and MS SQL drivers,
Official PHP switched to NGINX, but I have so many websites running Apache (and they USE Apache too) that I can’t switch to nginx at this time.

I’ve spent so much time (weeks) to find out how to make a simple image that does this, but no succes jet.

I appreciate any help!

I just found this, I’m trying now to see if this is a solution:

I see there is a apache/php/debian section.
(then I just have to add the MS SQL)

Why do you think that? What do you call official PHP? This is the officia image for PHP

https://hub.docker.com/_/php

You can find CLI, FPM and Apache variants too. I don’t see any NginX and the Apache variant means you get an Apache HTTPD server with the PHP module but I haven’t used PHP that way for a long time.

I really don’t understand the NginX part. As far as I know NginX doesn’t have PHP module, but it can connect to a PHP-FPM port similarly to Apache HTTPD.

This is the source code of the official images, yes.

I mean’t connecting from an HTTPD server (or NginX) and you connect to HTTPD (or NginX) from a web browser. IT is usually the better way, but if you are still learning how PHP works this way, then yes, you can use the Apache variant of the official image too.

FROM php:8.2-apache-bullseye

Why do you think that? What do you call official PHP? This is the officia image for PHP

I’m sorry. I guess I’m wrong here. I know that at Azure the default for webapp (Linux) now is Nginx and I thought I read somewhere that this is because PHP defaults to nginx these days. I see now, as I slowly begin to understand a little more of the Linux/Docker concept, that apache can still be used from within the official docker PHP pages. Thank you.