0

Before you continue to read - the issue has been fixed

Well... this is kinda weird.

I'm working on a web app for some friends. I have a working version uploaded to their hosting, and, suddenly, it stopped working a couple of days ago.

I haven't added anything or changed anything on the server. There is no error, simply the app stopped loading and a blank html page is loaded instead.

I've traced the problem until /vendor/composer/autoload_real.php file.

In the end of the static class inside this file, there is a loop where several other files are being included (actually requested), I've checked that when it tries to request /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php, the system stops. Obviously, I've checked that the file is there, and it isn't been touched.

Well, I'm positive I've didn't changed anything on this part of the app (it's core framework, and I usually don't mess up inside), but just of a sudden it stopped working.

The working copy on my computer just works fine. I've uploaded my copy of helpers.php, but nothing changed.

Anyone had experienced similar issues recently? Anyone has any idea about how to fix it?

EDIT: It's been several days since I could check on this for the last time. Now I've been tracing raw php execution on /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php file. This is, I've started echoing messages and trying to execute just this file, to see where code execution is stopped.

I know this is very crappy debugging, but I haven't access to apache nor I can restart it, and it seems there is no easy way to get an error code without this.

So patiently trying I've reached two points where execution stops on this file:

Creation of factory method

if (! function_exists('factory')) {
    /**
     * Create a model factory builder for a given class, name, and amount.
     *
     * @param  dynamic  class|class,name|class,amount|class,name,amount
     * @return \Illuminate\Database\Eloquent\FactoryBuilder
     */
    function factory()
    {
        $factory = app(EloquentFactory::class);

        $arguments = func_get_args();

        if (isset($arguments[1]) && is_string($arguments[1])) {
            return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ?? null);
        } elseif (isset($arguments[1])) {
            return $factory->of($arguments[0])->times($arguments[1]);
        }

        return $factory->of($arguments[0]);
    }
}

and creation of mix method

if (! function_exists('mix')) {
    /**
     * Get the path to a versioned Mix file.
     *
     * @param  string  $path
     * @param  string  $manifestDirectory
     * @return \Illuminate\Support\HtmlString|string
     *
     * @throws \Exception
     */
    function mix($path, $manifestDirectory = '')
    {
        return app(Mix::class)(...func_get_args());
    }
}

In both cases func_get_args is involved... I haven't a specific error, but I have the tingling that the problem is related somewhat to the fact that this function isn't returning anything.

EDIT2: Ok, I tried php artisan and composer commands suggested on answers to no success. The issue is still there.

I've also deleted the logs and checked that no new log was created while trying to load the site.

I've tried a clean laravel install from scriptaculous on a new directory (I've done this when I first uploaded the site, it worked perfectly for several months) and this new install doesn't reach the front page neither. A blank page (on Firefox) or a 500 error (on Chrome) is shown instead.

I forgot to mention an important data. My app is sharing space with a wordpress instance. The wordpress is installed on public_html, and my site on public_html/mySiteDirectory. This hasn't supposed any problem so far more than make me tweak lightly .htaccess file to make routing work fine.

There is also a phpbb forum sharing space on it's own directory inside public_html.

I wonder if any of those could have somewhat been upgraded and produced this strange outcome.

Also... laravel app_debug is enabled on .env file since the beginning, but never showed anything. This seems to be something that fails before laravel framework is fully loaded.

EDIT 3: IT'S FIXED.

Well... first of all, let me thank you all for your help. Actually there wasn't one answer that fixed the problem, but many of you suggested to use phpInfo() to check php version which ultimately led to the true problem.

Yes... surprisingly, although php -v on terminal showed php 7.2 running on server, and cpanel php management tools showed also php 7.2 installed and running, when I used phpInfo(); php 5.6 was showed on the response.

I used the own cpanel tools to make an upgrade/downgrade to 7.3 and again to 7.2 and et voilá phpInfo(); shows 7.2 and the page is again up and running.

