PHP7 – Fix Short-Tags Not Working


I have installed Apache2 MariaDB and PHP7 for use on localhost, but PHP does not work. The Apache webside looks as normal while phpinfo.php only gives me a blank page. I used to install with 'apt-get install lamp-server^', but I wanted MariaDB, so I installed every single package including some PHP extensions and phpmyadmin. I have no idea of how to get php working. Any clues?

~ # php -v
PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )


<? phpinfo(); ?> 

Best Answer

The problem is that, by default, PHP 7 does not supports short open tags <?.

It is described in the article PHP tags from

You need to use the full open tag <?php. Or, if you have PHP programs which are written for previous versions of PHP, you can change this rule in these ways:

  • you can add next directive into your-apache2-virtualhost.conf (or .htaccess) file:

    php_flag short_open_tag on
  • into the file /etc/php/7.x/apache2/php.ini you can set:

    short_open_tag = on

Don't forget to restart Apache2:

sudo systemctl restart apache2.service
Related Question