Search code examples
phpapache2gettextphp-gettext

php-gettext installed but not available


I have the following packages installed on Ubuntu 16.04:

  • apache2 2.4.18-2ubuntu3.1
  • php-gettext 1.0.11-2build1
  • gettext 0.19.7-2ubuntu3
  • php7.0 7.0.15-0ubuntu0.16.04.4

The only mention of gettext when I call phpinfo() is in the module authors section ("GetText = Alex Plotnick"), so I would assume that support has been compiled in correctly.

It seems that gettext isn't loaded properly into PHP, because the following code:

<?php

if ( false === function_exists('gettext') ) {
    echo "You do not have the gettext library installed with PHP.";
    exit(1);
}

Does indeed print "You do not have the gettext library installed with PHP."

Apart from documentation, the only php-gettext files I have installed are:

/usr/share/php/php-gettext/gettext.inc
/usr/share/php/php-gettext/streams.php
/usr/share/php/php-gettext/gettext.php

I haven't really touched any php or apache config (apart from try and install icingaweb2)

Can anyone see what my issue could be?

Update More debugging...

me@phoenix:~$ ls /etc/php/7.0/apache2/conf.d/
10-mysqlnd.ini  20-dom.ini      20-intl.ini  20-mbstring.ini  20-pdo_mysql.ini  20-wddx.ini       20-xmlwriter.ini
15-xml.ini      20-imagick.ini  20-ldap.ini  20-mysqli.ini    20-simplexml.ini  20-xmlreader.ini  20-xsl.ini


me@phoenix:~$ sudo a2dismod php5
ERROR: Module php5 does not exist!


me@phoenix:~$ sudo find / -name gettext.so
/usr/lib/php/20151012/gettext.so
/usr/lib/x86_64-linux-gnu/perl5/5.22/auto/Locale/gettext/gettext.so

Solution

  • It should work out of the box after installation. Have you restarted Apache? Try first sudo apache2ctl restart or sudo service apache2 restart on the terminal console. If both should not work on your system, try sudo /etc/init.d/apache2 restart.

    Check if there does exist a file /etc/php/7.0/apache2/conf.d/20-gettext.ini (or similar path on your system) containing the line

    extension=gettext.so
    

    There must not be a semicolon prepended, otherwise it is commented out. Some installations may also configue that line within the basic php configuration file /etc/php/php/7.0/php.ini, however the debian derivate's way is to use extra files in the conf.d folder.

    You can enable PHP modules (e.g. gettext) on the command line

    sudo phpenmod -v 7.0 gettext
    

    If this does not work, edit the configuration manually.

    Finally restart your Apache service as described above.

    Check also if Apache is running the expected PHP version 7.0 with the following line in your PHP page

    echo phpversion();
    

    You can enable / disable Apache2 modules from multiple installed PHP versions on the command line

    sudo a2dismod php5
    sudo a2enmod php7.0
    sudo apache2ctl restart