Call to undefined function mysqli_connect() - php

In this code must be an error due to empty arguments in the mysqli_connect function. But browser display different error. As I know mysqli_connect function installed by default. Where is the problem or my mistake? How I can fix it?
Dockerfile
FROM php:fpm
# Update system core
RUN apt update -y && apt upgrade -y
# Start PHP-FPM
CMD ["php-fpm"]
index.php
<?php mysqli_connect('', '', '', '', '', ''); ?>
Error in browser:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/index.php:3 Stack trace: #0 {main} thrown in /var/www/index.php on line 3

In your Dockerfile for PHP-FPM (I recommend the Alpine version) you have to install MySQLi extension separately
FROM php:7-fpm-alpine
# Update system core
RUN apt update -y && apt upgrade -y
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# Start PHP-FPM
CMD ["php-fpm"]

In Dockerfile you need add mysqli extension:
FROM php:7.3-fpm
# Update system core
RUN apt update && apt install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev libxml2-dev libcurl4-gnutls-dev
RUN docker-php-ext-install -j$(nproc) mysqli \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
# Start PHP-FPM
CMD ["php-fpm"]

Related

cannot stat '/usr/local/lib/odbclib.a': No such file or directory

cp: cannot stat '/usr/local/lib/odbclib.a': No such file or directory
configure: error: ODBC header file '/usr/local/incl/sqlext.h' not found!
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-configure odbc --with-unixODBC=shared,/usr' returned a non-zero code: 1
I am getting this error from the command below:
FROM george/php:7.4-fpm
RUN apt-get --allow-releaseinfo-change update
RUN apt-get update && apt-get install -y \
freetds-bin \
freetds-dev \
freetds-common
RUN apt-get install -y --no-install-recommends unixodbc-dev
RUN apt-get install -y --no-install-recommends unixodbc
RUN docker-php-ext-configure odbc --with-unixODBC=shared,/usr \
RUN docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr
RUN docker-php-ext-configure pdo_dblib --with-libdir=/lib/x86_64-linux-gnu
RUN docker-php-ext-install odbc
RUN docker-php-ext-install pdo_odbc
RUN docker-php-ext-install pdo_dblib
RUN docker-php-ext-install pcntl
RUN docker-php-ext-enable pdo_odbc
RUN docker-php-ext-enable pdo_dblib
RUN docker-php-ext-enable pcntl
https://github.com/docker-library/php/issues/732
I checked this link and I added the line as suggested:
apt-get install -y --no-install-recommends unixodbc-dev
But it doesn't seem to work. My image is based off Debian.
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Trying to install pdo_odbc, but I am running into difficulties. I am not sure if I need to configure it or not in my understanding not configuring it won't install it, but I am not sure what are the options when configuring it, there's no documentation on this anywhere.

Installing GD extension in Docker

I'm new to Docker and I'm trying to install PHP GD extension.
This is my current Dockerfile:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql bcmath gd
When running the docker via docker-compose build && docker-compose up -d I'm getting a lots of errors and in the end I get this message:
configure: error: Package requirements (zlib) were not met:
Package 'zlib', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli pdo pdo_mysql bcmath gd' returned a non-zero code: 1
Without the "gd" at the end the Docker container runs normally.
What could be the problem and how could I fix it?
You can try to add these settings in Dockerfile:
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
Official documentation. Hope it's help you.
In my docker using PHP8.0 I got GD working for jpg,png and webp by adding the following lines to my php.dockerfile:
FROM php:8.0-fpm-alpine
# Install dependencies for GD and install GD with support for jpeg, png webp and freetype
# Info about installing GD in PHP https://www.php.net/manual/en/image.installation.php
RUN apk add --no-cache \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
freetype-dev
# As of PHP 7.4 we don't need to add --with-png
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype
RUN docker-php-ext-install gd
One more way to approach the issue is to use install-php-extensions in Dockerfile:
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd xdebug
Works in Alpine and PHP8.
Docs here
If someone has problems installing php-gd extension in Docker, look up to #Dmitry comment or Documentation and search for "PHP Core Extensions".
You can see full code on my Github, if you want to see how am I running my NGINX and PHP with php-gd extension.

Error updating Dockerfile FROM php:7.2-fpm to php:7.3-fpm

Because I want PHP 7.3 features I am trying to update the project from PHP 7.2 to PHP 7.3. Within docker-compose.yml I have:
php:
build: ./docker/php
volumes:
- .:/var/www/html
links:
- mysql:mysql
depends_on:
- mysql
networks:
- pimcorenet
My Dockerfile is like:
FROM php:7.2-fpm
# install git
RUN apt-get update && \
apt-get install -y --no-install-recommends git
#install some base extensions
RUN apt-get install -y \
zlib1g-dev \
zip \
libpng-dev \
exiftool \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libicu-dev \
libpq-dev \
libxpm-dev \
libvpx-dev \
mariadb-client \
libxml2-dev
RUN docker-php-ext-install -j$(nproc) \
zip \
exif \
bcmath \
intl \
pcntl \
mysqli \
pdo \
gd \
pdo_mysql \
pdo_pgsql \
mbstring \
soap \
opcache \
iconv
# Install Imagick
RUN apt-get update && apt-get install -y \
libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick
# Install Composer
RUN echo "Install Composer"
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
I am getting the following error:
E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/r/readline/readline-common_7.0-5_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/j/jquery/libjs-jquery_3.3.1~dfsg-3_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/f/freetype/freetype2-doc_2.9.1-3_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/i/icu/icu-devtools_63.1-6_amd64.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/j/javascript-common/javascript-common_11_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' ..... more errors
ERROR: Service 'php' failed to build: The command '/bin/sh -c apt-get
install -y zlib1g-dev zip libpng-dev
exiftool libfreetype6-dev libjpeg62-turbo-dev
libmcrypt-dev libicu-dev libpq-dev libxpm-dev
libvpx-dev mariadb-client libxml2-dev' returned a
non-zero code: 100
What is the exact problem with this? Is it because some required PHP extensions are not yet available for PHP 7.3 or have been replaced? How do I resolve this? Just changed FROM php:7.2-fpm to FROM php:7.3-fpm.
You are failing to grok containers. And because of that you are taking the wrong approach.
You shouldn't be trying to 'upgrade' a php 7.2 to container to 7.3.
You should be creating a new container image that is based off 7.3 to begin with.
Incidentally, I would recommend making it me a new, separate service to your existing 7.2 container, i.e. a new Dockerfile, rather than just changing the existing container/Dockerfile. That will allow you to test the two versions alongside each other, rather than having a 'leap of faith' change over.
Also, I'd recommend building off the Debian or Ubuntu images directly, rather than going through the 'official' Docker images. They are only official in the sense of being made by Docker, but they are not quite as well supported in my opinion.
This is the dockerfile I'm using currently: https://github.com/Danack/example/blob/master/docker/php_fpm/Dockerfile Switching 7.2 to 7.3 should 'just work'.

Docker Call to undefined function imagecreatefromjpeg()

I try to install GD, because I'm getting the error "Call to undefined function imagecreatefromjpeg()".
When building the image I'm getting the error
E: Unable to locate package libfreetype6-dev
E: Unable to locate package libjpeg62-turbo-dev
E: Unable to locate package libpng12-dev
The command '/bin/sh -c apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev && docker-php-ext-configure gd --enable-gd-native-ttf --with-freetype-dir=/usr/include/freetype2 --with-png-dir=/usr/include --with-jpeg-dir=/usr/include && docker-php-ext-install gd && docker-php-ext-enable gd' returned a non-zero code: 100
My Dockerfile
FROM php:7-fpm
# Install GD
RUN apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng12-dev \
&& docker-php-ext-configure gd \
--enable-gd-native-ttf \
--with-freetype-dir=/usr/include/freetype2 \
--with-png-dir=/usr/include \
--with-jpeg-dir=/usr/include \
&& docker-php-ext-install gd \
&& docker-php-ext-enable gd
What's the right way to install GD?
What about running apt-get update first to update local list of packages? It should always be run before installing:
FROM php:7-fpm
RUN apt-get update && apt-get install --yes libfreetype6-dev ....
According to offical image doc:
If you are having difficulty figuring out which Debian or Alpine packages need to be installed before docker-php-ext-install, then have a look at the install-php-extensions project. to install the GD extension you simply have to add these to lines to Dockerfile and get ride of everty things:
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd

Installing ldap extension Docker

Hey all I am trying to instal ldap extension on a Docker php:5.6-fm images I need ldap for my project.
I have tired to install the extension through Dockerfile like so:
RUN apt-get install php5-ldap -y
get this error:
The LDAP PHP extension is not enabled.
I have also found some 'suggestion' online like so:
RUN \
apt-get update && \
apt-get install libldap2-dev -y && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-install ldap
get this error:
An exception occurred in driver: could not find driver
am I doing something wrong...? How do I install ldap in a docker image so that I can use it in my project...?
Here is what I did... and it's working. I had other modules configured, but I don't think they interfere with anything.
FROM php:5.6-apache
RUN apt-get update -y \
&& apt-get install -y libcurl4-openssl-dev pkg-config libssl-dev vim
# Configure MongoDB.
RUN pecl install mongodb \
&& docker-php-ext-enable mongodb
# Configure MySQL.
RUN docker-php-ext-install mysqli
# Configure LDAP.
RUN apt-get update \
&& apt-get install libldap2-dev -y \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
&& docker-php-ext-install ldap
RUN a2enmod rewrite && service apache2 restart
# Python 2.7 and modules
RUN apt install python2.7 python-pip -y \
&& python2.7 -m pip install pymysql pymongo redis
# We must reconfigure here the CMD directive.
CMD apache2-foreground

Categories