Php7 Does Not Work with Short-Tags

Php7 Does Not Work with Short-Tags

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.php:

<? phpinfo(); ?> 
7

1 Answer

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

It is described in the article PHP tags from php.net.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.