3

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
    Did you inatall libapache2-mod-php7.0 also if not please do then restart apache Jan 30, 2017 at 21:16
  • You need to enable php7.0 module for Apache: sudo apt install libapache2-mod-php7.0 && sudo a2enmod php7.0 && sudo systemctl restart apache2.service.
    – pa4080
    Jan 30, 2017 at 21:18
  • libapache2-mod-php7.0 already installed
    – prebre
    Jan 30, 2017 at 21:19
  • 1
    Try with <?php phpinfo(); ?> . By default php7.0 doesn't support short open tags - <?.
    – pa4080
    Jan 30, 2017 at 21:26
  • 1
    Sorry, I am still a bit confused about this forum, but now I have accepted your (BTW very useful) answer!
    – prebre
    Jan 31, 2017 at 17:31

1 Answer 1

8

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .