Laravel Artisan Serve cannot detect mysql when using Mamp - laravel

Sometimes I can't run php artisan migrate if I'm using mamp. It yield this error:
[PDOException] SQLSTATE[HY000] [2002] No such file or directory
Why would this be happening?

Sometimes you have to exclusively tell Laravel where the unix_socket location. In case of Mamp, you should add this line to your mysql config:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
If you are using xampp, the location would be C:/xampp/xamppfiles/var/mysql/mysql.sock.
To get path to your active socket file, try login to your mysql server and run status command.

Related

Laravel can't access database

I cvurrently have a laravel application running on heroku, the issue here is, I keep getting the error that I can't connect to the database: SQLSTATE[HY000] [1045] Access denied for user 'user'#'ec2-54-74-209-179.eu-west-1.compute.amazonaws.com' (using password: YES). Now the host is wrong here, the environment files are TOTALLY different (except for the username) then what the error gives....
How can I resolve this issue?
I've tried to use the DB_URL env, but that gives the same result...
Did you set the .env correctly on what's running on their server?
You can see all your projects in laravel at TOOLS->DEPLOYEMNT->CONFIGURATIONS
add all the info and connect to the remote project. I did the same and changed the .env directly there.
and of course you have to clean all the cache cause even if you change the .env it will not work until you'll clear it
php artisan cache:clear;
php artisan config:clear;
php artisan route:clear;
Obviously this need to be executed on the project on heroku or aws (as it appears from the Error)

Laravel is using the default homestead user details to connect, even though these have been deleted

I am using laravel 5.8.6 and can connect to my database using the artisan migration tool, and can read and write to the database using tinker with no issues.
When I launch the default scaffolding it fails to connect, complaining that the login failed for user homestead#localhost.
I have deleted the .env.example file and cleared the various cache files with no success.
A full search for homestead only reveals log entries:
Illuminate \ Database \ QueryException (1045)
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `users` where `email` =
Any ideas gratefully received.
I had the exact same problem and I just couldn't wrap my mind around how that was even possible. Turns out I seem to have changed the .env file after having started the dev server via php artisan serve. It doesn't pick up changes in the .env config at runtime and it caches the configuration.
After running
php artisan config:clear
, shutting down the dev server and restarting it, the issue was resolved and the database connection successful with the correctly set database credentials.

Laravel [PDOException] SQLSTATE[HY000] [2002] Connection refused

While pushing homestead repo to live server, i encountered the following error.
I can confirm that i can connect to mysql from the command line using the variables set in the .env file.
I know that it has something to do with this particular setup, as i am effectively operating a similar laravel 5.1 project on the same host.
I noticed that on the error page that i was looking at the top message, which was 3/3. Looking to the 1/3 (the first error) error helped me find the solution.
Laravel was still using the homestead credentials.
i found this by searching:
grep -r "homestead" .
returns
./bootstrap/cache/config.php: 'database' => 'homestead',
To clear the cache all that was left was to do was clear the cache.
php artisan config:cache

Access denied 'homestead'#'localhost' when running a Laravel Command

I'm having some trouble getting Laravel to connect to my database, when using a custom Artisan command.
I can post my command but I'll skip to my db settings as I suspect that is what is wrong. In start.php I have:
$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
and then I have no local/database.php files in my config. Instead I have a .env.local.php which works great for everything except this. All database settings are set as 'DB_NAME => getenv('DB_NAME'); etc.
When I run php artisan custom:command I get the following:
[Illuminate\Database\QueryException]
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: select * from `users` where `paused_until` = 3)
Then if I run
php artisan fdb:reactivate-paused --env=local
I seem to get much closer but still get:
Access denied for user 'homestead'#'localhost' (using password: YES)
Is it that Laravel doesn't know to use the .env.local.php file when I am running commands in the terminal? All my migrate and db:seed queries seem to work fine. Can anyone point me in the right direction?
Looking at it again this morning, I must have been 100% burnt out. I was running the command from my Local Machine, not the Homestead VM.

Laravel Homestead- How to migrate an app into the same folder and connect the MySQL database?

I was able to do install Homestead and to create a new app within the virtual machine.
However, I do have apps that I created outside the virtual machine and I would like to connect my database now. It is editable under localhost/phpmyadmin, it is my mysql standard installation in port 3306.
I have the folder that I have from the Internet and the first app that I specified is called Laravel, how do I do that?
If I just copy it in the same directory, I get:
php artisan serve
PHP Fatal error: Class 'Barryvdh\Debugbar\ServiceProvider' not found in /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 157
PHP Stack trace:
PHP 1. {main}() /home/vagrant/Code/foobooks/artisan:0
PHP 2. require_once() /home/vagrant/Code/foobooks/artisan:30
PHP 3. require() /home/vagrant/Code/foobooks/bootstrap/start.php:68
PHP 4. Illuminate\Foundation\ProviderRepository->load() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/start.php:210
PHP 5. Illuminate\Foundation\ProviderRepository->compileManifest() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:57
PHP 6. Illuminate\Foundation\ProviderRepository->createProvider() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:121
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'Barryvdh\\Debugbar\\ServiceProvider' not found","file":"\/home\/vagrant\/Code\/foobooks\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php","line":157}}vagrant#homestead:~/Code/foobooks$
vagrant#homestead:~/Code/foobooks$ cd laravel
-bash: cd: laravel: No such file or directory
Move your database from your host machine into homestead:
Install laravel homestead
Copy your app into your shared folder (I guess you did that so far)
backup your database from your host machine
Migrate your database in homestead with artisan migrate if you want a clean and empty database structure.
OR: Rebuild it from your backup. Make sure the database user/password specified in your laravel config exists in homestead and has write access to your rebuild database.
Your homestead database is still accessible from your host machine at 127.0.0.1 and port 33060 (http://laravel.com/docs/4.2/homestead#daily-usage)
Here is a nice tutorial for homestead 2.0 in case you have problems to setup: https://laracasts.com/lessons/say-hello-to-laravel-homestead-two

Resources