WordPress install can't use cURL

0

I’m about at my wits end with this, have tried so many different things I’ve lost track.

This is my Dockerfile

FROM wordpress:latest

RUN apt-get update
RUN apt-get install -y gcc
RUN apt-get install -y curl
RUN apt-get install -y libcurl4-openssl-dev
RUN docker-php-ext-install curl
RUN docker-php-ext-enable curl

Here is my compose.yml

services:
  db:
    # We use a mariadb image which supports both amd64 & arm64 architecture
    #image: mariadb:10.6.4-focal
    # If you really want to use MySQL, uncomment the following line
    image: mysql:8.0.27
    command: '--default-authentication-plugin=mysql_native_password'
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    expose:
      - 3306
      - 33060
  wordpress:
    image: wordpress:latest
    ports:
      - 80:80
    restart: always
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=wordpress
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - ./:/var/www/html
      - $PWD/php.ini:/usr/local/etc/php/php.ini-development
volumes:
  db_data:

Here is the list of extensions in php.ini that is referenced in that compose file. If you need to see the full thing, I’ll have to find another way to send it because it’s well over the limit of characters.

; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.
;
;extension=bz2
extension=curl
;extension=ffi
;extension=ftp
;extension=fileinfo
;extension=gd
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=ldap
;extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=oci8_19  ; Use with Oracle Database 19 Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop

I can SSH into the container and confirm that curl is installed and working, I can confirm that that php.ini is mapped to and replacing the php.ini-development in the container as well. Still, when I call curl_init() in one of my files I get “Fatal error: Uncaught Error: Call to undefined function curl_init()…”

I have run out of things to try, any other options?

Unless it changed in the latest PHP versions, which I don’t think so, php.ini-development is just n example that you can rename to php.ini to have a developer friendly config. If you mount your config file to that path it will be ignored. Try to mount it to /usr/local/etc/php/php.ini. That should work.

After that instead of checking the content of the config file, you can try a php file with the following content to check the applied settings:

<?php

phpinfo();

Doesn’t wordpress have a built-in phpinfo page?

Ran phpinfo() before making any changes, it does list cURL support as enabled and cURL information as 7.74.0.

Tried changing it /usr/local/etc/php/php.ini, can see it in the container but still no change.

It looks like curl is enabled by default in the wordpress image (I tried) and it works from the terminal without installing any library and extension, but I didn’t try it from a browser.

I also noticed that you use wordpress:latest in the compose file so it doesn’t matter what you write in the Dockerfile. Did you just remove the build section from the compose file?

Sorry, I did. Adding it back so that it looks like this, makes no difference.

services:
  db:
    # We use a mariadb image which supports both amd64 & arm64 architecture
    #image: mariadb:10.6.4-focal
    # If you really want to use MySQL, uncomment the following line
    image: mysql:8.0.27
    command: '--default-authentication-plugin=mysql_native_password'
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    expose:
      - 3306
      - 33060
  wordpress:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 80:80
    restart: always
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=wordpress
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - ./:/var/www/html
      - $PWD/php.ini:/usr/local/etc/php/php.ini
volumes:
  db_data:

  

Since the original base image already has curl enabled, it is understandable that it makes no difference. The question is why the original image doesn’t work for you. Maybe there are other config files that you couldn’t find and changes the loaded libraries somehow. If I remember correctly, the phpinfo shows the loaded config files. Have you checked that?

Second question: have you tried the curl_init function from the terminal just to test it?

Unfortunately, the answer to both of those questions is yes. I ended up just scrapping the container and trying with a new one and it worked. Somewhere along the line I must have modified a config that I didn’t realize or something and broke it.