Install Aimeos in separate database

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Install Aimeos in separate database

Post by rhand » 28 May 2024, 04:58

Trying to install Aimeos in different database from core Laravel app database but I only get migration table

Did add

Code: Select all

DB_CONNECTION=mysql_aimeos
DB_AIMEOS_HOST=localhost
DB_AIMEOS_DATABASE=aimeos
DB_AIMEOS_USERNAME=root
DB_AIMEOS_PASSWORD=
DB_AIMEOS_PORT=3306
and in database/config.php I added

Code: Select all

'mysql_aimeos' => [
            'driver' => 'mysql',
            'host' => env('DB_AIMEOS_HOST', '127.0.0.1'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'database' => env('DB_AIMEOS_DATABASE', 'forge'),
            'username' => env('DB_AIMEOS_USERNAME', 'forge'),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            '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'),
            ]) : [],
        ],
Sother tables are added besides migrations table and an invites table based on another package that I do not need in this database and I get this error post

Code: Select all

php artisan migrate  --database=mysql_aimeos
:

Code: Select all

   INFO  Preparing database.  

  Creating migration table ............................................................................................................... 37ms DONE

   INFO  Running migrations.  

  2017_04_04_185723_create_invites_table ................................................................................................ 127ms DONE
And yes I did run

Code: Select all

composer update -W 
php artisan vendor:publish --tag=config --tag=public

User avatar
aimeos
Administrator
Posts: 8020
Joined: 01 Jan 1970, 00:00

Re: Install Aimeos in separate database

Post by aimeos » 28 May 2024, 07:41

You have to adapt the database configuration in the ./config/shop.php file:
https://github.com/aimeos/aimeos-larave ... hp#L51-L66
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Install Aimeos in separate database

Post by rhand » 28 May 2024, 09:32

I added

Code: Select all

...
'resource' => [
		'db' => [
			'adapter' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.driver', 'mysql' ),
			'host' => config('DB_AIMEOS_HOST', '127.0.0.1'),
			'port' => config('DB_AIMEOS_PORT', '3306'),
			'socket' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.unix_socket', '' ),
			'database' => config('DB_AIMEOS_DATABASE', 'aimeos'),
			'username' => config('DB_AIMEOS_USERNAME', 'forge'),
			'password' => config('DB_AIMEOS_PASSWORD', ''),
			'stmt' => config( 'database.default', 'mysql' ) === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
			'limit' => 3, // maximum number of concurrent database connections
			'defaultTableOptions' => [
				'charset' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.charset' ),
				'collate' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.collation' ),
			],
			'driverOptions' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.options' ),
		],
...
to config/shop.php. Already had

Code: Select all

...
'mysql_aimeos' => [
            'driver' => 'mysql',
            'host' => env('DB_AIMEOS_HOST', '127.0.0.1'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'database' => env('DB_AIMEOS_DATABASE', 'forge'),
            'username' => env('DB_AIMEOS_USERNAME', 'forge'),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            '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'),
            ]) : [],
        ],
...
in config/database.php but I guess that did not work. However, still getting nothing extra on php artisan migrate --database=mysql_aimeos so I think I need something to load `DB_CONNECTION=mysql_aimeos` as well

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Install Aimeos in separate database

Post by rhand » 28 May 2024, 10:13

Then I ran

Code: Select all

php artisan aimeos:setup                   

   Aimeos\Base\DB\Exception 

  An exception occurred in the driver: SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'aimeos': SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'

  at vendor/aimeos/aimeos-base/src/DB/Statement/DBAL/Simple.php:75
     71▕        {
     72▕                try {
     73▕                        $result = $this->getConnection()->getRawObject()->getWrappedConnection()->query( $this->sql );
     74▕                } catch( \Doctrine\DBAL\Driver\Exception $e ) {
  ➜  75▕                        throw new \Aimeos\Base\DB\Exception( $e->getMessage() . ': ' . $this->sql, $e->getCode() );
     76▕                }
     77▕ 
     78▕                return new \Aimeos\Base\DB\Result\DBAL( $result );
     79▕        }

      +22 vendor frames 
  23  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      
So perhaps something else I still missed?

User avatar
aimeos
Administrator
Posts: 8020
Joined: 01 Jan 1970, 00:00

Re: Install Aimeos in separate database

Post by aimeos » 29 May 2024, 07:02

According to your error message, the user name isn't passed for login into the database.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Install Aimeos in separate database

Post by rhand » 30 May 2024, 03:05

The Aimeos shop.php configuration file with

Code: Select all

'username' => config('DB_AIMEOS_USERNAME', 'forge'),

did not pass on data. Or it did not show what user used in the mentioned error. I assumed it would load data from .env but it did not hence the `''` without username mentioned. When I used root as user in `config/shop.php`

Code: Select all

 'resource' => [
        'db' => [
            'adapter' => config('database.connections.'.config('database.default', 'mysql').'.driver', 'mysql'),
            'host' => config('DB_AIMEOS_HOST', 'localhost'),
            'port' => config('DB_AIMEOS_PORT', '3306'),
            'socket' => config('database.connections.'.config('database.default', 'mysql').'.unix_socket', ''),
            'database' => config('DB_AIMEOS_DATABASE', 'aimeos'),
            'username' => config('DB_AIMEOS_USERNAME', 'root'),
            'password' => config('DB_AIMEOS_PASSWORD', ''),
            'stmt' => config('database.default', 'mysql') === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
            'limit' => 3, // maximum number of concurrent database connections
            'defaultTableOptions' => [
                'charset' => config('database.connections.'.config('database.default', 'mysql').'.charset'),
                'collate' => config('database.connections.'.config('database.default', 'mysql').'.collation'),
            ],
            'driverOptions' => config('database.connections.'.config('database.default', 'mysql').'.options'),
        ],
all was well and migrations ran. Very odd . When I checked the value

Code: Select all

php artisan tinker                                   
Psy Shell v0.12.3 (PHP 8.2.15 — cli) by Justin Hileman
> echo getenv('DB_AIMEOS_USERNAME');
root⏎
it was fine and loaded. So what did

Code: Select all

'username' => config('DB_AIMEOS_USERNAME', 'forge'),
not first try and get aimeos username from .env:

Code: Select all

# DB_CONNECTION=mysql_aimeos
DB_AIMEOS_CONNECTION=mysql_aimeos
DB_AIMEOS_HOST=localhost
DB_AIMEOS_PORT=3306
DB_AIMEOS_DATABASE=aimeos
DB_AIMEOS_USERNAME=root
DB_AIMEOS_PASSWORD=

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Install Aimeos in separate database

Post by rhand » 30 May 2024, 03:43

My bad. I needed env:

Code: Select all

...
 'resource' => [
        'db' => [
            'adapter' => config('database.connections.' . config('database.default', 'mysql') . '.driver', 'mysql'),
            'host' => env('DB_AIMEOS_HOST', 'localhost'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'socket' => config('database.connections.' . config('database.default', 'mysql') . '.unix_socket', ''),
            'database' => env('DB_AIMEOS_DATABASE', 'aimeos'),
            'username' => env('DB_AIMEOS_USERNAME', 'forge'),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            'stmt' => config('database.default', 'mysql') === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
            'limit' => 3, // maximum number of concurrent database connections
            'defaultTableOptions' => [
                'charset' => config('database.connections.' . config('database.default', 'mysql') . '.charset'),
                'collate' => config('database.connections.' . config('database.default', 'mysql') . '.collation'),
            ],
            'driverOptions' => config('database.connections.' . config('database.default', 'mysql') . '.options'),
        ],
...
That did allow environmental values to load.. of course. Thanks for all your input.

Post Reply