Laravel database still use old name after .env changed - php

Edit:
php artisan config:cache work nice, but now I got other problem.
the URL giving me Error 500
I upload a project to a new subdomain area after I changed .env file
when I open URL I still got an error with the old database and user
I tried to check online with the .env file but - I don't know where he stored this database, I tried to see where is this name with ctrl+f but - nothing found
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=faceterc_hot
DB_USERNAME=faceterc_hot
DB_PASSWORD=testpro
I expect to get the same error maybe but not with the old database name.
and this gives me a indicate that maybe the file or something not changed or he using the other details from I don't know where

Good, practice for, If you change in a .env file first restart the server using below command.
php artisan serve
then after run below more command for clear old cache and config.
composer dump-autoload
php artisan config:cache
php artisan config:clear

You can simply do a
php artisan config:cache
In case you are on a shared hosting, you can change the values in config/database.php to only use the set values in your .env. Setting it like this will make sure, it only use the .env values.
mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],

php artisan config:clear Solve the problem with DATABASE error
just ran :
php artisan config:clear
with ssh at the main folder.

Just execute
php artisan config:cache
as the laravel cache's the environment files rather than accessing the data from it on every request.

It's always a good practice to run these couple of commands when you change any environment related variable:
php artisan config:clear
php artisan cache:clear

Execute these commands:
php artisan config:cache
php artisan route:cache
php artisan optimize
That will clear your env cache and it should do.

Related

Database (database/db_intranet.sqlite) does not exist

I managed to migrate and seed a sqlite database (located in database dir) by replacing the database block in .env with the following
DB_CONNECTION=sqlite
DB_DATABASE=database/db_intranet.sqlite
However when I want to make any operations to the database from the models I'm given this error
Illuminate\Database\QueryException
Database (database/db_intranet.sqlite) does not exist.
Which is solved by changing the block to this
DB_CONNECTION=sqlite
DB_DATABASE=../database/db_intranet.sqlite
My question is, why? And what can I do so I don't have to constantly alter the .env file to work with the database?
In database.php change :
'database' => env('DB_DATABASE', database_path('db_intranet.sqlite')),
to:
'database' => database_path('db_intranet.sqlite'),
Instead of a relative path you need to use an absolute path in your .env file, as :
DB_DATABASE=/var/www/project/database/db_intranet.sqlite
On windows, like :
DB_DATABASE=C:\www\project\database\db_intranet.sqlite
After change, run php artisan config:clear and php artisan cache:clear then serve it.
you have to use relative path in the .env file as
DB_DATABASE=/var/www/project/database/db_intranet.sqlite if you are using Ubuntu operating system.
if you are using windows system then you can use
DB_DATABASE=C:\www\project\database\db_intranet.sqlite
and in config/database.php you can use
'database' => env('DB_DATABASE', database_path('db_intranet.sqlite')),

SQLSTATE[28000] [1045] Access denied for user 'root'

I have my project ready and I have just uploaded to a shared hosting server. Everything works perfectly fine on my local machine but the page is displaying the error:
"SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: NO)"
I have checked my password and username and they are both correct. The server requirements are also as I already have 2 other Laravel sites running with the same host.
I have done php artisan config:cache php artisan cache:clear But no headway.
What could be causing this and how do I get it solved? I earnestly need a solutions as this has kept me sleepless for nights now.
try to with these 3 artisan command.
1) php artisan config:clear
2) php artisan cache:clear
3) php artisan config:cache
different config? it's saying your password is empty ;)
"I have checked my password and username"
"(using password: NO)"
app/config/database.php:
'mysql' => array(
'read' => array(
'host' => '192.168.1.1',
),
'write' => array(
'host' => '196.168.1.2'
),
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '<insert password here?>',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Open terminal and type
sudo mysql -u root -p
It will prompt you in mysql, here you can fire any mysql commands.
Use mysql table for change table type, so we can use empty password. Bellow is command for it
USE mysql;
Now we change type of table by following command
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
now we have to flush the privileges, because we have used UPDATE. If you use INSERT, UPDATE or DELETE on grant tables directly you need use FLUSH PRIVILEGES in order to reload the grant tables.
FLUSH PRIVILEGES;
now exit from mysql by following command
exit;
now restart mysql server by following command
service mysql restart
Hope this may help
Thank you.
Anytime you deploy a project, you should typically run the php artisan config:cache command as part of your production deployment routine. I suggest you
Remove the configuration cache file
Flush the application cache
Create a cache file for faster configuration loading
To do this, run the following Artisan commands on your command line
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Where you don't have access to the command line on your server, you can programmatically execute commands by adding the following to your routes:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('config:clear');
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
And then call the clear-cache route from your browser.

Laravel 5.6 Application In Production

When am trying to migrate anything , then every-time it's asking me about
Do you want to run ".env" instead? (yes/no) [no]:
I added .env file in my project. also i tried to solve this problem with this below changes :
config/app.php
'.env' => env('APP_ENV', 'development'),
'debug' => env('APP_DEBUG', true),
.env file below :
APP_ENV=local
APP_DEGUG = true
i also tried to fix this problem with
php artisan config:clear
after this
php artisan key:generate
Nothing changes when i checked this current mode by :
php artisan env
It's showing me
Current application environment: production
how to solve this ?
I had this problem too, and these steps helped me:
clear config
php artisan config:clear
after this php artisan key:generate
now cmd say me its local
php artisan env
There's a typo:
Not:
'.env' => env('APP_ENV', 'development'),
But:
'env' => env('APP_ENV', 'development'),
without dot before env

Laravel 5.5 Queue: No connector for []

I have two websites running identical laravel 5.5 project. In fact both websites hosted on the same server. One of them works, another one has troubles with queues. I have double-checked everything.
.env:
...
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=database
QUEUE_DRIVER=database
...
conf/queue.php
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
I do have empty jobs table as well.
Whenever I do try to run queues I'm getting an error
php artisan queue:work --daemon
In QueueManager.php line 172:
No connector for []
Please check the config queue drive setting. If use Redis, you can use php artisan tinker check
current the config.
Check command queue:
php artisan queue:work redis --queue=QUEUE_NAME --tries=3 --memory=128 --timeout=300
Check job listen by command line:
ps aux | grep php
I just had to specify a "connection" (database for my case) after queue:work command like below:
php artisan queue:work database --queue=Q_NAME
and the error disappeared!
Hi I encountered the same problem and couldn't find the solution but I followed laravel deploy optimizations, like cache config, view and routes which result into this. (I am not sure why).
I followed these and it worked like magic. (I don't know why it worked)
php artisan config:clear
php artisan route:clear
php artisan view:clear

"SQLSTATE[HY000] [2002] No such file or directory" error when migrating table in Laravel

I am getting the following error when I try to migrate a table in Laravel 5 using the "php artisan migrate" command:
'SQLSTATE[HY000] [2002] No such file or directory' in . . .
/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
My .env file includes the default settings as follows:
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
My database.php file lists mysql as the default database connection, homestead is listed as the database in my homestead.yaml file, and homestead is one of the tables listed when I access mysql and use the show databases; command.
Any thoughts about what I might be doing wrong?
try 127.0.0.1 instead of localhost in your .env file. It works for me :)
Add mysql.sock path in database.php file like below example
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Eample
'mysql' => [
'driver' => 'mysql',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '8889'),
PDOException SQLSTATE[HY000] [2002] No such file or directory
Change localhost as your DATABASE_HOST in the .env file, change it to 127.0.0.1, and after that run php artisan config:clear and then run php artisan migrate:install again.
Or if your problem is not solved, use these changes in your .env files:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
Then in Database.php add folder location:
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
Finally, try:
php artisan config:clear
php artisan migrate:install
This seems to be an issue with the socket file. Please let me know if this helps Starting with Zend Tutorial - Zend_DB_Adapter throws Exception: "SQLSTATE[HY000] [2002] No such file or directory"
Okay, this is might be a special case to me however I had this issue.
I moved my files from a Laragon based server to a mamp based server on a different machine. I had this error for days and I only received this error when running php artisan migrate and not when loading the page. When loading the page i received table not found which is understandable as the table isn't there.
After quite some time I just though of running composer update and then it fixed the error and worked for me. Not sure if this helps anyone but I came back to this post in case it somehow does.

Categories