How to change database of yii2 advanced template - yii2

How can i change the database information of my yii2 advanced template?
i cant find the database settings.
http://www.yiiframework.com/doc-2.0/guide-index.html

In /common/config/main-local.php you set your database settings:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=DATABASE_NAME',
'username' => 'DATABASE_USER',
'password' => 'DATABASE_PASSWORD',
'charset' => 'utf8',
],
The installation guide for advanced template is here: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md

The advanced template has environments that each define the target specific configuration. Basically after cloning the template you need to make sure you setup the files under the environments-folder correctly (it comes with dev and prod predefined configurations - for development and production environments).
In the config subfolders you'll find the *-local.php files that indicate configuration specific to that environment.
For the database you have to look in common/config/main-local.php.
After you're done with that, just navigate back to the templates' root folder and run ./init. It will ask you which environment you want and put the files in place. Switching to another environment is just an ./init call away.
Obviously you're not obligated to keep on using the environments if you don't have use for it, you might as well modify the /common/config/main.php file and add the connection info there. But given that the advanced template assumes multiple deployment stages for your application it is a very good setup.

Related

Access denied (remote-user and database user are different) on drush sql-sync

With Drush v8.0.3 in both sides (local is a Mac and desarrollo is a Linux Server with CPanel), I'm executing:
sql-sync #project.local #project.desarrollo
and getting this error at the end of the process (everything else works):
ERROR 1045 (28000): Access denied for user 'myremotehostuser'#'localhost' (using password: YES)
My alias file includes this:
$aliases['desarrollo'] = array (
'root' => '/home/myremotehostuser/subdomains/project/',
'uri' => 'http://project.myremotehost.com',
'remote-user' => 'myremotehostuser',
'remote-host' => 'myremotehost.com',
'path-aliases' => array(
'%dump-dir' => '/tmp',
),
'source-command-specific' => array (
'sql-sync' => array (
'no-cache' => TRUE,
'structure-tables-key' => 'common',
),
),
'command-specific' => array (
'sql-sync' => array (
'sanitize' => TRUE,
'no-ordered-dump' => TRUE,
'structure-tables' => array(
'common' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history', 'sessions', 'watchdog'),
),
),
),
);
And drush status on "desarrollo" returns:
Drupal version : 7.41
Site URI : http://project.myremotehost.com
Database driver : mysql
Database hostname : localhost
Database port :
Database username : databaseuser
Database name : databasename
PHP configuration : /usr/local/lib/php.ini
PHP OS : Linux
Drush script : /usr/local/bin/drush
Drush version : 8.0.3
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : /home/myremotehostuser/subdomains/project/
Drupal Settings File : sites/default/settings.php
Site path : sites/default
As you can see, the "database owner" (a MySQL user) is not the same as "remote-host" (a CPanel user).
Drush is supossed to scan the setting files in both sides to figure out the right config, if I'm not wrong, you don't even have to add a $databases array or a db-url string since v7. Then, why is it trying to access the db with 'myremotehostuser'#'localhost' instead of 'databaseuser'#'localhost'?
In this case, there is no database user called 'myremotehostuser' and I guess that I could solve the problem by creating it and granting permissions for 'databasename' but I'm almost sure I'm missing something really dumb here and there must be a simple solution.
edit:
Trying the same alias file in the same server with host user name and database user name still being different, but this time in a freshly created account, seems to work prefectly. So I guess the problem it's being caused by some CPanel/WHM configuration issue rather than any Drush related thing. I will keep trying this a couple of times before closing the question.
I encountered this issue too. It turns out drush is first looking for the file ~/.my.cnf and if it's found, it'll use it to connect. The file contains the username and password.
[client]
user=myremotehostuser
Once I temporarily remove this file, drush can dump the sql successfully using the site's settings.php.
Repeating the rsync and sql-sync processes in new accounts work without problem. The issue only happens in this already created account, with multiple databases, users, and prefixes. I don't have full access to this account so I can't test it properly.
This issue was too specific and probably didn't deserve a question by itself since it's almost impossible to replicate. I'll consider it "solved" and will update it in the case I find out why it's not working.

Predis configuration in Laravel 5.2

