this question also exist of SFO but I was recommended to ask here since it is more a server configuration issue.

I have a major problem.

My apache2 does not process php7 code but instead shows the codes straight in the browser(chrome) or blank page(firefox)

Many have had a similar problem but apparently managed to solve it.
(White Screen - PHP 7 on Ubuntu 16.04 fails to render scripts)

I have followed many threads on how to get it working to no avail.

Also, I have forced my site to only work on https if that could be an issue.

Ubuntu release: Ubuntu 16.04.3 LTS

apache2 -v
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2017-07-27T14:34:01


$ php -v
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

$ ps -A|grep php
7799 ?        00:00:52 php-fpm7.0

Apache mods:

$ ls -lart /etc/apache2/mods-enabled/  
php7.0.load -> ../mods-available/php7.0.load
php7.0.conf -> ../mods-available/php7.0.conf

$ dpkg --list|grep libapache2  
ii  libapache2-mod-php                 1:7.0+35ubuntu6                            all          server-side, HTML-embedded scripting language (Apache 2 module) (default)  
ii  libapache2-mod-php7.0              7.0.22-0ubuntu0.16.04.1                    amd64        server-side, HTML-embedded scripting language (Apache 2 module)  
ii  libapache2-mod-python              3.3.1-11ubuntu2                            amd64        Python-embedding module for Apache 2

php module:

$ sudo a2enmod php7.0
Considering conflict php5 for php7.0:
Module php7.0 already enabled

Extract from my Apache conf(/etc/apache2/sites-available):

<VirtualHost *:443>
  ServerName ############
  ServerAlias ############
  DocumentRoot /var/www/html/public

  ErrorLog /var/www/html/logs/eu_error_log
  CustomLog /var/www/html/logs/eu_access_log combined

  ScriptAlias /cgi-bin/ /var/www/html/cgi-bin/
  DirectoryIndex index.html index.htm index.php7

  <Directory /var/www/html/public>
    Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
    AddType application/x-httpd-php .php7
    AddType application/x-httpd-php-source .phps
    AddType application/json .json

  <Directory /var/www/html/cgi-bin>
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted

  <Directory /usr/lib/cgi-bin>
    Require all granted
  <IfModule mod_fastcgi.c>
    AddHandler php7-fcgi .php7
    Action php7-fcgi /php7-fcgi
    Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
    FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization

#  RemoveHandler .php
#  RemoveHandler .php7
  php_admin_value engine On
#  IPCCommTimeout 301
#  FcgidMaxRequestLen 1073741824
  php_value memory_limit 128M
  php_value suhosin.session.encrypt Off

  SSLEngine on
  SSLCertificateFile ############
  SSLCertificateKeyFile ############
#  SSLCACertificateFile ############
  SSLProtocol All -SSLv2 -SSLv3
  SSLCompression off
  SSLHonorCipherOrder On


And my www folder:

$ ls -lart /var/www/html/public/*
-rw-r--r-- 1 root root    27 sep 10 15:35 .htaccess
-rw-r--r-- 1 root root    29 sep 10 15:46 index.php7


$ sudo cat /var/www/html/public/.htaccess
DirectoryIndex index.php7

$ sudo cat /var/www/html/public/index.php7:
echo "Hello World";

A normal index.html produces proper output.
Any idea on what else to check?

  • Can you make sure the permissions are set right for /usr/lib/cgi-bin/php7-fcgi? What happens when you do php index.php7 in the command line? – Tux_DEV_NULL Sep 12 '17 at 12:22
  • It prints the string "Hello World" to the console as expected. – IgorLopez Sep 12 '17 at 14:16
  • When examining the path: /usr/lib/cgi-bin/ it is empty. I am assuming something is amiss with the apache2 mod for php. In my conf (which I have copied from other solutions) I have the path: /usr/lib/cgi-bin/php7-fcgi but when it comes to what is installed I only have mod-php and the folder /usr/lib/cgi-bin/ is empty. I installed libapache2-mod-fastcgi and restarted apache but still the same. – IgorLopez Sep 12 '17 at 15:49
  • Don't mix fcgi and mod_php; pick one or the other and stick to it. – womble Sep 13 '17 at 3:56
  • Ok so I removed the mod-php sudo apt remove --auto-remove libapache2-mod-php and restarted but still the same. I have no clue on how the parts are connected. My /etc/apache2/mods-enabled/fastcgi.load contains only one line: LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so but there is an libphp7.0.so file in the same folder. In my Apache conf there are two <Directory path > sections but both paths are empty, e.g. /var/www/html/cgi-bin and /usr/lib/cgi-bin which have ended up in the conf by copy/paste from other solutions. – IgorLopez Sep 13 '17 at 18:03

Your Answer

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

Browse other questions tagged or ask your own question.