Echofish Error 500 "CDbConnection failed to open the DB connection" - php

I have to test Echofish to centralize log files.
I followed the installation procedure , but this one does not seem up to date.
When that connects me to the web interface , I get an error 500 - "CDbConnection failed to open the DB connection."
Error 500 in Echofish
When manually connects me to the database with " mysql -u echofish -p ETS_echofish ", it's works.
I changed the file db.php following documentation.
<?php
return array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=ETS_echofish',
'emulatePrepare' => true,
'username' => 'echofish',
'password' => 'my_password',
'charset' => 'utf8',
);
I use CentOS 7
Echofish uses Yii
Thanks

Please try this
<?php
return array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=ETS_echofish',
'emulatePrepare' => false,
'username' => 'echofish',
'password' => 'my_password',
'charset' => 'utf8',
);

Found the following solution which avoided disabling SELinux: Connect DATABASE Error TYPE: 2002: Permission denied
Basicly setsebool -P httpd_can_network_connect_db 1
That solved my problem. Hope it helps.

Related

sqlsrv_connect works fine in php but fails in laravel on the same server(AWS EC2 Instance)

I am trying to connect MSSQL database as my second database in Laravel, In the core PHP file It works fine but when I try to connect in the laravel It throws an error.
Here is my .env
MSSQL_CONNECTION=sqlsrv
MSSQL_DATABASE_URL='/EC2AMAZ-61LPEGK\SQLEXPRESS'
MSSQL_HOST=XX.XX.X.XXX
MSSQL_PORT=1433
MSSQL_DATABASE="/dbcrm"
MSSQL_USERNAME="sauser"
MSSQL_PASSWORD='dbpassword123'
MSSQL_TRUSTSERVER='yes'
MSSQL_ENCRYPT=False
MSSQL_STRICT=false
and here is my laravel database config:
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('MSSQL_DATABASE', '/EC2AMAZ-61LPEGK\SQLEXPRESS'),
'host' => env('MSSQL_HOST', 'XX.XX.X.XXX'),
'port' => env('MSSQL_HOSTDB_PORT', '1433'), //I had tried null
'database' => env('MSSQL_DATABASE', '/dbcrm'), //tried without '/'
'username' => env('MSSQL_USERNAME', 'sauser'),
'password' => env('MSSQL_PASSWORD', 'dbpassword123'),
'trust_server_certificate' => env('MSSQL_TRUSTSERVER', 'yes'), //tried 'no'
'encrypt' => env('MSSQL_ENCRYPT', False), //tried true
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
Here is the PHP file code which works fine and connect the database as well as execute the query,
$host ="XX.XX.X.XXX";
$username ="sauser";
$password ="dbpassword123";
$database ="dbcrm";
$params = [
"UID" => $username,
"PWD" => $password,
"Database" => $database,
"TrustServerCertificate" => "yes",
];
if(sqlsrv_connect($host, $params)) {
echo "connected..";
} else {
echo "Connection could not be established.<br />";
echo "<pre>";
die( print_r( sqlsrv_errors(), true));
echo "</pre>";
}
I am using the same server for both cases and I have installed/enabled SQLSRV. Please find the phpinfo screenshots for reference.
Why it is working in PHP file but not in the Laravel. Please help.
Note : MSSQL database is installed on another AWS windows Instance and TCP is enabled, and port number is 1433
Here is the error what I am getting,
Finally, able to figure out the issue, Posting the same so it will help someone who has struck for days and ripping their hair out to find the solution.
Change the below .env variables and database config as below,
MSSQL_ENCRYPT=yes
MSSQL_TRUSTSERVER=True
config/database.php
'trust_server_certificate' => env('MSSQL_TRUSTSERVER', true), //Some libraries accessing ODBC/JBDC require Yes/No settings, others True/False,
'encrypt' => env('MSSQL_ENCRYPT', 'yes'), //same here try Yes/No or True/False

Can't connect to RabbitMQ on Amazon MQ

