I currently have a laravel 5.8 instance working on my local machine, I moved the files over to a Staging server that runs on Centos. I recently updated the PHP version there to 7.3 it was at 5.4 Now I’m trying to get the server up and display the webpage but I keep getting a strange error.
I’ve already restarted the whole server.
I went to /var/www/myproject/public_html/staging/app/Exceptions/Handler.php:50 (this is vendor files though)
public function report(Exception $e)
{
if ($e instanceof Exception) {
$debugSetting = Config::get('app.debug');
Config::set('app.debug', true); //<--- This is line 50
//echo "<pre>" . $e . "</pre>";
$data = ['content' => $e->getMessage(),'line' => $e->getLine(),'trace' => $e->getTraceAsString()];
Config::set('app.debug', $debugSetting);
}
return parent::report($e);
}
If you’re familiar with Laravel you would know that Config is a part of the core functionality of the project and for it to not be able to access it means something else is wrong that is making it not to be either set correctly or instantiated incorrectly.
I just tried to run composer update or composer install but this error is also preventing me.
I also checked the httpd/ssl_error_log and it says almost the same error as shown below
PHP Fatal error: Uncaught Error: Class 'Config' not found in /var/www/myproject/public_html/staging/app/Exceptions/Handler.php:50nStack trace:n#0 /var/www/myproject/public_html/staging/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(314): App\Exceptions\Handler->report(Object(Symfony\Component\Debug\Exception\FatalThrowableError))n#1 /var/www/myproject/public_html/staging/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Foundation\Http\Kernel->reportException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))n#2 /var/www/myproject/public_html/staging/public/index.php(57): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))n#3 {main}n thrown in /var/www/myproject/public_html/staging/app/Exceptions/Handler.php on line 50
My Error
PHP Fatal error: Uncaught Error: Class 'Config' not found in
/var/www/myflexca/public_html/staging/app/Exceptions/Handler.php:50
Stack trace:
#0
/var/www/myproject/public_html/staging/vendor/laravel/framework/src/Illuminat/
Foundation/Console/Kernel.php(367): AppExceptionsHandle->report(Object(SymfonyComponentDebugExceptionFatalThrowableError))
#1
/var/www/myproject/public_html/staging/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(132):
IlluminateFoundationConsoleKernel->reportException(Object(SymfonyComponentDebugExceptionFatalThrowableError))
#2 /var/www/myproject/public_html/staging/artisan(35):
IlluminateFoundationConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput),
Object(SymfonyComponentConsoleOutputConsoleOutput))
#3 {main}
thrown in
/var/www/myproject/public_html/staging/app/Exceptions/Handler.php on line 50
SOLUTION
I fixed this by changing the
use Config;
at the top to
use IlluminateSupportFacadesConfig;
It was only followed by more errors but it got past this one.
REAL PROBLEM
My Laravel dependencies were not up to date. The real solution is to re-install Laravel to get the dependencies.
composer global require laravel/installer
2
Answers
My solution to my problem ended up being for me to reinstall Laravel using
It turns out that the server I was moving it to didn't have all of the updated dependencies that was needed for the updated instance of Laravel. Before trying anything else try doing this to see if it needs updating/reinstalling.
If you’ve just changed from PHP version, you probably have vendor files for the older PHP 5.x version that contains legacy/deprecated code for the new versions of PHP 7.x
Based on that, I recommend deleting the
composer.lock
file, thevendor
folder as well and then, execute composer again withcomposer install
.As the
composer.lock
doesn’t exists anymore it’ll make a clean install for your new PHP version.Hope it helps.