Nextcloud Nightmare - php code is shown instead of web interface

Thanks for the suggestions.

@NeptuneUK hereā€™s what I get when I run apachectl configtest: Syntax OK
and hereā€™s the contents of /etc/apache2/sites-available/nextcloud.conf:

Alias /nextcloud "/var/www/html/nextcloud/"
<Directory /var/www/html/nextcloud/>
    Options +FollowSymlinks
    AllowOverride All
      <IfModule mod_dav.c>
        Dav off
      </IfModule>
 
     SetEnv HOME /var/www/html/nextcloud
   SetEnv HTTP_HOME /var/www/html/nextcloud
</Directory>

@victorbw Iā€™ve tried your two suggestions, both with no change. (Still getting Internal Server Error.)
apache2: nextcloud.conf is listed above, and hereā€™s Nextcloudā€™s config.php:

<?php
$CONFIG = array (
  'instanceid' => 'oc1cyu2az99f',
  'passwordsalt' => 'XXX',
  'secret' => 'XXX',
  'trusted_domains' => 
  array (
    0 => '99.99.99.99',
  ),
  'datadirectory' => '/media/nextcloud-data',
  'dbtype' => 'mysql',
  'version' => '17.0.2.1',
  'overwrite.cli.url' => 'http://99.99.99.99/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'XXX',
  'dbpassword' => 'XXX',
  'installed' => true,
);

Youā€™d need to add DirectoryIndex index.php above the Options line inside the Directory statement.

Depending on your Apache/PHP setup you have to tell Apache that .php files should be handled with PHP.

    <FilesMatch "\.(php|php[57]|phtml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>

I tried that, restarted Apache, and Nextcloud did allow me to sign in. Then, clicking on Admin/Services it crashed back to displaying ā€œInternal Server Errorā€.

So I removed your code and restarted Apache again. Still ā€œInternal Server Errorā€. As a last resort, I stopped and started both MySQL and Apache and found I could access the site ā€“ for a while.

Nextcloud now stays up sometimes for minutes at a time, then ā€“ while in the middle of simple housekeeping tasks such as adding an email address for admin ā€“ it simply crashes out to the login screen. And wonā€™t let me log in again. Nothingā€™s changed. Thereā€™s only one user and one password, but it insists theyā€™re wrong. The only way to get back in is to restart MySQL and Apache, then I can log in again.

Just tried it again. Clicked on Admin/Apps. Bang! Out again to the login screen but no login accepted. Stop and start MySQL and Apache and I can get back in again ā€¦ for a few more minutes.

There are no significant issues on the Overview ā€“ just a warning about using HTTP ā€“ and the NC Security Scan gives the site an A rating.

You shouldnā€™t try to change more than one thing at a time, when performing such kind of trouble shooting. First, Iā€™d rule out the MySQL instanceā€¦ no need to restart it, if itā€™s working. So before you restarted MySQL did you check to see, if it still runs and if you can connect to it using the credentials you have in your config.php?

1 Like

HI @GeoffP,

Thanks for the feedback on your nextcloud.conf and the apache syntax check.

They both seem fine in terms of configuration at the site level.

1.) Could you post the contents of your /etc/httpd/conf/httpd.conf?

2.) Was this install a fresh one, on a clean box? That is to say this box wasnā€™t in service prior to to your attempt to install NC?

3.) Does the server meet the recommended minimum installation requirements?

I noticed you deviated from the NC install guide you referenced.

As I installed on a virgin lightsail instance, using the same NC installation guide, OS (and version) and NC version, it would seem at this point to indicate that Ubuntu isnā€™t the issue, or NC. It would point to a configuration issue with Apache. Sometimes a small omission or typo can have bewildering effect.

It also seems that the original issue you posted is resolved. That is to say .php files are not being served as text/raw files. Correct us if this is not the case. It would seem you are now dealing with other issues. @budy gave some great advice, stick to the issue at hand, one at a time, implement a suggestion, test, evaluate, feedback and if not resolved move forward, just small steps one at a time.

