6

After entering my username and password into the admin uri of magento I get the following error in system.log

[2017-10-09 00:00:00] main.CRITICAL: Image CAPTCHA requires FT fonts support [] []

there is no such requirement listed by the magento installation guide

Is there a php module I have to enable/install? php -m|grep -i -e 'font' lists nothing... freetype and freetype-devel (v2.4.11)have both been installed to the system.

6 Answers 6

5

you need to change the php configure script to include --with-freetype-dir=/usr/lib64/ where /usr/lib64 contains the libfreetype.so file.

My final configuration so far looks like:

./configure --with-apxs2=/usr/bin/apxs --enable-bcmath --with-curl --with-gd \
--with-jpeg-dir=/usr/lib64/ --with-png-dir=/usr/lib64/ --with-freetype-dir=/usr/lib64/ \
--enable-intl --enable-mbstring --with-mcrypt --with-mhash --with-openssl \
--with-pdo-mysql --enable-soap --with-xsl --enable-zip --enable-opcache  --with-config-file-path=/etc

then you need to make;make install; and restart the web server.

3
  • 2
    On Ubuntu 14, I needed to first install libfreetype-dev: sudo apt-get install libfreetype6-dev, and then my config directive was: --with-freetype-dir=/usr/lib/x86_64-linux-gnu/' Jan 17, 2018 at 15:46
  • 1
    @user3338098 Please consider accepting your own answer as the accepted answer to this question. It also worked for me thank you. Jun 28, 2019 at 20:46
  • had to add the --with-config-file-path since the default is /usr/local/lib/php.ini which is the last place anyone would ever look. Jul 5, 2019 at 20:05
4

I found fix for development environment, because I use Mac OS and the apache php doesn't support these fonts and it's a lot of work to get it working and not mess up my system.

open vendor/zendframework/zend-captcha/src/Image.php and add return in the constructor after the parent is called like this

/**
 * Constructor
 *
 * @param  array|\Traversable $options
 * @throws Exception\ExtensionNotLoadedException
 */
public function __construct($options = null)
{
    parent::__construct($options);
    return;

    if (! extension_loaded("gd")) {
        throw new Exception\ExtensionNotLoadedException("Image CAPTCHA requires GD extension");
    }

    if (! function_exists("imagepng")) {
        throw new Exception\ExtensionNotLoadedException("Image CAPTCHA requires PNG support");
    }

    if (! function_exists("imageftbbox")) {
        throw new Exception\ExtensionNotLoadedException("Image CAPTCHA requires FT fonts support");
    }
}
8
  • 4
    This is an absolutely terrible answer; you should never modify anything in vendor.
    – chrBrd
    Nov 11, 2018 at 23:19
  • 1
    Unless it's purely for debugging modifications to check what core code is doing (even then with a decent IDE this shouldn't be necessary); you should_ absolutely_ not be touching anything in vendor. You certainly shouldn't recommend others do without adding huge caveats. If you need to modify code in vendor to get something to work then your code is broken and your solution is wrong.
    – chrBrd
    Nov 12, 2018 at 22:08
  • 1
    I don't recommend to do it in production, the first line says "I found fix for development environment", because most of the time the dev environment is different than production. For example I'm developing on Mac, but the production is on Linux, in order to use exactly the same software, versions and configs I need to invest a lot of time to setup some kind of container which I don't want to do.
    – nacholibre
    Nov 14, 2018 at 12:56
  • 1
    Learning how to use Docker for a simple dev env takes about a week. If you're so unwilling to spend that amount of time learning how to use the tools of your trade in order to ensure a consistent development environment between the platforms you work with then I sincerely hope I never have to inherit a codebase you've touched. I doubt you even require containers, just a single, simple dependecy installed. Advising people to do critically stupid things like edit anything in vendor, regardless of whether they're in dev or prod is just fundamentally poor advice.
    – chrBrd
    Nov 15, 2018 at 0:15
  • 1
    This is bad advice. I do urge you consider removing this answer. Jun 28, 2019 at 19:06
4

For docker users - update for Magento 2.4, for those using official php docker images - I had to use --with-freetype rather than @cgalvaojr answer --with-freetype-dir, like this:

FROM php:7.4-fpm

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -qq && apt-get -y upgrade && apt-get update -qq

# apt packages we might need:
RUN apt-get install -y -qq wget git ssh mariadb-client unzip vim rsync nginx jq

# extensions already in: ctype curl hash iconv pic ftp mbstring mysqlnd argon2 sodium pdo_sqlite sqlite3 libedit openssl zlib pear
# official Magento 2.4 required exts: bcmath ctype curl dom gd hash iconv intl mbstring openssl pdo_mysql simplexml soap xsl zip sockets

# for php extensions - not needed, all preinstalled except for gd:
RUN apt-get install -y -qq libjpeg62-turbo-dev libpng-dev libxml2-dev libxslt-dev libsodium-dev libzip-dev libfreetype6-dev
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install bcmath gd intl pdo_mysql simplexml soap xsl zip sockets
RUN docker-php-ext-enable bcmath gd intl pdo_mysql simplexml soap xsl zip sockets
3
  • docker-php-ext-install -j$(nproc) gd //need to run this to take effect
    – hkguile
    Apr 12, 2021 at 2:49
  • @hkguile - you shouldn't need to. Installation of gd is handled in the penultimate line of the provided code, and all -j$(nproc) will do is parallelise the job across mutliple cores. It will likely make building the image faster, but it shouldn't be necessary.
    – chrBrd
    Jan 15 at 3:36
  • ooo man you saved me upvoted
    – Asad Ullah
    Mar 24 at 20:36
1

This is almost definitely caused by the underlying system not having FreeType installed (if FreeType is already installed then @user3338098's solution should fix it).

If you come across this problem absolutely do not follow the most upvoted answer (@nacholibre's). Either install the freetype library on your server (usually freetype, libfreetype or similar, will vary depending on distro. apt install freetype should work on Ubuntu), or ask your hosting provider to do so for you. In fact, if you need to ask a managed Magento hosting provider to do this for you then just swap hosting provider.

Never, ever modify code in vendor. If you need to do so then you are doing something very, very, *very* wrong; it completely negates the whole point of using Composer in the first place.

1

For me (using docker) solves problem with:

FROM php:7.2.0-fpm-stretch

RUN apt-get update --fix-missing libfreetype6-dev
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
&& docker-php-ext-install gd

-1

Magento 2.2 has changed the behaviour of the Magento_Captha module to have both the frontend and the admin captcha enabled by default, compared to earlier 2.x versions where the opposite was true

On machines without FreeType built into the PHP GD library (such as OSX High Sierra) this will give the above error when trying to login to the Magento admin system

'main.CRITICAL: Image CAPTCHA requires FT fonts support'

A simple resolution for non-production environments is to disable the behaviour as per earlier Magento versions

vendor/magento/module-captcha/etc/config.xml

   <admin>
        <captcha>
            <type>default</type>
            <enable>0</enable>

...

    <customer>
        <captcha>
            <type>default</type>
            <enable>0</enable>
3
  • 1
    I've tried this, but it doesn't work.
    – nacholibre
    Nov 3, 2017 at 19:54
  • 1
    You can alternatively disable the module locally as follows bin/magento module:disable Magento_Captcha
    – Judder
    May 3, 2018 at 16:58
  • No you cannot disable the module on a standard installation. You will get something like : Unable to change status of modules because of the following constraints: Cannot disable Magento_Captcha because modules depend on it: Magento_AdminAnalytics... Mar 29, 2020 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.