PHP does not load after configuring virtual host

Hello community,

I have been wanting to setup my own cloud with Nextcloud for a long time, and now I finally got to it.

I am running a Centos 7 server and manage to install the nextcloud package from the tarball with the apache 2.4.6 and PHP 7.4.4 services. I have been testing this for a couple days within my local network, and as everything was working as expected, I decided it was time to publish it to the world. Hence, SSL generation time.

For the SSL certificate I was planning on using the Let’s Encrypt certbot tool, for which the site has to be already accessible.
After properly opening my 80 and 443 ports on my router, and being able to access the Nextcloud in full glory though http, it is time to create the SSL certificate. During the generation of the certificate it tells me that no Virtual Host file has been setup, and therefore cannot grand me a certificate.

Of course… The virtual host… Forgot about that… So I generated a file with a *:80 VirualHost that looks like the one described in this documentation.

I also did some separation for site-available and sites-enabled folders and some SELinux permissions stuff as described here.

The problem now is that after creating and reloading the website does not render the NextCloud interface, but only shows me the plain text index.php in the browser.

There is something wrong, but I cannot seem to figure out what it is, therefore I turn to you, community!
Any ideas? Help is really appreciated!


Nextcloud version: 18.0.3
Operating system and version: Centos7
Apache or nginx version: 2.4.6
PHP version: 7.4.4

The issue you are facing:
NextCloud PHP does not render when accessing the site.

Is this the first time you’ve seen this error? (Y/N):
Yes.

Steps to replicate it:

  1. Install NextCloud fresh
  2. Create VirtualHost file in the way described above
  3. Access the website through http.

The output of your Nextcloud log in Admin > Logging:

Not sure what this is referencing to.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => '',
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '192.168.x.x',
    2 => 'web.address',
  ),
  'datadirectory' => '/custom/data/directory',
  'dbtype' => 'mysql',
  'version' => '18.0.3.0',
  'mysql.utf8mb4' => true,
  'overwrite.cli.url' => 'http://www.localhost/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'user',
  'dbpassword' => 'pw',
  'installed' => true,
  'maintenance' => false,
);

The output of your Apache/nginx/system log in /var/log/____:

[Wed Apr 01 01:02:37.158920 2020] [ssl:warn] [pid 12728] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Wed Apr 01 01:02:37.188924 2020] [mpm_prefork:notice] [pid 12728] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.4 configured -- resuming normal operations
[Wed Apr 01 01:02:37.188977 2020] [core:notice] [pid 12728] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Wed Apr 01 01:14:33.630505 2020] [mpm_prefork:notice] [pid 12728] AH00170: caught SIGWINCH, shutting down gracefully
[Wed Apr 01 01:14:34.713637 2020] [core:notice] [pid 13493] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Wed Apr 01 01:14:34.714386 2020] [suexec:notice] [pid 13493] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Apr 01 01:14:34.735247 2020] [lbmethod_heartbeat:notice] [pid 13493] AH02282: No slotmem from mod_heartmonitor
[Wed Apr 01 01:14:34.735317 2020] [ssl:warn] [pid 13493] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Wed Apr 01 01:14:34.761225 2020] [mpm_prefork:notice] [pid 13493] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.4 configured -- resuming normal operations
[Wed Apr 01 01:14:34.761246 2020] [core:notice] [pid 13493] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

For some reason the tag in the Apache config, was not considered after creating the virtual host file. By adding the php handler tag to the class in the VirtualHost file (e.g. /etc/httpd/sites-enables/www.example.com.conf) the page does load correctly:

   <FilesMatch \.(php|phar)$>
       SetHandler application/x-httpd-php
   </FilesMatch>
1 Like