hInterface 'Throwable' not found - laravel

when querying the database with sql error laravel throws Throwable interface not found instead of the query exception.

i have a same trouble yestoday with 'laravel new demo', meybe the repository server has error before. i rebuild my laravel project with 'composer create-project laravel/laravel=5.4 demo --prefer-dist' this afternoon, it work! do like this.

In my last project, I got this error too. I used php 5.6.30 version. When i upgrade to 7.0.1 version, everything is fine. http://php.net/manual/en/class.throwable.php

I was using php5.6 and got this after I did composer update.
So I installed the php7.1 following this answer
Then I disabled php5.6 using
sudo a2dismod php5.6
and then I ran the following to enable 7.1
sudo a2enmod php7.1
and finally restarted apache2 using.
sudo service apache2 restart
and it worked.

I fixed mine when I did a netstat -tln and found out the mysql is running 0:0:0:0:3306, and on my .env file is set to DB_HOST= 127.0.0.1. I changed it to DB_HOST=localhost and is working fine right now.

Related

How to enable php-Mcrypt extension in Laravel Homestead

I am trying to get an old Laravel 4.1.x app up and running again so that it can be modernized. This requires an environment with PHP 5.6 and the Mcrypt extension. I have installed Homestead 9.0.3 (the latest stable version). Within the VM, I have set the PHP version to 5.6
sudo update-alternatives --config php
I have then installed the php-mcrypt extension
sudo apt-get install php5.6-mcrypt
I am now able to create a new Laravel 4.1.x project, which is a process that requires Mcrypt to complete, so we're certainly getting somewhere:
composer create-project laravel/laravel="4.1.*" myAppName
However, when I browse to the webpage for myAppName, I see the message:
Mcrypt PHP extension required.
I have also tried steps that are usually recommended for this problem, ie:
sudo ln -s /etc/php/5.6/conf.d/mcrypt.ini /etc/php/5.6/mods-available/mcrypt.ini
sudo phpenmod mcrypt
sudo service php5.6-fpm restart
But I still get the same message in the browser.
What step have I missed?
With homestead v9 you should be up and running with php5.6 out of the box as stated in
here, but unfortunately it is not your case, and I understand that...
Old packages were not installed by default (php5.6-mcrypt), as you mentioned and they should be added by hand via:
sudo apt-get install php5.6-mcrypt
After that all packages are ready, up and working, especially php5.6-mcrypt.
The root of your problem is in multiple site definitions under your homestead.yaml.
Most probably some of them are overlapping and your nginx is referring to the wrong resource/site_definition, and wrong paths.
Therefore you might think some strange php versions or routes are run/executed.
You can verify that, by deleting some/all of them, leaving the only one important for you - in (/etc/nginx/sites-enabled/...).
Of course please do that inside the container and issue sudo service nginx restart, afterwards...
All of your problems should be gone after that.
If something goes wrong. You could easily recover your current installation to current state using vagrant destroy and vagrant up afterwards, cause all is saved in Homestead.yaml.
In my installation Homestead v9 is running with php5.6 on laravel 4.1 without any problems...
Hope it helps #jsm...
Because all the PHP versions installed on homestead you need to set the PHP version for a site in the Homestead.yaml.
First check what version the server is running with phpinfo();
Check the file /etc/nginx/sites-enabled/homestead.test and look for this line:
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
If you didn't set the php version on the sites list, this file will be pointing to the php7.3.sock.
In this case the version 5.6 has mcrypt installed, but 7.3 don't.
You can just replace the line
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
for
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
and then reload nginx with sudo nginx -s reload.
Or set the php version on Homestead.yaml:
sites:
- map: homestead.test
to: /home/vagrant/code/public
php: "5.6"
And then run vagrant provision, it will change the nginx configuration for PHP 5.6.

Laravel error - Class setEventDispatcher does not exist

