I have read a lot of posts regarding artisan migration issues, but unfortunately none of them are applicable to my situation.
So I am running Laravel Homestead via Vagrant and I have created a new database in the Vagrant VM.
On my Ubuntu desktop I can connect to the database via DBeaver and it shows the database. Because I am running the database in a Vagrant VM, I am connected to it through 192.168.10.10 (specified in the Homestead.yaml file) and not localhost (127.0.0.1). So far so good.
I created a migration file by running the following command: php artisan make:migration create_todo_table. However, when I run php artisan migrate I get the following exception error:
Illuminate\Database\QueryException
Could not find driver (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')
The data regarding the database in my .env file is as follows:
DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
I have tried clearing the cache by running php artisan config:cache but had no luck.
Can someone give me some insight, please?
DB host inside your vagrant should be localhost or 127.0.0.1 because project and database both are inside vagrant but DBeaver is outside vm so 192.168.10.10 is okay for DBeaver.
DB_HOST=localhost
I got in fixed by editing my php.ini file.
For Windows I changed ;extension=php_pdo_mysql to extension=php_pdo_mysql.dll.
For Ubuntu I changed it into extension=pdo_mysql.so.
After that, I still got an error stating that the connection was actively refused. I fixed this by changing DB_HOST=localhost to DB_HOST=192.168.10.10.
Hope this will help someone someday!
Related
I've attempted to access my PostgreSQL database from both a Laravel project, DBeaver and Artisan. Accessing it from Laravel project or Artisan ($ php artisan migrate) always results in:
Illuminate\Database\QueryException
SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
Because I'm not relying in my Laradock settings and I'm not familiar with Laravel in general, I did re-download Laradock with default settings, but situation continues same.
Partial laravelProject/.env:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret
Partial laradock/.env:
POSTGRES_VERSION=alpine
POSTGRES_DB=default
POSTGRES_USER=default
POSTGRES_PASSWORD=secret
POSTGRES_PORT=5432
Environment used to run Artisan:
$ docker-compose exec --user=laradock workspace bash
I installed Laravel in this environment using composer global require laravel/installer.
DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=yourprojectdatabase
DB_USERNAME=default
DB_PASSWORD=secret
To connect using DBeaver:
Host: localhost
Port: 5432
Database: you can leave it empty
Username: default
Password: secret
Click on the PostgreSQL tab right there in Connection.
Make sure "Show all databases" is checked.
Recently I bought a Macbook and I want to run a laravel app using XAMPP. I downloaded the last available XAMPP for Mac OS, installed composer and successfully ran the project. Composer is working as expected, the local host is also working fine (when I try to access PhpMyAdmin it works). After that, I wanted to migrate using php artisan migrate after I created the database into PhpMyAdmin under the name web3project. I cloned my git repository containing the laravel application and edited the .env file:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:B8MsHk7bk84kwOl5HQebNY7c2UGLlDtpb/YbGl8HkYE=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=web3project
DB_USERNAME=root
DB_PASSWORD=
I tried editing
DB_HOST=127.0.0.1
to
DB_HOST=localhost
The error I receive is:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = web3project and table_name = migrations and table_type = 'BASE TABLE')
As I mentioned I am new to Mac OS and I may be doing something wrong with the XAMPP but the localhost is indeed working.
I moved the Laravel project from localhost to server. Which I have done every step on the server.
I am able to view the login page on my server. The problem is I am not able to connect with my MySQL server.
My .env file:
APP_NAME=Transport
APP_ENV=local
APP_KEY=base64:mrakeyidharhaikonsdf
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=transport_db
DB_USERNAME=root
DB_PASSWORD=mypass
I tried to change the host to 127.0.0.1 and also tried to put my server's IP address. It didn't helped me. Am I missing something?
My error:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select count(*) as aggregate from users where email = user.email#gmail.com)
I know this question may have answers already on Stack Overflow. But I have different issue here.
To be honest, while working on Laravel 6, I also faced this issue many times and probably was unable to figure out the solution. I tried commands like
php artisan config:cache and php artisan config:clear, but these two commands didn't help.
To come over this issue, you have to execute all the below commands:
php artisan route:cache
php artisan route:clear
php artisan config:cache
php artisan config:clear
php artisan optimize
Note: Make sure in .env you have add db_password and it is not null and also check if your db_password uses any special character. Always enclose them in "".
Example:
DB_PASSWORD="%123456%"
To debug this issue you can also create a test route and then dump the .env variable there to check if they have the correct values or not.
Route::get('/test/env', function () {
dd(env('DB_DATABASE')); // Dump 'db' variable value one by one
});
Note: Please make sure to restart your server.
Make sure your database credentials and database host are set correctly:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"
If you have not set any database password then add:
DB_PASSWORD=""
The problem is that the project made a cache file. 'config.php' must be deleted in order to allow the system to restart and you can do so by locate this file and deleting it:
bootstrap/cache/config.php
I was working in the Laravel framework using homestead and had such a problem. In fact, this error was because I did not create the database in Vagrant. So, I created the database. In more details:
run vagrant ssh to get homestead command line.
run mysql to start the MySQL command line client.
run create database database_name; to create your database. Note that the database should be inside two ` (not ') marks.
Modify the .env file of the Laravel project as below:
DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=askidb2
DB_USERNAME=homestead
DB_PASSWORD=secret
(if you previously made your model and configured files in Laravel projects for creation tables), run php artisan migrate in the command line of the project's folder. This causes it to create tables in the askidb2 database.
(perhaps optional for you) since before I set needed files for seeding the question table I just run php artisan db:seed to seed my desired table(s).
If you use Homestead to serve your application, you must connect to the Homestead built-in database. Otherwise, I get an error (SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost') when I try to connect to the MySQL database that is installed on my Mac.
Here is how I connect to the Homestead database. I am not sure why the host → 127.0.0.1 from the Laravel documentation doesn't work.
In the .env file
DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=homestead
DB_PASSWORD=secret
I use Sequel Pro as the GUI to manage the database, and here is how I connect Sequel Pro to the Homestead MySQL database.
Connect with standard mode
Host: 192.168.10.10
User: homestead
Password: secret
Port: 3306
Connect with SSH mode
So the problem is mine. I apologize for that.
I missed to put my DB_PASSWROD inside "". So that caused my two hours.
I have the password which contains some special characters at the beginning. So it should be inside the "" to avoid the problems.
For example, if my password is "%helloworld#",
then in the .env file, it should be:
`DB_PASSWORD="%helloworld#" `
Previously, I had
`DB_PASSWORD=%helloworld#
I had this error while my connection with the database was established. The problem was that I was on localhost, not 127.0.0.1.
First
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"
Then type
php artisan config:clear
This will make your problem clear. Then type
php artisan migrate
I had this error because my XAMPP user Account access for root and password did not match Laravel .env database DB_USERNAME & DB_PASSWORD.
This will Work:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"
This may also be due to the DB_PORT. Go to the PhpMyAdmin Database server and check the server.
So I changed from this
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
to
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
Change the .env as follows
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="Your DB name"
DB_USERNAME=root
DB_PASSWORD=
and then run php artisan config:cache
and then run php artisan migrate:fresh --seed
and then run php artisan serve
Please make sure to have the same db name in .env file and db name in php myadmin
Kindly check your mysql port no as well.
If you have changed your xampp mysql port, then do check PORT Number in your projectfolder ".env" file as well as "database.php" file.
In my case, if I have Bitnami WordPress. It's a service using an Apache/localhost address, so my XAMPP instance is only accessible via 127.0.0.1 and when accessing localhost I got 'Access denied error ...'. Then when I stop the Bitnami service, everything is back to normal.
After installing Laravel 5.5 for a new project, I get this error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
.env db connection info:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=lavavelproject
DB_USERNAME=root
DB_PASSWORD=
Dev environment: Windows
PHP 7.0
Try to clear cache by terminal:
php artisan config:cache
Do it always when you change config file.
Sometimes the most common issue is using localhost, change this to 127.0.0.1 and it should work for you.
Sometimes you will have to run:
php artisan cache:clear and in the rare moments as I have found also running php artisan key:generate
Faced the same issue, changing DB_HOST=mysql to DB_HOST=localhost solved my problem.
I had same problem. The solution was to change DB_HOST=mariadb to DB_HOST=localhost.
If it matters, my localhost is 127.0.0.1.
Anyway, for my project and my PC config, the problem comes from Apache (XAMP), I think.
My project run in Docker containers.
I put in my ".env" file above two lines,
DB_HOST=mariadb
#DB_HOST=localhost.
The last line (localhost) is commented and not change when I run the project.
For running php artisan commands, I'll deactivate "mariadb" and activate "localhost".
Simple trick to not change much.
On your application .env should be pointing to the IP of your database. Your database is the same server as your Laravel application, it should be:
.env
DB_HOST=127.0.0.1
so I want to deploy my existing Laravel project into my digital ocean VPS
I used this tutorial and I uploaded my site successfully.
My .env file is:
APP_ENV=local
APP_KEY=my app key
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=my ip
DB_PORT=3306
DB_DATABASE=form
DB_USERNAME=root
DB_PASSWORD=my pass
But here is the problem: I used MySQL and created and ran
php artisan migrate
and got these errors:
[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = form and table_name = migrations)
and
[PDOException] SQLSTATE[HY000] [2002] Connection refused
In your .env file, change DB_HOST from 127.0.0.1 to localhost
Put string:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
after DB_PASSWORD=
It works for MAMP. Set your path to mysql.sock
In your .env file, change DB_HOST from 127.0.0.1 to localhost
and then
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
This worked for me.
There are a few possibilities why your getting this error.
database server isn't started, check if you can still use your phpmyadmin. If you can still use it then nothing is wrong with your database server.
wrong config; check username, password and server settings in both your .env file and your config/database.php
no privileges to the server and or database with given credentials
Looking at the steps you already took I think it's the last.
Check to see if this user has access to the database from the remote location. By default the root user has access to the server locally (localhost,127.0.0.1 and ::1).
So check to see if the user has access from either your remote ip or from anywhere.
As you are using digitalocean I would suggest to check if they have a specific configuration to connect to mysql database.
SELinux might be the cause.
Set this rule and try again:
sudo setsebool -P httpd_can_network_connect_db=1
After long hours this worked for me:
Changing the port in php My Admin previously 8889
APP_NAME=laravel
APP_ENV=local
APP_KEY= YOUR KEY
APP_DEBUG=true
APP_URL=127.0.0.1
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
and then
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
Before you do changes as per instructed above,
check if your database server running or not. If you are using command prompt, running mysql.server status or mysqld status shall show the database status.
If the database is running, check if the dbuser is allow to connect from '%' or 'localhost' or '127.0.0.1'. If not, just grant the user access from '%'
If you have done 1 and 2 and still can't connect, see if the db user is allow to access the schema. If not, grant access to the schema
If you reach here and still got the same error, try to restart you web server.
My composer was installed globally, i run php artisan serve without starting xampp & getting this error. After running my xampp server, it's working fine from my side.
In attempt to provide a solution for those of you that have not found success in any of the already mentioned answers, I will share my solution.
Coming from Windows 10 I was of the understanding that the password for the root user was always blank thus my .env file looked as follows:
DB_USERNAME=root
DB_PASSWORD=
On Mac, the password is defaulted to "root" also. Changing my .env file to look as follows fixed my issue:
DB_USERNAME=root
DB_PASSWORD=root
in your .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ur_db_name
DB_USERNAME=ur_db_username
DB_PASSWORD=ur_dbuser_password
If you are using XAMPP on Mac, just use the embedded IP Address from your XAMPP Dashboard as DB_HOST instead of 127.0.0.1 or localhost.
If It still refuses to connect deal with a user but stick on that idea.