In the latest Drupal 8 releases, the vendor/twig/twig/ext directory doesn't exist anymore.
To build the extension, I first globally required Twig, and then compiled the extension.
composer global require twig/twig:~1.0
cd ~/.composer/vendor/twig/twig/ext/twig
phpize
./configure
make
make install
Then, I edited the php.ini file to add a line about the new extension.
extension=twig.so
I ran the command on OS X 10.11. In a different OS, the directory where Composer put the packages globally required could be different.
I am using Drupal 8.0.4, but it could be that previous versions didn't have the ext/twig version already. From the other answers given here, I take that Drupal 8.0.1 already missed the necessary directory.
On OS X 10.11, I got the following error:
PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/DevDesktop/php5_5/ext/twig.so' - dlopen(/Applications/DevDesktop/php5_5/ext/twig.so, 9): no suitable image found.
Did find: /Applications/DevDesktop/php5_5/ext/twig.so: mach-o, but wrong architecture in Unknown on line 0
Following what reported in Compiling PHP extensions on Snow Leopard with XAMPP, I then tried with the following commands.
composer global require twig/twig:~1.0
cd ~/.composer/vendor/twig/twig/ext/twig
phpize
CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 ./configure
make
make install
After restarting Apache, the Twig extension was listed between the PHP extensions.
As of today (February 26, 2016), I was not able to compile the extension for PHP 7.0, since make
fails with a warning and a fatal error.
/Applications/DevDesktop/php7_0/include/php/Zend/zend_hash.h:134:15: warning:
fastcall calling convention ignored on variadic function
[-Wignored-attributes]
ZEND_API void ZEND_FASTCALL zend_hash_apply_with_arguments(HashTable *ht...
/Applications/DevDesktop/php7_0/include/php/Zend/zend_portability.h:231:39: note:
expanded from macro 'ZEND_FASTCALL'
# define ZEND_FASTCALL __attribute__((fastcall))
.composer/vendor/twig/twig/ext/twig/twig.c:23:10: fatal error:
'ext/standard/php_smart_str.h' file not found
#include "ext/standard/php_smart_str.h"