Unable to run migration via artisan command - laravel

I have a Laravel 7 project and pushed it to a live server for production but I can't run migration successfully. I always get an error 'access denied' error.
I can confirm that the command sees the .env file and the connection details are all correct. When I ssh into the server and run mysql command using same parameters saved in the .env file, connection is successful. Adding the details into workbench and SequelPro also works so I am not sure why php artisan migrate doesn't work

Run the following command:
php artisan tinker
Tinker is Laravel's own repl.
It will prompt you to enter the commands. Here you can check and print the value of the environment variables by entering string inside env method.
>>> env('DB_DATABASE')
and so on for the other DB parameters.
Hope this helps.
For more help you can check out the official Github repository of tinker:
https://github.com/laravel/tinker

Related

How to run a command with arguments in Laravel Vapor

I Just started testing Laravel Vapor, everything working well except I'm using filament package which it needs to run a command to create admin user, the command is working locally on my computer and I have a user now, but in production when I execute the command (./vendor/bin/vapor command production) and then the command that creates the user (php artisan make:filament-user). vapor not giving any input to enter my name and my email address. So is there anyway to give arguments for commands in vapor? or is there anyway to give the these arguments with the command? thank you
simple, just use your command by command line in the console or inside vapor page, menu commands in your project, example:
php artisan <command_name> '<arguments_parameters>'
my job command with argument:
php artisan metric:consolidate '2022-01-29 00:00' (job name with date start argument).

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)

Not work "Migrate" and mysql in laravel project

I install laravel and create project.
I Configed configuration file database and create database in mysql(mysql runnig in wamp server).
I want use migrate for create table in mysql,but i should wait a lot of time and see error.
What shoud i do?
This could help you run these command in terminal:
php artisan migrate --force
The migrate:refresh will roll back all of your migrations then execute the migrate command.this will re-creates your entire database.
php artisan migrate:refresh
This will absolutely help you,run this command:
php artisan migrate:fresh
if it did't help please chick out this:
https://laravel.com/docs/5.7/migrations
Probably you entered your mysql Server credentials in the database config, but you have to edit the .env file. Values in there overwrite config settings.

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 Envoy on fortrabbit

I've setup a Laravel app on a Fortrabbit server. I can do the following
$ ssh user#server
$ cd htdocs
$ php artisan migrate
Which works perfectly fine.
But I'm trying to use Envoy for tasks like this. So I've made a simple task:
#servers(['test' => 'user#server'])
#task('task:test', ['on' => 'test'])
cd htdocs
php artisan migrate
#endtask
However, I encounter the following issue when doing so:
$ envoy run task:test
[user#server]: \(><)/ Welcome to the rabbit hole. \(><)/
[user#server]: [PDOException] SQLSTATE[HY000] [2002] No such file or directory
It might be worth noting that the db connection uses credentials from ENV variables set in the Fortrabbit interface. If i SSH into the server and do env, all the variables are listed as they should be. But when doing
$ ssh user#server env
I only get a small portion of the Fortrabbit server ENV variables.
I can't figure out what could be the cause of the error, and I haven't been able to find anything when asking Google. Could anybody shed a bit of light on this? Thanks alot.
As #ukautz said, the session scripts are not executed by envoy, that's why some of your environment variables are missing.
Here's what I did:
#servers(['dev'=>"<<user#server>>"])
#task('list')
. /etc/profile.envvars
env
#endtask
That showed all ENV variables, including those set by you on the dashboard !
Your script should work with this:
#servers(['test' => 'user#server'])
#task('task:test', ['on' => 'test'])
. /etc/profile.envvars
cd htdocs
php artisan migrate
#endtask
I suggest to check if your environment dedection works as expected.
$ php artisan env
If not, your can force the environment for artisan commands, like so:
$ php artisan migrate --env=test_server

Resources