I'll try to share the reward between several answers (don't know if something like that is even possible), and will +1 every answer suggesting phpInfo(); as it showed as the key to fixing this problem.

If I cannot share the reward I'll accept as final answer the one from Don't Panic, as it was the one that convinced me that there was a problem with php versions.

Adam
  • 25,960
  • 22
  • 158
  • 247
Bardo
  • 2,470
  • 2
  • 24
  • 42
  • 3
    Check error logs, post any relevant error message here, otherwise we can't help you. Php error logs, nginx or apache error logs, laravel error loga (under storage/logs). If you don't changed anything, or your server have upgraded php version, or you have some server problem like out of disk space, or corrupted files. – Elias Soares Mar 21 '20 at 17:27
  • 2
    "the system stops" what do you mean with this? Again, error messages aren't monsters. Read them! – Elias Soares Mar 21 '20 at 17:29
  • That's the problem. I haven't find any error yet. Just the framework initializing stops at the point I stated on the question, this is why I'm so lost, if I had an error to investigate shouldn't be here asking about any ideas. I'll try to check apache logs from hosting's cpanel to see if there is anything. I didn't find anytyhing on php nor laravel logs. – Bardo Mar 22 '20 at 21:55
  • What do you mean by stops? Be clear! What's the result on the browser? Blank page? What status code? 500? – Elias Soares Mar 22 '20 at 22:12
  • If you read carefully the question, you'll see I've stated that a blank html page is loaded. There is no error, no alert message or response code. – Bardo Mar 23 '20 at 06:57
  • 1
    You can see the response code on chrome developer tools at network tab. Usually when errors occurs, the response status code will be 500. Most of apache and nginx setups are made to hide out any error message, so you get that blank page. But somewhere the error log should be written. If not, you can temporarily enable error outputting in php (https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Elias Soares Mar 23 '20 at 10:15
  • Did you by any chance changed something in the .env file before this thing happened? – George Koniaris Apr 09 '20 at 16:45
  • @GeorgeKoniaris nope, I didn't. – Bardo Apr 10 '20 at 10:37
  • 1
    What are the exact versions of PHP (use `phpinfo();`) and Laravel? – Don't Panic Apr 11 '20 at 04:23
  • @Bardo Glad you cracked it! :-) – Don't Panic Apr 12 '20 at 10:50

7 Answers7

4

If you look at the code in the functions you have traced the problem to, both contain interesting or less-common PHP features:

  • factory() includes ??, the null coalescing operator. This was introduced in PHP 7.0.

    I see in a comment you added to another answer that you are using PHP 7.2. This question describes Laravel failing in factory(), because even after upgrading to PHP 7.2, and phpinfo() showing 7.2, Apache was still using PHP 5.6. This seems unlikely, but when all else fails ... ?

  • mix() includes ..., the spread or splat operator. This was introduced in PHP 5.6, but there are reports of it failing in Laravel with 7.x due (AFAICT) due to mismatches between the PHP versions Apache and the CLI are using.

    Considering you mentioned you uploaded the code from your local machine (rather than using php composer install), and that CPanel tends to update PHP automatically and silently, this seems like a possibility - there are 4 PHP versions in play (CLI/web on your machine, and CLI/web on server), and they all need to be in sync.

As a side note, as you've already discovered you are really working blind without the logs. Either the PHP and/or Apache logs will give you more info, typically describing exactly the problem, and save you having to manually trace things as you've been doing. If those logs aren't showing anything, maybe PHP isn't configured to log errors - try enabling that.

It probably depends on your CPanel version and config, but standard locations for your logfiles are typically:

  • Apache access log: /usr/local/apache/domlogs/<your-username>/
  • Apache error log: /usr/local/apache/logs/error_log
  • PHP error log: /home/<your-username>/public_html/error_log
Community
  • 1
  • 1
Don't Panic
  • 13,965
  • 5
  • 32
  • 51
1