Short version
I'm getting this error, when I run php artisan serve and visit my home page:
ReflectionException (-1)
Class setEventDispatcher does not exist
Details
Laravel version: 5.6.39
Environment: local
OS: macOS Mojave 10.14.2
It started, when I got an error using npm (in another project), so I reinstalled Node (this way).
After doing that, then this project (in question) couldn't be started. I was getting this error, when running php artisan serve:
dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib with anything php related
Referenced from: /usr/local/bin/php
Reason: image not found
That error was resolved by updating and upgrading brew.
Then I was capable of starting the project (php artisan serve). But when I visit the home page, this error was shown:
ReflectionException (-1)
Class setEventDispatcher does not exist
If I follow the stack trace, then I can see that it was this line (from my homeController) that triggered the error:
if( ! Auth::check() ){
return view( 'pages.home' );
}
If I commented that out, then the same error occured from another place, where the Auth-module was being used.
Here's the stack trace:
Does anyone know how to resolve this? I can't find any promising results on Google, - and I have no idea why this happens... :-/
Addition1
I tried composer clear-cache and deleting the vendor-folder, and then doing a composer install and the problem still occured.
I also checked my Service Providers, as Marcus suggested, - but I don't really know what to look for in there. It all looks pretty regular (no fancy if-statements or anything).
Addition2
I realized, that I couldn't connect to my database using Sequel Pro. And it was because Brew had updated my MySQL-version from 5.5 to 8.0.
That was resolved by doing something along these lines (I did a bunch of stuff, so I might be missing a coulple of steps):
brew unlink mysql
brew install mysql#5.7
brew switch mysql 5.7.21
brew link mysql
and I could then verify the version with mysql --version. I also had some permission issues with that MySQL-version-change, but I'm emitting that, so this doesn't get too long.
Addition3
I tried disabling the Laravel Debugbar (by deleting it from composer.json, deleting composer.lock and vendor and then running composer install). And that fixed it!! ... But!
When I later tried to install Barryvdh's IDE Helper, then the exact same error came back!?
I performed these three steps, to install the IDE Helper (and re-introduce the error):
Run this command from the root of my directory: curl https://gist.githubusercontent.com/barryvdh/5227822/raw/4be028a27c4ec782965bb8f2fdcb4c08c71a441d/_ide_helper.php -o _ide_helper.php
Add these lines to app/Provider/AppServiceProvider.php:
...
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
Run this command: composer require --dev barryvdh/laravel-ide-helper
So I'm back at this error:
ReflectionException (-1)
Class setEventDispatcher does not exist
... The stack trace is identical to the one shown previously (sprung from Container.php).
Tried every solution, none of them worked.
Finally, i realised that when trying to upgrade php to 7.3.3 it was infact a network error that caused the fail. Read the logs, tried again, restarted valet and tried again.
It works now.
Upgrading to 7.3.3 was the solution indeed.
Thank you!
So this is what usually fixes it for me
Reinstall composer dependencies by removing vendor folder and composer.lock. Then run composer clear-cache and then composer install (this is usually the problem)
Check that all service providers are imported correctly in app.php under directory config
Make sure that your service providers are not importing something that does not exist, for example if you register a service provider in production but is only installed as dev:
if (env('APP_DEBUG')) {
$app->register(Barryvdh\Debugbar\LumenServiceProvider::class);
}
If you use valet, I solved it running
valet restart and all works fine.
cheers!
The fix for me was to update PHP to 7.3.3 and then restart valet. Apparently this was a bug with php 7.3
https://github.com/laravel/framework/issues/27052
Hope this helps
I got some idea... I've just run into this problem after reconfiguring my apache virtual host ports, so I restarted apache/httpd again, and the problem went away. Might it be related with the server environment?
I am facing the same issue in mac book pro. My system configuration is PHP 7.3, MySQl and I use SQL Pro. I have implemented all the above methods but nothing gets worked.
The issue is still a mystery for me but for temporary I have solved this issue using
artisan command as bellow.
php artisan serve
Its Allow me to run the project on http://localhost:8000
Hope this can help to solve this issue.
Try to restart PHP. When I reboot my Mac, then this happens. After restarting PHP everything starts to work.
sudo brew services restart nginx

PDOException could not find driver

I'm getting this error when i try to migrate. Im trying to run my project on postgres on MAC OS. Any suggestion how can i do this? I uncomment this in php.ini
but i nothing happend.
extension=php_pdo_pgsql.dll
extension=php_pgsql.dll
add this line in php.ini
extension=pdo_mysql.so
and then install the PDO by running following command:
sudo apt-get install php-mysql
EDIT
and also try to restart your computers sometimes it happens that restarting apache did not reloads the configuration

Has anyone got memcached to work on Laravel Homestead php7 box?

I loaded up Laravel/Lumen on the new Homestead php7 box and encountered this error:
FatalThrowableError in MemcachedConnector.php line 51:
Fatal error: Class 'Memcached' not found
Doing a phpinfo(); shows there is no memcached extension, but sudo service memcached status says memcached is running. It seems there is a php7 branch for memcached here: https://github.com/php-memcached-dev/php-memcached/tree/php7
Can anyone guide me on how to get it working in the new php7 Homestead VM?
EDIT: I just saw on the homestead install documentation that it says "Memcached (PHP 5.x Only)". Question still remains on how to get it working.
The work on php-memcached for PHP7 is not yet complete, not all tests pass; You can use everything but JSON serialization, I think.
There is no pecl support for PHP7, so right now you need to install extensions manually, like this:
git clone https://github.com/php-memcached-dev/php-memcached
cd php-memcached
git checkout php7
phpize
./configure
make
sudo make install
You must make sure that phpize is the PHP7 version. Additionally, if the php in your PATH is not PHP7, then the php-config in your PATH is not either, in this case you must pass --with-php-config=/absolute/path/to/php7-config to ./configure.
I have the same problem, but on Windows when using XAMPP. It seems memcached works for now with PHP 5+ only.
The problem for Windows users is to find the right .dll file named
php_memcache.dll (x86/x64 platforms).
I've spent hours looking for a solution, but nothing found. The very fresh description how to use memcached is here:
HOW TO: Install Memcache on XAMPP (Windows 7/8/10)
We still have to wait for PHP7+ implementation.

Laravel Migration Error :: PDOException, Could not find driver

I am trying to make a laravel and stucked when migration. when i enter php artisan migrate in terminal, showing PDOException error. attaching my screenshot of terminal and phpinfo.
What i sthis issue, How can i solve this,
I am using Xampp.
Anybody please help me.
Thanks
Try re-installing Xampp? You could use Laravel homestead for a virtual machine, it makes sure you have the proper PHP version and the required dependencies needed to install and avoids having to run Xampp or MAMP or WAMP or any of the amps.
It looks like Xampp cannot find: /usr/lib/php5/20121212/php_pdo_mysql.dll, so make sure that file exists.
You may need to re-install PHP PDO on your machine, refer to: http://php.net/manual/en/pdo.installation.php
Also per PHP docs:
PDO and all the major drivers ship with PHP as shared extensions, and
simply need to be activated by editing the php.ini file:
extension=php_pdo.dll
Please check you have installed more than one php version in your system, one is running for web server and another for php CLI, using PHP_INFO for web and php --ini in commandline, if different version found then upgrade or downgrade means make it one version configuration, and make sure PDO is enable in your system.
From php5.6 to php7.0:
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php7.0
From php7.0 to php5.6:
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php5.6

Resources