Hello everyone.

I've installed Drupal 8 and got a notice on the status page about installing the Twig C extension. I followed the link;

http://twig.sensiolabs.org/doc/installation.html

...however, there's only this relevant path in the Drupal 8 installation directory:

./vendor/twig/twig

which has these contents:

CHANGELOG composer.json lib LICENSE phpunit.xml.dist README.rst

There's no "ext" directory to change into. ./vendor/twig only contains the "twig" directory. Am I looking in the wrong location? I followed the instructions in a forum post to find where I should be looking for the correct directory, but it doesn't appear to be present on my install.

Comments

bjmagar1906’s picture

Twig C extension is a php extension which is supposed to be added in to ext folder under php directory not in to /vendor/twig/twig . The installation guide can be found at http://twig.sensiolabs.org/doc/installation.html#installing-the-c-extension

elevarni’s picture

Thanks - that corrects one misunderstanding. As someone who has never installed a php extension before those instructions (which were the ones I was going from) didn't explicitly say where to do that... obvious if you know, I suppose!

Next problem - there's no "ext" folder anywhere in the php folder structure under /etc/php5 - I'm using nginx and php5-fpm, does that change anything?

...or I just had a thought. Should I be following those instructions from the beginning and starting with:

composer require twig/twig:~1.0

?

desro’s picture

I recently installed Drupal 8 and also saw that Twig C extension is not available on my shared host. I contacted their customer support (One.com) and found that adding the Twig C extension for PHP is not something that they will do as they do no change the php.ini files for their servers. That being the case, I am wondering of possible side effects that may arise of the situation.

Right now, my issue at the moment is that the blocks that I am placing are not appearing on my site. Could not having this extension available cause a problem with block layout?

Daniel Schaefer’s picture

Are you still experiencing this issue? It doesn't sound related to the Twig Extension thing (in fact, you should ignore it- no benefit). Are the blocks being saved properly?

Daniel Schaefer’s picture

The link provided on the status page in not very helpful. Also, in case anyone wonders, the Twig C Extension is not compatible with PHP 7. And it looks like they won't be upgrading it soon (if at all).

I actually managed to install it on php5 before (after spending many hours trying to figure out where to put what, of course) but the difference was barely noticeable. Best performance boost is to use OPCache. But then again D8 is so fast out of box already.

In my opinion this status message can be ignored and should be removed from the status page.

solodky’s picture

my report says:

PHP 7.0.5 (more information)

and;

Twig C extension Not available
Enabling the Twig C extension can greatly increase rendering performance. See the installation instructions for more detail."

that's sweet

Jean Gionet’s picture

Here's how I installed the twig C extension using Composer on my Dreamhost shared hosting account:

  1. you have to ensure you have Composer installed and working. (here's how I installed it on Dreamhost)
  2. cd ~/.php/composer
  3. run: composer require twig/twig:~1.0
  4. cd ~/.php/composer/vendor/twig/twig/ext/twig
  5. run:
    phpize
      ./configure
      make
      make install
  6. cd modules
  7. cp twig.so ~/.php/5.6/ (I'm using php 5.6. If you're using another version you have to change 5.6 to whatever version you have configured. Here are Dreamhost's instructions on configuring your version of PHP and phprc file.)
  8. use nano or vi to edit: ~/php/5.6/phprc
  9. add this line: extension= /home/<--your user name-->/.php/5.6/twig.so
  10. On Dreamhost I have to kill the php process by typing: killall php56.cgi
  11. load your Status page again to see if it loaded properly.

Hope this helps people a bit ;)

A Day In The Life

MarcRNelson’s picture

Installs as described by Jean Gionet. Thank you!

cfont’s picture

Jean and Marc, have you seen any noticeable improvements since getting this successfully installed on Dreamhost shared account? Is it worth the 5 minutes to install/configure and potentially maintain?

MarcRNelson’s picture

Hi,

I would not say that I have seen any earth shattering differences, but its probably worth just spending the extra 5 minutes to install.

Best Regards,
Marc

drupert55’s picture

Hello.

Looks like not all shared server hosting companies have the Twig C extension available for Drupal 8 even though the installation of Drupal 8 can be done via Softaculous. The reason provided is it must be enabled globally (effecting all shared server users) versus installed/enabled locally. The solution is to e.g. get a cloud plan. The instructions via https://groups.google.com/forum/#!topic/twig-users/YcghbZMKD8w didn't seem to work when tried.

How will D8 perform without Twig?

Thanks!

vm’s picture

The C extension is optional but it brings some nice performance improvements.

quoted from: http://twig.sensiolabs.org/doc/installation.html

It's optional for twig which is why its optional for Drupal 8. Also of note, your question is answered in the 3rd comment of the link you posted above.