2

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.

Information:
Ubuntu release: Ubuntu 16.04.3 LTS

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

Php:

$ 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>

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

  <Directory /usr/lib/cgi-bin>
    Require all granted
  </Directory>
  <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
  </IfModule>

#  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 ############
  SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
  SSLProtocol All -SSLv2 -SSLv3
  SSLCompression off
  SSLHonorCipherOrder On

</VirtualHost>

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

Content:

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

$ sudo cat /var/www/html/public/index.php7:
<?php
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.