Search code examples
phpdockeralpine-linuxphp-shorttags

How to enable Short Tags in Php7 in Alpine Linux?


I am already aware of the general fix; placing the setting "short_open_tag=On" inside php.ini and then restarting whatever server you're using, however with Alpine Linux the situation is a bit more complicated.

It seems the php7 package you install via the command apk add php7comes with a pre-configured "configure command" embedded into the php executables, and one of the configuration options specified is '--disable-short-tags'. To demonstrate, this is the output of php -i after creating a simple docker container:

phpinfo()
PHP Version => 7.3.13

System => Linux 9ea27eea7b8e 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64
Build Date => Dec 22 2019 05:57:19
Configure Command =>  './configure'  '--build=x86_64-alpine-linux-musl' '--host=x86_64-alpine-linux-musl' '--prefix=/usr' '--program-suffix=7' '--libdir=/usr/lib/php7' '--datadir=/usr/share/php7' '--sysconfdir=/etc/php7' '--localstatedir=/var' '--with-layout=GNU' '--with-pic' '--with-pear=/usr/share/php7' '--with-config-file-path=/etc/php7' '--with-config-file-scan-dir=/etc/php7/conf.d' '--disable-short-tags' '--enable-bcmath=shared' '--with-bz2=shared' '--enable-calendar=shared' '--enable-ctype=shared' '--with-curl=shared' '--enable-dba=shared' '--with-db4' '--with-dbmaker=shared' '--with-gdbm' '--enable-dom=shared' '--with-enchant=shared' '--enable-exif=shared' '--enable-fileinfo=shared' '--enable-ftp=shared' '--with-gd=shared' '--with-freetype-dir=/usr' '--disable-gd-jis-conv' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-webp-dir=/usr' '--with-xpm-dir=/usr' '--with-gettext=shared' '--with-gmp=shared' '--with-iconv=shared' '--with-imap=shared' '--with-imap-ssl' '--with-icu-dir=/usr' '--enable-intl=shared' '--enable-json=shared' '--with-kerberos' '--with-ldap=shared' '--with-ldap-sasl' '--with-libedit' '--enable-libxml' '--with-libxml-dir=/usr' '--enable-mbstring=shared' '--with-mysqli=shared,mysqlnd' '--with-mysql-sock=/run/mysqld/mysqld.sock' '--enable-mysqlnd=shared' '--enable-opcache=shared' '--with-openssl=shared' '--with-system-ciphers' '--with-password-argon2' '--enable-pcntl=shared' '--with-pcre-regex=/usr' '--enable-pdo=shared' '--with-pdo-dblib=shared' '--with-pdo-mysql=shared,mysqlnd' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-pgsql=shared' '--with-pdo-sqlite=shared,/usr' '--with-pgsql=shared' '--enable-phar=shared' '--enable-posix=shared' '--with-pspell=shared' '--without-readline' '--with-recode=shared' '--enable-session=shared' '--enable-shmop=shared' '--enable-simplexml=shared' '--with-snmp=shared' '--enable-soap=shared' '--with-sodium=shared' '--enable-sockets=shared' '--with-sqlite3=shared,/usr' '--enable-sysvmsg=shared' '--enable-sysvsem=shared' '--enable-sysvshm=shared' '--with-tidy=shared' '--enable-tokenizer=shared' '--with-unixODBC=shared,/usr' '--enable-wddx=shared' '--enable-xml=shared' '--enable-xmlreader=shared' '--with-xmlrpc=shared' '--enable-xmlwriter=shared' '--with-xsl=shared' '--enable-zip=shared' '--with-libzip=/usr' '--with-zlib' '--with-zlib-dir=/usr' '--disable-phpdbg' '--enable-fpm' '--enable-embed' '--with-litespeed' 'build_alias=x86_64-alpine-linux-musl' 'host_alias=x86_64-alpine-linux-musl'

And this is the Dockerfile:

FROM nginx:alpine
RUN apk --update --no-cache add php7
CMD ["php", "-i"]

From what I read online, you cannot override these configurations and the configuration files will be ignored. Any ideas on what I should do to fix this?


Solution

  • php config in alpine is in /etc/php7/,

    so you need to add something like

    COPY ./php-overrides.ini /etc/php7/conf.d/
    

    into your Dockerfile, and php-overrides.ini should have short_open_tag=on in it