I created an Amazon MQ broker:
Select broker engine: RabbitMQ 3.8.6
Single-instance broker
Network and security: Public access
VPC and subnets: Use the default VPC and subnet(s)
I have tried two libraries: from RabbitMQ manual and Enqueue\AmqpExt
Either of them cannot connect to Amazon (with docker container all works fine. But I want to try AMAZON MQ.
I used code below:
use Enqueue\AmqpExt\AmqpConnectionFactory;
use PhpAmqpLib\Connection\AMQPSSLConnection;
$connectionFactory = new AmqpConnectionFactory([
'host' => 'b-da219bXXXXXXXXXXXX86a.mq.us-east-1.amazonaws.com',
'port' => 5671,
'vhost' => '/',
'user' => 'xxxx',
'pass' => 'xxxx', // I can login with this to rabbit admin panel
'persisted' => false,
'ssl_on' => false,
'ssl_verify' => false,
]);
$c = $connectionFactory->createContext();
$queue = $c->createQueue('emails');
$c->declareQueue($queue);
Result:
Library error: connection closed unexpectedly - Potential login failure.
With 'ssl_on' => true the same error.
I don't know can it be happen because I didn't provide ssl cert to amazon.
If so, how to fix it?
I've had success with php-amqplib, and I am actually not using the newest version (I am on v2.12.3). I can connect using this:
$connection = new AMQPSSLConnection($host, $port, $user, $pass, $vhost, ['verify_peer_name' => false], [], 'ssl');
I found that I had to set 'verify_peer_name' => false, or else I just got a unable to connect to ssl://localhost:5671 (Unknown error) error, but I was also port-forwarding through localhost.
Amazon MQ broker (RabbitMQ specifically) is using SSL by default (you can notice that connection string starts with amqps, not amqp
In your case, you should set to true ssl_on and ssl_verify options
Answered by #Eugene K in a sub-comment:
You need to add the DSN to the SSLOptions array, and you need to use a AMQPSSLConnection instead of an AMQPStreamConnection
$this->connection = new AMQPSSLConnection(
'myhost.mq.eu-west-1.amazonaws.com',
'5671',
'username',
'xxx',
'/',
[
'dsn' => 'amqps:'
]
);
I see you installed amqp-ext and using it's ConnectionFactory
use Enqueue\AmqpExt\AmqpConnectionFactory; but
If you are using php-enqueue and want to connect to AWS AMQ RabbitMQ you should install and use enqueue/amqp-lib instead of enqueue/amqp-ext
and connection details
use Enqueue\AmqpLib\AmqpConnectionFactory;
new AmqpConnectionFactory([
'host' => env('RABBITMQ_HOST'),
'port' => env('RABBITMQ_PORT', 5672),
'vhost' => env('RABBITMQ_DEFAULT_VHOST'),
'user' => env('RABBITMQ_USERNAME'),
'pass' => env('RABBITMQ_PASSWORD'),
'persisted' => false,
'ssl_on' => true,
'ssl_verify' => true,
]);

PHP PDO MySQL Tunnel Connection Double Port [duplicate]

This question already has an answer here:
PHP PDO initialization fails due to "double port" - Uncaught PDOException: SQLSTATE[HY000] [2002]
(1 answer)
Closed 5 years ago.
Before i've installed my app and works fine but when i make new installation on other device with same code and config,
i got error when trying to connect tunneling mysql with pdo extensions on yii 1.
The error message like this:
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Failed to parse address "localhost:3307:3306"
I just want to connect with port 3307 but :3306 auto included
I've tried some method but keep not working
My main config:
'db' => array(
'class' => 'CDbConnection',
'connectionString' => !empty($ini['db']['conn_str'])
? $ini['db']['conn_str'] : 'mysql:host=localhost;dbname=xxx',
'username' => !empty($ini['db']['user'])
? $ini['db']['user'] : 'root',
'password' => isset($ini['db']['password'])
? $ini['db']['password'] : 'xxx',
'tablePrefix' => !empty($ini['db']['prefix'])
? $ini['db']['prefix'] : 'dcl_',
'emulatePrepare' => true,
'charset' => 'utf8',
'schemaCachingDuration' => 86400,
'enableParamLogging' => TRUE,
'enableProfiling' => TRUE,
),
'dbmm' => array(
'class' => 'CDbConnection',
'connectionString' => !empty($ini['dbmm']['conn_str'])
? $ini['dbmm']['conn_str'] : 'mysql:host=localhost;dbname=xxx',
'username' => !empty($ini['dbmm']['user'])
? $ini['dbmm']['user'] : 'root',
'password' => isset($ini['dbmm']['password'])
? $ini['dbmm']['password'] : 'xxx',
'tablePrefix' => !empty($ini['dbmm']['prefix'])
? $ini['dbmm']['prefix'] : 'mm_',
'emulatePrepare' => true,
'charset' => 'utf8',
'schemaCachingDuration' => 86400,
'enableParamLogging' => TRUE,
'enableProfiling' => TRUE,
'attributes' => array(
PDO::MYSQL_ATTR_LOCAL_INFILE => true
),
),
'dbantrian' => array(
'class' => 'CDbConnection',
'connectionString' => !empty($ini['dbantrian']['conn_str'])
? $ini['dbantrian']['conn_str'] : 'mysql:host=localhost;dbname=xxx',
'username' => !empty($ini['dbantrian']['user'])
? $ini['dbantrian']['user'] : 'root',
'password' => isset($ini['dbantrian']['password'])
? $ini['dbantrian']['password'] : 'xxx',
'emulatePrepare' => true,
'charset' => 'utf8',
'schemaCachingDuration' => 86400,
'enableParamLogging' => TRUE,
'enableProfiling' => TRUE,
),
My .ini file:
[db]
conn_str = "mysql:host=localhost:3307;dbname=xxx"
user = "root"
password = "xxx"
prefix = "dcl_"
[dbmm]
conn_str = "mysql:host=localhost:3307;dbname=xxx"
user = "root"
password = "xxx"
prefix = "mm_"
[dbantrian]
conn_str = "mysql:host=localhost:3307;dbname=xxx"
user = "root"
password = "xxx"
The tools what i use:
Ubuntu 16
Ajenti V
Nginx
PHP 5.6
PDO and PDO Mysql
MariaDB 5.7
I can't use the solution from PHP PDO initialization fails due to "double port" - Uncaught PDOException: SQLSTATE[HY000] [2002] because i disallowed to update core files of yii
I don't know what i miss
Thanks before and sorry for my english
Update:
My app on old device has error (like on my new app) after sudo apt upgrade
Setting up php5.6-common (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-curl (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-sqlite3 (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-mbstring (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-xml (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-gd (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-readline (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-mcrypt (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-json (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-mysql (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-opcache (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-cli (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-fpm (5.6.30-10+deb.sury.org~xenial+2) ...
NOTICE: Not enabling PHP 5.6 FPM by default.
NOTICE: To enable PHP 5.6 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php5.6-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Setting up php-msgpack (2.0.2+0.5.7-1+deb.sury.org~xenial+2) ...
Setting up php-mysql (1:7.1+52+deb.sury.org~xenial+1) ...
Setting up php-pgsql (1:7.1+52+deb.sury.org~xenial+1) ...
The configuration string should look like:
mysql:host=localhost;port=3307;...
The port part must be separated from the host.

Having trouble with sqlsrv on CentOS 7. Looking for assistance or possibly ODBC alternative

I'm having a try at connecting to a MSSQL DB using PHP on a Linux system.
Using tsql -S <dbConfig> or tsql -H <dbHost> successfully connects to the database (with user credentials of course). However, using the same host and config within PDO returns a failed to connect to host adapter error.
The issue seems to be living somewhere between PHP PDO and, I'm assuming freetds.
The debug looks like this:
PDOException in Connector.php line 55:
SQLSTATE[01002] Adaptive Server connection failed (MYHOST.database.windows.net) (severity 9)
in Connector.php line 55
at PDO->__construct('dblib:host=MYHOST.database.windows.net;dbname=RecipeDB;charset=utf8', 'MYUSER#MYHOST', 'MYPASSWORD', array('0', '2', '0', false)) in Connector.php line 55
at Connector->createConnection('dblib:host=MYHOST.database.windows.net;dbname=RecipeDB;charset=utf8', array('driver' => 'sqlsrv', 'host' => 'MYHOST.database.windows.net', 'database' => 'RecipeDB', 'username' => 'MYUSER#MYHOST', 'password' => 'MYPASSWORD', 'charset' => 'utf8', 'prefix' => '', 'name' => 'remoteRecipes'), array('0', '2', '0', false)) in SqlServerConnector.php line 32
at SqlServerConnector->connect(array('driver' => 'sqlsrv', 'host' => 'MYHOST.database.windows.net', 'database' => 'RecipeDB', 'username' => 'MYUSER#MYHOST', 'password' => 'MYPASSWORD', 'charset' => 'utf8', 'prefix' => '', 'name' => 'remoteRecipes')) in ConnectionFactory.php line 61
at ConnectionFactory->Illuminate\Database\Connectors\{closure}()
It seems I'd managed to remove the line containing [global] from my /etc/freetds.conf file. Once I replaced it PDO was able to make a call to the database.
Below is what it looks like for me:
[global]
# TDS protocol version
; tds version = 4.2
tds version = 8.0
client charset = UTF-8
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
dump file = /tmp/freetds.log
debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[testConnection]
host = MYHOST.database.windows.net
port = 1433
tds version = 8.0

imap_open failed in my server but works in local

$mailboxes =
array(
'label' => 'Mail',
'mailbox' => '{mail.example.com:143/novalidate-cert}INBOX',
'username' => "myadress#mail.com",
'password' => "mypassword"
);
imap_open($mailboxes['mailbox'], $mailboxes['username'], $mailboxes['password'])
I have caught this error when I use imap_last_error() :
"Connection failed to mail.example.com,143: Connection timed out"
But when I have tried it in localhost (Wampserveur), everything works fine.
Note: extension=php_imap.dll is enable on my serveur.

Categories