Start wtih composer dumpautoload. Then run php artisan optimize:clear. Re-upload the whole site and you should be good to go. I have experienced a very similar issue. Do you run a pipeline on the server or are you just FTP-ing the site up? Are you able to run composer on the server and the same for artisan? If you can, you need to those commands there are as your cache is often based on your host computer drives and will fail in prod.

Munsterlander
  • 1,356
  • 1
  • 16
  • 29
  • Done, no success. More info added on question – Bardo Apr 10 '20 at 11:17
  • Ok, then does ANY php template get served? Can you do a basic `phpinfo()`? I know you are tracing execution, but lets just verify apache and php are playing nice. Then I would start on the error with the mix first. Do you have a `webpack.mix.js` file on the server? Did you run `npm run prod` or `npm run dev` prior to upload? Are your storage and bootstrap/cache set to 755? I have had issues with 755 before and had to go 777 on apache 2.4. Let me know, because now I am intrigued. – Munsterlander Apr 10 '20 at 15:52
  • Finally it was a matter of php versions running on server. Check last edit on question for further info – Bardo Apr 12 '20 at 10:32
1

Simply replacing the file might not be helpful. Try enabling the error log or check if you are able to reach this file bootstrap/app.php. If yes it means there is no problem in the composer. Try checking the version of PHP installed and if it is compatible with your Laravel. Try checking PHP Error Log. It might be helpful.

Vimal Rai
  • 757
  • 5
  • 6
0

Ok I should mention a few things

1: Go to storage/logs directory and delete all *.log files then you refresh the web page and you'll check out to see for any log file if there is no log file it means it's related to server configuration and etc. if there is a log file you read it and you post it in here

2: Did you pull the code on cpanel by console command using version control system like git or svn or you just uploaded it in a classic way, if you indeed pulled it with VCS you may did a composer update instead of composer install which will updates all packages as possible as defined in composer.json file and you may have got a higher version of vendor than your local and something may broke in there.

3: You may have a different php version on server vs your local which many times casing real problems.

I can't tell for sure until you post your log file here

AH.Pooladvand
  • 1,944
  • 2
  • 12
  • 26
  • Deleted the logs on storage/logs and tried to access the page. No log file was created. – Bardo Apr 10 '20 at 10:51
  • I upload files through file manager (although use git on my computer). PHP version is 7.2 in both, server and my computer. – Bardo Apr 10 '20 at 10:54
  • I'm prone to think this is a server related issue. I've tried to make a clean install of laravel from scriptaculous (I did this the first time I uploaded the app and it was working several months) and the new clean install doesn't reach the front page neither. Just laravel, without anything more. – Bardo Apr 10 '20 at 11:06
  • Then it has to be server related issue – AH.Pooladvand Apr 10 '20 at 12:37
  • Any idea about how to approach it? – Bardo Apr 11 '20 at 14:09
  • Honestly server issues which are `500 server error` they could have wide variety causes and also I'm not really a cpanel guy but if you have access to ssh you can start by tracking apache logs or any other web server that you're using it could be permission issue, could be owner issue, it could be anything, if I were you I was trying to get a simple hello world in an Html file then proceed from there – AH.Pooladvand Apr 11 '20 at 16:04
0

So here is what i would have done.

If it is possible simply turn0on debugging, this will show you the error in the web browser itself (you can do that from .env file)

You can also read the laravel log file for errors as mentioned earlier.

If you do not want to do this, run the following commands

PHP artisan cache:clear

PHP artisan route:cache

PHP artisan config:cache

PHP artisan clear-compiled

PHP artisan optimize

If you could share more details that would help...

Hamid Ali
  • 194
  • 2
  • 8
0

Have you checked permissions and ownership for storage and bootstrap/cache folder?

these permissions need to be set for the app to work

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Sidharth
  • 1,675
  • 1
  • 15
  • 23
0

I tried everything and nothing worked. The best solution for me was that I deleted cpanel files and reuploaded all the codes.

Akash Sethi
  • 184
  • 1
  • 4
  • 15