Setup Travis-CI with Laravel 5 and PostgreSQL - php

After migrating from MySQL to PostgreSQL, I've been having problems integrating Laravel 5.1 with Travis-CI. I've tried the following configuration:
.env.travis
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_DATABASE=CDJ_BD
DB_USERNAME=postgres
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
.travis.yml
language: php
php:
- 7.0
addons:
postgresql: "9.4"
before_install:
- composer self-update
- cp .env.travis .env
- psql -c 'create database CDJ_BD;' -U postgres
install:
- composer require phpunit/phpunit:4.8.* satooshi/php-coveralls:dev-master
- composer install --dev
script:
- php artisan migrate --seed
- ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml
after_script:
- php vendor/bin/coveralls -v
database.php
...
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'testing' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'CDJ_BD'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'CDJ_BD'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
...
After running php artisan migrate --seed, the following exception is thrown:
[PDOException]
SQLSTATE[08006] [7] FATAL: database "CDJ_BD" does not exist
My MySQL configuration was pretty similar and ran without any problems. Any suggestions on how to resolve this issue?
Thanks.

As suggested in the comments by wildplasser, the problem was the CAPS database name in env('DB_DATABASE', 'CDJ_BD'), in database.php and in the .travis files. Switching them all to lowercase 'cdj_bd' solved the problem.

Related

Failed to connect database using docker in laravel

i have a problem when connect database using laravel and docker ,i got error like this :
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = sisuket and table_name = migrations and table_type = 'BASE TABLE')
and this is my docker-compose in section mariadb
mariadb:
image: docker.io/bitnami/mariadb:10.7
ports:
- 3306:3306
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MARIADB_DATABASE=sisuket
- MARIADB_ROOT_USER=sisuket
- MARIADB_ROOT_PASSWORD=sisuket
restart: always
networks:
- app-tier
and this is my .env and database.php , i have try to change DB_HOST to be localhost and 127.0.0.1 . but,that's useless
APP_NAME=app
APP_ENV=local
APP_KEY=base64:aQ+ckCjANh0NPWNp1zOWJYHS6k3eiaoBmMVdhX93oqQ=
APP_DEBUG=true
APP_URL=http://localhost:80
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST= mariadb
DB_PORT=3306
DB_DATABASE=sisuket
DB_USERNAME=sisuket
DB_PASSWORD=sisuket
[//database.php
'mysql' => \[
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'mariadb'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'sisuket'),
'username' => env('DB_USERNAME', 'sisuket'),
'password' => env('DB_PASSWORD', 'sisuket'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter(\[
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
\]) : \[\],
\],][1]
Thre thing what you can try:
php artisan config:cache. If that not work =>
Remove the whitespace in the line DB_HOST= mariadb => DB_HOST=mariadb and php artisan config:cache. If that not work =>
If that not work change DB_HOST to DB Host DB_HOST=127.0.0.1 and php artisan config:cache.

php laravel artisan migrate error in model?

i am new to php laravel i try to migrate project with database but i got following error ?
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = lcrud and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
+34 vendor frames
35 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
and here is the .env file
APP_NAME=lcrud
APP_ENV=local
APP_KEY=base64:PchgVozhfLeJtzlwFMtY0VGEpsfj2PYCtS7eVcothEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lcrud
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
i have double check that my password is nothing so i have tried to place empty string like this DB_PASSWORD='' and also like this DB_PASSWORD=' ' but it does not work also in other stackoverflow question i read about php.ini file and made changes according this page.
my php version is PHP 7.2.24-0ubuntu0.19.04.2 (cli) (built: Jan 14 2020 13:26:02) ( NTS )
and when i type which php in terminal i got /usr/bin/php
i was trying other question answer but not working .
Please help me , Thank You .
UPDATE
here i have my database.php file that might help you ,
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
],
You get this error because there is no mysql server driver. you can try it by install it with use of below commands.
sudo apt-get install mysql-server php7.1-mysql
sudo service apache2 restart
sudo service mysql restart
Hope this will help you.
"lcrud" database exist ?
or
php artisan config:clear
php artisan cache:clear
I think can you missing php7.x-mysql
You can run:
php -v
For example Output: PHP 7.1
sudo apt-get install php7.1-mysql
Update:
PHP 7 is not available for Ubuntu Trusty in the standard Ubuntu repositories (2016-01-02).
You could use the PPA ppa:ondrej/php.
sudo apt-add-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1-fpm
sudo apt-get install php7.1-mysql
sudo service apache2 restart

How can I solve this problem in composer?

I am beginner of using laravel 6, so this the error message that I faced,
1) SQLSTATE[42S02]: Base table or view not found: 1146 Table
'forge.settings' doesn't exist (SQL: select * from settings where
auto_load_disabled is null)
2)SQLSTATE[42S02]: Base table or view not found: 1146 Table
'forge.settings' doesn't exist
even I have tried the command php artisan migrate:fresh but it exists the same error, the command include
php artisan serve, php artisan migrate, are also not work for me..
Below are the code,
In my .env file:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=root
DB_PASSWORD=
The command php artisan migrate:key is not work, the error message is same to the above 1) and 2)...
and I have also try to copy another app key that can run on the server but still not work.
The database I have already create on phpmyadmin named 'forge' using xampp server.
my database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'modes' => [
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION'
],
'engine' => 'InnoDB',
]
Can anyone help me? Please..

php artisan migrate:install won't work

I just started downloading laravel 5 today. Where I install my laravel in my desktop. When I try to create a database using laravel comman php artisan migrate:install and it give's me a error SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database 'forge' I tried a lot of examples on google but didn't work for me.
I follow on of the steps on the internet where I configure my .env file followed the array contain in database.php database to 'forge', username to 'forge' and password to ''
database.php
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
.env
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:oqZ6S+IZANLCbszbhef9VSPqd/4rw22oT0mixzsflZo=
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
How can I create database just typing php artisan migrate:install and automatically create laravel_migration database in my localhost? Just saw this on the internet. But when I did this it didn't create for me.
As mentioned in the comments, the tutorial assumes you are using their development virtual machine. Since you're not, you need to start up MySQL and do the following:
CREATE DATABASE IF NOT EXISTS forge;
CREATE USER forge#localhost IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON forge.* TO forge#localhost;
Once the database and user are created, you should be good to go. This should be part of their documentation...

Laravel 5: Error: "Driver not found" while migrating the database(mysql) in laravel

It's been around 5-6 hours since I've been trying to use database in laravel 5.
I've gone through of videos and it confused me a lot.
I have created the model and migration but when i try to migrate it gives me an
[ PDOException ] Driver not found
I've made numerous changes to .env and database.php but nothing works.
I am using laravel 5 with xampp server.
Kindly help
Thank you
.env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=zZfvju3BKjxmLKbl5gsVJ3ymkIvHbGNq
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=medicaldb
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
database.php file
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'medicaldb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
Finally, at last! it worked!!
In php.ini file:
(semi-colon) ; works as a single-line comment in php.ini file.
(semi-colon) was added at the beginning of the line - which disables pdo mysql driver.
I just needed to remove the semi-colon(;) to enable mysql, from the beginning of the line.
Same problem, ubuntu 17.10, Laravel 5.6
It is the issue normally come when you upgrade you php version I get the same issues in my lammp stack while i update from php 7 to 7.1 I get Solve by following command
Open Terminal
sudo apt install php7.1-pdo php7.1-mysql
Have fun with Code
Are you sure you have mysql intalled? also, please check pdo_mysql module is enabled. use phpinfo();

Categories