I am confused about the Predis setup (PHP client for Redis) in this case in a Laravel 5.2 project.
The documentation says you need to autoload it into composer to use it in the entire app without loading it on each page...
HOW? WHERE? WHAT? do I need to add or write to do this? I can't seem to figure it out as I know very little about installation en server configuration..
This is what I mean. This needs to go somewhere I assume
require 'Predis/Autoloader.php';
Predis\Autoloader::register();
Thx
Another method
Download predis package from https://github.com/nrk/predis
Extract it
Copy the contents of folder into Laravel/vendor/predis/predis. Then folder structure will be
In Controller
class WelcomeController extends Controller
{
public function index()
{
$client = new \Predis\Client([
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379
]);
$client->set('foo', 'bar');
return $value = $client->get('foo');
}
}
If redis is installed in your system, it will return value of 'bar'
Please, read documentation careful:
Autoloading is handled automatically when dependencies are managed through Composer, but it is also possible to leverage its own autoloader in projects or scripts not having any autoload facility:
// Prepend a base path if Predis is not available in your "include_path".
require 'Predis/Autoloader.php';
Predis\Autoloader::register();
By default Laravel uses Composer to install dependencies, so you do not need to do anything special. Just add predis/predis as usual to your deps in composer.json. Read more using of composer here.

Yii2: Cannot perform RBAC migration (You should configure "authManager"...)

As it is described here I'm trying to do the migration in order to let yii create the user authentication tables. However I get the error:
Exception 'yii\base\InvalidConfigException' with message 'You should
configure "authManager" component to use database before executing
this migration.'
The authManager is present in the configuration but I still get that error. Configuration:
'components' => [
...
'db' => $db,
'authManager' => [
'class' => 'yii\rbac\DbManager',
// 'defaultRoles' => ['guest'],
],
...
],
What's the problem?
Problem was quite simple: The configuration was not used. yii migrate is a console command and usually the configuration for such commands is placed in a seperated file.
In case of yii2-app-base template, from which I have created my application, there is a config/console.php configuration file where the authManager needs to be declared. It is not sufficient to have it in the config/web.php declared only.
In case of yii2-app-advanced the authManager should be declared in console/config/main.php and not in the backend or frontend configuration files.

Yii2 Gii : You are not allowed to access this page

I'm using Yii2 advance template and I can access gii tool successfully in my local machine.
But when I upload it into real server, there is a message "You are not allowed to access this page."
Could you tell me which file should I have to config and could you print screen or paste the whole content of that config file?
Thanks you before hand.
You should simply add your IP address in gii config :
'gii' => [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1'] // adjust this to your needs
],
http://www.yiiframework.com/doc-2.0/guide-start-gii.html
EDIT : in advanced app, gii conf is in
environments/dev/backend/config/main-local.php
environments/dev/frontend/config/main-local.php

Configuring MySql inWildFly

I followed the steps trying to configure MySQL in WildFly. I have two questions for your help with:
1) I downloaded the mysql-connector-java-5.1.33-bin.jar and placed it under modules/system/layers/base/com/mysql/main/. Do I need to download the actual MySql? Or the connector jar is sufficient?
2) In creating a new data source in WildFly console, I was not able to create a new data source. Part of the information I need to fill in is a pair of user name and password to access the database. Where should I create this user name and password first? I am guessing this is where I got the problem from.
I got this error message when testing the connection in wildfly console:
Unexpected HTTP response: 500
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "mysqlDSPool")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "JBAS010440: failed to invoke operation: JBAS010447: Connection is not valid",
"rolled-back" => true
}
first you need to install Mysql server and a JDBC 4-compliant driver, normally all new JDBCs provided by Mysql.org are JDBC 4-compliant, find a platform independant one here, then you need to add a datasource here in this file standalone/configuration/standalone.xml or using this command
data-source add --name=myDataSource--jndi-name="java:jboss/datasources/myDataSource" \
--connection-url="jdbc:mysql://localhost:3306/myDB" \
--driver-name=h2 --user-name="myDB_Username" --password="myPassword"
username and password are those used to connect to Mysql database.
1) You need to download the jdbc-driver jar which, I think, is the connector jar. But please don't place it under modules/system/... but directly under modules since the system folder is reserved for internal modules that are delivered with the server.
2) Here is an example (configures an Oracle datasource):
/subsystem=datasources/jdbc-driver=OracleJdbcDriver:add(driver-module-name=oracle.jdbcaq,driver-name=OracleJdbcDriver)
/subsystem=datasources/data-source=OracleDS:add(jndi-name=java:jboss/datasources/OracleDS,enabled=true,jta=true,use-java-context=true,connection-url=jdbc:oracle:oci:#dbms:1523/DEV,driver-name=OracleJdbcDriver,min-pool-size=5,max-pool-size=100,user-name=username,password=password,prepared-statements-cache-size=100,exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter)