I am working on a project where I need to connect Laravel to a postgres db. First time doing this, in the past just used mysql. I am getting this error PDOException::("SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host when I try to run php artisan migrate. I am on a mac so I used brew install postgresql. This is a db that already has tables in it.
In my .env file I changed my db to
DB_CONNECTION=pgsql
DB_HOST=<host name>
DB_PORT=5432
DB_DATABASE=<db name>
DB_USERNAME=<user name>
DB_PASSWORD=<password>
What else am I missing?
It seems like your config is missing in pg_hba.conf file.
Suppose you are on localhost, have you tried adding host all all 0.0.0.0/0 md5 entry in your pg_hba.conf? Remember to restart your postgresql services after that.
Related
I am admittedly new to Laravel and back end development but I'm trying to open a Laravel project in my browser and am receiving an error message instead. I'm inheriting this project from a client who was working with another group of developers and they have since gone AWOL so I'm on my own to try to figure out what the issue is here.
The first error messages were:
**Warning:** require(C:\xampp\htdocs\vizzue\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in **C:\xampp\htdocs\vizzue\bootstrap\autoload.php** on line **17**
**Fatal error:** require():Failed opening required 'C:\xampp\htdocs\vizzue\bootstrap/../vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in **C:\xampp\htdocs\vizzue\bootstrap\autoload.php** on line **17**
To try to fix that error (from a solution I found on here), I ran composer install in the terminal to try to download the missing files. That switched the previous error messages to Whoops, looks like something went wrong. (Not very helpful).
So then I found more advice on here to get more detailed errors for my problem and was outputted a long list of errors under four separate headings.
Heading 1
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `sessions` where `id` = hA02gV6ShpNslkw0N8Wrgm8QmyA0ZxoXfCNHsVTK limit 1)
Heading 2
PDOException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Heading 3
QueryException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `sessions` where `id` = hA02gV6ShpNslkw0N8Wrgm8QmyA0ZxoXfCNHsVTK limit 1)
Heading 4
PDOException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
My PHP version is: PHP 7.2.28
My Laravel version is: Laravel Framework 5.4.36
Also, I have created a .env by copying the .env-example file.
EDIT:
I found the database information inside of the database/migrations directory so I actually DO have the database files. I'm still having an error, however. I ran php artisan generate:key and that was fine. But when I ran php artisan migrate I got the following error:
In Connection.php line 647:
could not find driver (SQL: select * from information_schema.tables where ta
ble_schema = homestead and table_name = migrations)
In Connector.php line 68:
could not find driver
first you have change the name of .env.example to .env then configure your database names settings in it. after that run composer install to install your project dependencies. make sure your webserver is up and running
You should configure your .env file to enable laravel access on your database. If you don't have one just copy the .env.example file and rename it to .env.
And then change the following properties:
DB_DATABASE=YOUR_DATABASE_NAME
DB_USERNAME=USER_NAME
DB_PASSWORD=PASSWORD
and then you should run php artisan key:generate to generate a new encryption key
EDIT
For your new problem you should run composer update and then composer require doctrine/dbal
if that does not work
You might need to comment out the following in your php.ini file.
;extension=pdo_mysql.so
As said here
Here is the basic installation process for a laravel project. I'll try to explain each of them so that you'll be able to figure out your mistakes on your own.
Getting the source code
You first need to get the source code of your app . Most of the time it's done via git . For instance , you'll need to type git clone https://github.com/miracuthbert/saas-boilerplate.git yoursaasproject to clone the repository hosted on github here
Install dependencies
Go to the root of the directory of the source code you previously got by typing
cd projectname.
The laravel framework uses composer as its dependencies manager. So you need to install it . (What you already did)
Then, from the root of your project, type the following intructions in the same order :
composer install
composer update
Environment configuration
The environment variables of the laravel framework are managed through a dot env file. An example file named .env.example is generally provided. You'll find it at the root of your project's folder. Assuming you are using a terminal with a bash prompt, type the following command to copy the .env.example to a .env file :
cp .env.example .env
After getting your new .env file, type
php artisan key:generate
to generate secure key in your .env file
Depending on the type of database management system you intend to use, here are some specific configurations to add in your .env file :
MySQL
If you choose MySQL as your DBMS, set the following values in your .env file :
DB_CONNECTION
DB_DATABASE
DB_USERNAME
DB_PASSWORD
homestead is the default DB_USERNAME and localhost is the default database host. Localhost is totally fine for working locally but you need to change your DB_USERNAME to an actual user of your DBMS with the corresponding password.
Sqlite
If you use sqlite, create a new sqlite database by typing :
`touch database/database.sqlite`
After setting up your database, enter the following command to create and populate tables :
php artisan migrate --seed
You may also need to edit other variables in the .env. The official laravel documentation is your best companion for that.
This is to the best of my knowledge what you need to do.
As for the driver error, here are few potential solutions adapted from an answer to a similar problem question asked here :
Be sure to configure the 'default' key in app/config/database.php
For mysql, this would be 'default' => 'mysql',
If you are receiving a [PDOException] could not find driver error, check to see if you have the correct PHP extensions installed. You need pdo_mysql.so and mysql.so installed and enabled. Instructions on how to do this vary between operating systems.
For Windows, the mysql extensions should come pre-downloaded with the official PHP distribution. Just edit your php.ini and uncomment the lines extension=pdo_mysql.so and extension=mysql.so
Also, in php.ini, make sure extension_dir is set to the proper directory. It should be a folder called extensions or ext or similar inside your PHP install directory.
There are other instructions given in the original answer but I'm only recommending those I understand. It was initially written for a postgres dbms.
If there are still problems, take a look at laragon. It's a bit like xamp (that you appear to be using on windows OS), but more powerful and easier to use.
The main backend languages and frameworks can be set up easily in few minutes. That includes php with laravel/symfony, ruby and Ruby on Rails, python and Django.
It allows you to manage multiple versions of the same programming language without any hassle and is fully extendable.
If you're new to Laravel or backend development, and working on the windows operating system, this is a must have.
I have installed a fresh Laravel project (5.7.5) on my Mac (10.13.6).
I have installed mysql (8.0.12) with brew install mysql and the laravel project with the laravel create laraveltest command.
Laravel is running in the Valet environment (2.1.1).
I can connect to the Mysql server with the Sequel Pro client (127.0.0.0, root with no password) and also by the command line mysql -uroot.
I can create a database create database laraveltest and use the database use laraveltest but when I try migrating the database php artisan migrate i get an error:
'PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away')
So it seems that Laravel can't connect to my mysql server.
My .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laraveltest
DB_USERNAME=root
DB_PASSWORD=
I tried uninstalling/installing mysql. restarting the computer. deleting/creating the laravel project. same error.
Any ideas what I can try to resolve this?
input your root password of your php admin i think you do have a password to root php admin right ? DB_PASSWORD="yourpassword"
I just received some open project files form a customer, where I have to make some adjustments. The project is based ons Symfony Framework and in order to get the project running on my machine, I have to set up the symfony workflow.
I already installed all necessary dev dependencies I guess and when I start my app via:
php bin/console server:run
I get following errors: [PDOException] SQLSTATE[HY000] [2002] No such
file or directory
I read couple of threads about this error and most people recommend changing the host from "127.0.0.1" to "localhost" and vice versa.
If i enter "localhost" to be my host, I end up with the error from above.
If I put "127.0.0.1" as my host, I get "connection refused" instead of "No such file or directory"
Make sure your local mysql service is running as well.
Check database configuration in yaml. Make sure the connection to your local mysql is correct.
Run
app/console doctrine:schema:update --force
to create the database and all the tables for the project.
Let us know if anything of this works or does not.
I had the same problem and fixed it by adding
parameters:
#...
database_driver: pdo_mysql
in the app/parameters.yml file.
You should also check if your database_(name|user|password) values are correct.
I'm new to Lumen and when I try to use:
php artisan migrate
I get the following error.
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
If I change 'localhost' to '127.0.0.1' I get this error:
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
If I use:
php artisan migrate --database=Lumen
I get:
[InvalidArgumentException]
Database [Lumen] not configured.
Here is my .env file
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=Lumen
DB_USERNAME=root
DB_PASSWORD=root
I've read other questions on stack overflow and have tried the solutions i.e. configuring php versions and checking the path to mysql.sock and it's all fine. I am using the full path and my PHP version is correct.
I am using MAMP and have a Database called 'Lumen' (there are no tables at the moment).
Created a migration using terminal:
php artisan make:migration --create=items create_items_table
I am using php artisan serve (server 8000) to view my project, which I can view.
MAMP is on:
apache=80
nginx=80
mysql=3306
I used the same configuration for my Laravel project and that is working fine. But laravel does have a database.php file which has all the details inside of it.
I hope that's enough information, any help would be much appreciated!
Thanks in advance
EDIT: This is my app.php file, the rest is left untouched.
require_once __DIR__.'/../vendor/autoload.php';
Dotenv::load(__DIR__.'/../');
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
$app->withFacades();
$app->withEloquent();
Is it possible you forgot to enable the dotenv variables? In your bootstrap/app.php file you can enable the environment variables by uncommenting the following line:
Dotenv::load(__DIR__.'/../');
Lumen Documentation about databases
After a lot of fiddling about, I found the answer.
The problem was with MAMP, the pdo socket for mysql was not in the php.ini file and had to be included there.
[Pdo_mysql]
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/pdo_mysql.cache_size
pdo_mysql.cache_size = 2000
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=
Including that line fixed all my probelems.
To the new guys out there trying out Lumen, after 3 sad hours, I finally solved this issue. It's not you, it's the MAMP!
All this time, MAMP was not using the default ports 80 and 3306 for web and mysql. So click that button. That's all! And I'm posting this on my blog soon :D
If you're using MAMP on macOS you can just add this code in your .env file:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
And you don't need to modify any MAMP's config.
I am having some errors with laravels php artisan migrate command, when I try to migrate, it keeps throwing errors saying, unknown database 'database name'
I have checked my database configure file and even copied to a different project and it works perfectly there, I have tried composer dump-autoload command but that didn't solve the problem either. Please I will really appreciate if someone helps, since this is a new project and can't afford to lose even a minute to my deadline, thanks in advance!
The command I run from the terminal while I have CD'ed into the project folder is.
php artisan migrate
This is the error I get.
[PDOException]
SQLSTATE[42000] [1049] Unknown database '[gicfamily4]'
[PDOException]
SQLSTATE[42000] [1049] Unknown database '[gicfamily4]'
This is a MySQL error and is indicative of either a misconfiguration in your environment's database.php config file (misspelling in the database name) or the database gicfamily4 simply doesn't exist on the database server you are connecting to.
Verify your connection information again. If possible, try to attempt to connect to the mysql server from the command line using the exact same information contained in your database.php file (via copy and paste):
$ mysql -u <username from database.php file> -p -h <database host from database.phpfile>
Enter Password: <paste password from database.php file>
mysql> use gicfamily4;
I suspect you will get the exact same error as above.