when i write this command:
php artisan migrate
Laravel Provides Database migrations which don't work very well for me when i write this command:
php artisan migrate
it always give me this error
Change the .env file from 127.0.0.1 to localhost fixed it.
DB_HOST=localhost
do config:cache after .env file change. php artisan config:cache
Ensure you have an .env file, and that the database related variables within have been set correctly.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
Related
I got this error when I logged in.
I tried:
+ php artisan cache:clear
+ php artisan view:clear
+ php artisan key:generate
+ php artisan config:cache.
I also restarted the server!
My code:
DB_CONNECTION=mysql
DB_HOST=http://45.77.34.158/phpmyadmin
DB_PORT=3306
DB_DATABASE=dataname
DB_USERNAME=user
DB_PASSWORD=12345679
My server is an online server!
Can anybody tell me where I am wrong?
I use php7.3.9, laravel 5.7, composer 1.9.1.
Thanks!
https://diy.stackexchange.com
DB_HOST should be IP Address only
Change
DB_HOST=http://45.77.34.158/phpmyadmin
to
DB_HOST=45.77.34.158
if that doesn't work then run this command this will help you to clear cached config
php artisan cache:clear
the host should not be an URL, instead use only the IP ADDRESS.
DB_HOST=45.77.34.158
DB_CONNECTION=mysql
DB_HOST=45.77.34.158
DB_PORT=3306
DB_DATABASE=dataname
DB_USERNAME=user
DB_PASSWORD=12345679
In .env file change DB_HOST=??????? to DB_HOST=localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=root
DB_PASSWORD=
this is my configuration for laravel 5.4
but php artisan migrate is not working and have error
and the migrate error
Users-MacBook-Pro: ATP Developers php artisan migrate
In Connection.php line 664:
SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: NO) (SQL: select * from information_schema.tables where table schema = atp_db and table_name = migrations)
In Connector.php line 87:
SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: NO)
I faced a similar problem. So, I run the following commands as mentioned at
https://laracasts.com/discuss/channels/general-discussion/env-file-and-config-keys-not-updating-after-change,
php artisan cache:clear
php artisan config:clear
php artisan route:clear
Also, make sure to restart the server as well
php artisan serve
you should write these:
DB_DATABASE = your database name
DB_USERNAME = root
DB_PASSWORD = your password
and again run php artisan serve to make sure about saving .env and again run php artisan migrate
Indeed I had the same problem, I can not explain why Laravel indicates the old Host but the solution is to change the password.
Use below => php artisan config:cache
Change env host entry to DB_HOST=localhost. Or add the #'127.0.0.1' credentials to mysql.
The error indicates that you do not have the correct user and host combination in your database. The env file shows host is 127.0.0.1 but localhost is specified in the error. Add user#localhost entry to the database or user#% for wildcard.
This error would indicate that you don't have a database user configured in your .env file: ''#'localhost' . Your .env should have all those fields populated with the database name and credentials you configured before running any function that connects to the database.
Here are the preliminary steps to setup your database and .env file prior to running a php artisan migrate:
Hope it helps.
Step 1: Login to your mysql and create the database.
mysql -u root -p
create database just_brew_it;
Step 2: Although you can use root to authenticate via laravel, I'd create a new user to mitigate risk of any security issues:
GRANT ALL PRIVILEGES ON just_brew_it.* TO 'brew_user'#'%' identified by 'pint0fStell#' WITH GRANT OPTION;
FLUSH privileges;
Step 3: Modify your .env with the appropriate database, username and password
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= just_brew_it
DB_USERNAME= brew_user
DB_PASSWORD= pint0fStell#
This combo worked for me:
php artisan clear-compiled
composer dump-autoload
php artisan optimize
I had the same issue and i couldnt run "config:cache" artisan command even with Artisan::call('config:cache');
so i done this and solved my issue:
artisan config:cache caches all files from /config into a single array that it stores. It then reads all config variables from that array and ignores anything in .env or the /config files until you recache them. That's why it still works after deleting .env.
https://laravel.com/docs/5.6/configuration#configuration-caching
If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php file, which is the cache file config:cache generates.
How to run laravel project from github on localhost when .env file is missing in the laravel project?
You can rename the .env.example to .env and then run php artisan
key:generate and it'll function as it should.
If you're using a command line simply type cp .env.example .env and
run the key:generate command.
If you are missing the .env files completely, you may take the .env.example file from: https://github.com/laravel/laravel/blob/master/.env.example
Then simply create a new file named .env within your project. You will still need to run php artisan key:generate once you have created the file.
Copy .env.example
Change the name with .env
Make your own settings in .env file.
After that run "php artisan key:generate"
I changed MAIL_DRIVER in .env file of production server like that:
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAILGUN_DOMAIN=mg.xx.com
MAILGUN_SECRET=key-xx
MAIL_ENCRYPTION=null
I run these commands also:
php artisan config:clear
php artisan config:cache
However, they did not change MAIL_DRIVER. Server continues to send mail via old MAIL_DRIVER. I got from controller env("MAIL_DRIVER"), and it gets nothing (NULL).
How can I solve this problem.
You will need to restart your server and/or just re run php artisan serve on local dev.
I seem to be having a problem with artisan reading the default config/database.php file.
When I run for php artisan migrate:status - or any other migration related commands I get
exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access
denied for user 'homestead'#'localhost' (using password: YES)'
even though the default database connection name is set to sqlite, which doesn't require credentials of any kind.
My .env has APP_ENV=local and I'm running it under the local environment with PHP 5.6.2 using Mamp.
After calling php artisan I've noticed there is a command to clear the configuration cache file php artisan config:clear - then run php artisan config:cache to cache it with the applied changes - which solved the problem.