I have hosted my drupal site on amazon and wanted to scale the dbserver to handle the increased traffic. I have enabled Read Replica of dbinstance of RDS. I dont know what all changes have to be done from drupal end to get this working.
If anyone has configured the above implementation into their site then some pointers would be really appreciated.
Since Drupal 7, they made it very easy to use it with MySQL master(Read/Write)-slave(Read-only) setup. Assume that we have 2 MySQL servers configured in master-slave mode.
In settings.php, start with the MySQL master configuration.
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'mysql-master-db',
'username' => 'mysql-master-username',
'password' => 'mysql-master-password',
'host' => 'mysql-master(Read + Write)-IP',
);
Now below this, add the following code to configure the slaves.
$databases['default']['slave'][] = array(
'driver' => 'mysql',
'database' => 'mysql-slave1-db',
'username' => 'mysql-slave1-user',
'password' => 'mysql-slave1-password',
'host' => 'mysql-slave1(Read-only)-IP',
);
Now below this, if you want any of the select queries to use the slave server, then use the following syntax:
$query = db_select('node', 'n', array('target' => 'slave'));
By providing array('target' => 'slave') argument, the query will run against one of the slave databases. If there are multiple such queries for the same page, then all will run on the same slave server. If no slave is available, then that option will be ignored and the query will run against the master.
Related
I have implemented the sigle signon in worpress with Java with Aws cognito.
it is working fine with http but after moving http to https. API's are not working and throwing the error below:
WP_Error Object
(
[errors] => Array
(
[http_request_failed] => Array
(
[0] => cURL error 35: error:1408F10B:SSL routines:ssl3_get_record:wrong version number
)
)
[error_data] => Array
(
)
)
I have consumed the get and Post API like below:
$bodyData = array(
'username' => $_POST['username'],
'password' => $_POST['password']
);
$response = wp_remote_post('https://example.com:8083/digitalIdentityProvider/login',
array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '2.0',
'sslverify' => true,
'blocking' => true,
'headers' => array('Content-Type'=> 'application/json'),
'body' => json_encode($bodyData) ,
'cookies' => array()
));
Could you please someone guide or suggest ?
Thanks.
After playing with wordpress code and AWS, I found the issue with Aws ELB and Load Balancer .
SSL Certificate has applied to LB and Third party API and wordpress were hosted on AWS EC2 and for EC2 there was not SSL certificate and I was trying to access API with
HTTPS:
https://example.com:8083/digitalIdentityProvider/login hence request was not verifying over there hence I was not receiving any response from API.
I have changed API call
from https://example.com:8083/digitalIdentityProvider/login
to http://example.com:8083/digitalIdentityProvider/login
after change it https to http. it working fine.
I lost several hours trying to connect to cloud SQL from PHP flex env, but I found the answer.
I hope this help other people.
An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory
or
Access denied for user 'root'#'cloudsql' (using password: NO)
1.- enable Google Cloud SQL API: https://console.cloud.google.com/apis/
2.- get your cloud sql instance name
3.- add the beta_settings to your yaml
beta_settings:
cloud_sql_instances: "here-your-instance-name"
4.- config your doctrine dbal unix_socket
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'dbs.options' => array (
'db_conn' => array(
'driver' => 'pdo_mysql',
'unix_socket' => '/cloudsql/here-your-instance-name',
'host' => 'localhost',
'dbname' => 'your-database',
'user' => 'your-user',
'password' => 'your-password',
'charset' => 'utf8',
'collate' => 'utf8_spanish2_ci'
)
)
));
I need to get the client IP instead I am getting server IP.
My code
$submission = (object)array(
'nid' => $webform_nid,
'uid' => 0,
'submitted' => REQUEST_TIME,
'remote_addr' => ip_address(),
'is_draft' => FALSE,
'serial' => $serial,
'data' => $data,
);
Can anyone please tell me why I am getting the server IP?
Not really in the Drupal way but you can use superglobal
$_SERVER["REMOTE_ADDR"]
"The IP address from which the user is viewing the current page."
http://php.net/manual/fr/reserved.variables.server.php
i want to place the following codes into include/mail.inc of Drupal7 so that i can send mail from SourceForge's project web space. Don't ask me to install SMTP Authentication Support, and i don't have access to php.ini , I wonder where should these codes be placed? Thanks in advance!
include('Mail.php');
$recipients = array( 'someone#example.com' ); # Can be one or more emails
$headers = array (
'From' => 'someone#example.com',
'To' => join(', ', $recipients),
'Subject' => 'Testing email from project web',
);
$body = "This was sent via php from project web!\n";
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'YOUR_PROJECT_NAME',
'password' => 'PASSWORD', # As set on your project's config page
#'debug' => true, # uncomment to enable debugging
));
$mail_object->send($recipients, $headers, $body);
if this code could success send email without drupal7 (you must make sure it)
then you could do it in three ways:
write a drupal 7 module ,copy mail.php into *.module, and make the rest code as a function,that's the way as the handbook of drupal.
just copy all of the code to you theme/page.tpl.php , and run it directly , a little dirty
hack drupal core , include/mail.inc , just change function drupal_mail_send
I created a Drupal website in a XAMPP environment, but would like to further develop it in a MAMP environment. That is, without losing all the content I already added. I changed the settings.php file like this
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => 'localhost:8889',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
But I get the error:
PDOException: SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:8889' (2) in lock_may_be_available() (line 164 of /Applications/MAMP/htdocs/kooknet2/includes/lock.inc).
Does anyone know how I can solve this? Thanks!
It's a tiny error, you've got the port as part of your host string (:8889) when you should be adding it to the array key that actually says port. Try this:
$databases = array (
'default' => array (
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => 'localhost',
'port' => '8889',
'driver' => 'mysql',
'prefix' => '',
),
),
);
If you have local MySQL server, login to it from console, check user-pass-port. It see,s you haven't MySQL instance on 8899 port
I would suggest using the backup and migrate module to grab a copy of your database. Then setup your site on mamp (with a new db/install), and use BAM to restore from your backup.
If you're using the same file path, there shouldn't be any other steps to worry about otherwise you might need to copy/move your files directory and also reconfigure your file path settings in the drupal interface. (Also you may need to be aware that any links to internal content that is embedded in your node body may also need to be adjusted so the path is correct)