My personal opinion at this point would be to do a completely fresh install from scratch on a clean box if this is possible. Follow exactly the guide you referenced, donā€™t change anything. Establish if the install and initial configuration is good. Then small steps to change data directory etc. Obviously remembering to backup your server at key points to enable you to roll-back if needed.

Hi @NeptuneUK,

Thanks for the response. In response to your pointsā€¦

  1. Iā€™m guessing you mean /etc/apache2/apache2.conf. (Thereā€™s no /etc/httpd/conf/httpd.conf in Ubuntu.) Itā€™s a 7K file so rather than post it here, Iā€™ve copied it to a Pastebin link: https://pastebin.com/yxEhWSLF

  2. Yes, this was a fresh install.

  3. Yes, the server meets the minimum requirements.

And yes, the original issue has been resolved, and thatā€™s lead on to the current issue.

Iā€™ve been developing and testing software for decades so Iā€™m well aware of the incremental nature of the debugging process, and that is partly why Iā€™m hesitant to do a fresh reinstall. NC is now working, sometimes for 10-15 minutes at a time. Then it simply crashes out to the login screen and refuses a login until I restart Apache. That suggests a problem in NC itself. (Or perhaps not. Having just typed the above, I had a crash out to an ā€œInternal Server Errorā€ screen which requires a restart of MySQL and Apache, then Iā€™m back to login.)

You say you tried a virgin install on Lightsail. Did you also run it for a while? Iā€™m back in again just now, looking at Logging, Apps, etc. then, after a few minutes, it crashes back to ā€œInternal Server Errorā€.

Iā€™m not sure what you mean when you say I deviated from the installation guide. The only deviation Iā€™m aware of was to reference attached storage when configuring Nextcloud. The reason I did that was because I followed the advice detailed here, specifically:

Changing data directory after installation is not officially supported. Consider re-installing Nextcloud with new data directoryā€¦

(The original was also in bold type!)

Wiping the server and starting again is an option, but that will destroy any chance of learning whatā€™s actually going wrong here ā€“ and perhaps finding a rare, gnarly bug that could affect someone else.

Hi @GeoffP,

So maybe it might be best to document which action you implemented that led to the original issue ā€œNextcloud Nightmare - php code is shown instead of web interfaceā€ being resolved, then marking this thread as closed and resolved, attributing whoever if anyone gave the solution that worked for you.

That done open a new thread with the new issue you are experiencing? It will make it easier for people to locate whichever issue it is they are experiencing and itā€™s resolution.

I ran the instance I span up for about 3 days, and it had a few visits other than myself. The instance remained available and stable during that time without crashing, displaying PHP as text/raw and there were no other issues in the error or sys logs. I obviously then terminated the instance as itā€™s billable.

Yes the deviation for the data directory is specifically what I was referring to. It wasnā€™t something you mentioned previously, and is important in terms of the operation of NC (NC checks the data directory and specifcally a text file written there). If NC is unable to read the text file for whatever reason (permissions, mountpoint availability etc) you can see the ā€˜internal serverā€™ error message, depending on what / how you mounted your data directory could have a bearing (eg a physical disc that is slow to respond to read requests after idling.) Also the omission could indicate other deviations you felt werenā€™t relevant, but that possibly could be.

1.) What do the apache / NC logs have to say about the ā€˜internal server errorā€™?

2.) What happens if you change the data directory to the default location (same physical media as you NC installation?) Do you get stability.

3.) Do a fresh install, following the guide you referenced EXACTLY and see if the issue/issues are replicated again. This could point to a issue with your data directory mountpoint / media etc depending on the result. (You can always backup your current installation using your preferred method dd, rsync, tar etc) and restore later to troubleshoot if you really want to find that gnarly bug.

Hi @GeoffP,

I just thought Iā€™d mention I also just did a quick install on an MS Azure compute unit (alternative Hypervizor to AWS), using the guide you referenced. All worked OK and as expected.

@GeoffP if you want a quick setup (on a new machine).

the default is nginx/postgresql so you have to change nextcloud_webserver_type = 'apache' and nextcloud_db_type = 'mysql'. follow the readme.

sounds like trouble with the server.

yes. month/years. depends. i run two ā€œbaremetalā€ and two ā€œdockerizedā€. on different hoster.

I succumbed. Dumped the AWS Lightsail image and started a fresh one. Again, I followed the installation guide I referenced in my first post ā€“ but without the extra storage, just a standard default install ā€“ kicked it off, signed in, dismissed the intro, clicked on Admin and bang: Internal Server Error.

Since then itā€™s continued to die at irregular intervals exactly as Iā€™ve described above. Each time it requires a stop and start of MySQL and Apache. A typical example occurred just now deleting a folder. A popup appeared on the right saying ā€œError deleting folder ā€¦ā€ and the session dropped back to the login screen. But I canā€™t log back in even after clearing the browser cache, etc. ā€œWrong username or password.ā€ Restart MySQL and Apache and I can log back in.

I can only conclude that itā€™s a server issue. AWS Lightsail running Ubuntu 18.04 canā€™t handle Nextcloud. Iā€™ll free up a local server and see if I have any more luck. Thanks for all your feedback and suggestions!

There is maybe a limitation on the AWS side.
I use this How To for installing and tweaking Nextcloud :

If you follow it, you wonā€™t get this error. Tested on real servers, vm and VPS

please could someone open a ticket at aws and let me know the answer. :sunglasses:

@GeoffP

Which AWS Lightsail instance type did you select?
Which region did you select?

Guys, make your life a bit easier, run the Nextcloud VM install scripts for Ubuntu Server 20.04:

@GeoffP,

Once again I just followed the guide to which you reference in your original post (just user and password changes).

Itā€™s up and running here: NO LONGER DEPLOYED.

Itā€™s Ubuntu 18.04, latest NC on a Lightsail $5 instance in London. All running fine (except it is topping out the RAM, obviously, bbut for a proof of installation box thatā€™s all Iā€™m prepared to spendā€¦ ) Took all of 5 minutes.

Added a NC test user with a miserly 500MB allowance, all OK. Been up for 30 mins no issues. Iā€™ll leave it up overnight and see what happens, but all looks good as it did before.

Iā€™ve used the referenced guide, Ubuntu 18.04, NC, Lightsail $5 London UK region. This is the second time Iā€™ve done this now and both times without issues. The only variable in this is you and I.

Hi @GeoffP,

So just deleted the Lightsail instance I span up, itā€™s run for 2 days without any issues.

I can only conclude the following:

AWS Lightsail (London Region) + Nextcloud + Ubuntu 18.04 + Referenced Guide = Good Installation and Configuration Candidate.

As my previous post, if you can advise which Lightsail Region and zone you are using and experiencing problems in, Iā€™ll try to duplicate. If that works OK, maybe you could consider creating an IAM for a Lightsail instance user and Iā€™ll create an instance in your AWS LS account and see what happens then.

Hi @enoch85,

As the OP seems to be on AWS, do you have instructions for an installation path on the AWS hypervisor stack?
Has this VM been tested on the AWS HVM Stack? Any feedback?

As long as itā€™s a clean Ubuntu Server 18.04 (which AWS provides) then the hypervisor doesnā€™t matter.

It runs perfectly fine on Digitalocean, and I have a hard time believing there would be any difference running AWS.

Boot up a machine and run the installer script, thatā€™s it. :slight_smile:

have you guys ever considered thinking about having a disk/lvm/partition filled to the top with logs??

as far as i can remember, I had one issue with a full partition which then ā€˜brokeā€™ my installation until removing *logs via ssh.

Is this issue solved? if yes, please mark the solution and edit the topic so people with the same issue can look it up.