We are using linux server CENTOS 7 but virtual. We install to /var/mqm (9.2-IBM-MQC-linux) to our server. we install /mqseries-0.15.0 with /opt/cpanel/ea-php74/root/usr/bin/phpize to our server. we try to connect with IBM MQ with php code
<?php
$mq_host_ip='****(1414)';
$queue_name = '****';
$mq_server = '****';
$mqcno = array(
'Version' => MQSERIES_MQCNO_VERSION_2,
'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
'MQCD' => array(
"ChannelName" => "*****",
'ConnectionName' => $mq_host_ip,
'TransportType' => MQSERIES_MQXPT_TCP
)
);
// Connect to the MQ server
mqseries_connx($mq_server,$mqcno,$conn,$comp_code,$reason);
if ($comp_code !== MQSERIES_MQCC_OK) {
echo 'Cannot open connection to server: ' . $comp_code ."--".$reason."--". mqseries_strerror($reason);
}else{
echo 'Connection good!';
}
?>
we get the error this
Cannot open connection to server: 2--2035--Not authorized for access.
.This is the our folder /home/trialwebsite/public_html.
Best Regards.
Murat ÖZKAN
The queue manager error log will usually tell you what specifically is wrong with the authentication/authorisation for a client program. The userid associated with the channel does not have appropriate rights or cannot be authenticated.
But one problem you might have with PHP is that it looks like the PECL-published PHP MQ library has not been maintained for a number of years and does not recognise the MQCSP structure needed to set the userid/password that the queue manager might be expecting. There is an un-merged PR opened at https://github.com/php/pecl-networking-mqseries/pull/5 which claims to add the MQCSP support so you might be able to do a git clone and use that branch as an alternative source of the interface.
Related
I'm trying to move my application to Heroku but I'm having problems accessing the database via PHP. I'm able to access the AWS database from my machine locally, but when I deploy to Heroku it fails.
I've followed directions from the main page: https://devcenter.heroku.com/articles/amazon-rds
And I've tried other threads on SO/AWS:
Getting Mysql2::Error (SSL connection error: ASN: bad other signature confirmation) on Heroku App with AWS RDS
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html#MySQL.Concepts.SSLSupport
I also saw instructions here:
https://devcenter.heroku.com/articles/getting-started-with-php#provision-a-database
But I'm trying to port an existing application so I need to stick with my existing PDO syntax. I'm trying to get this to work:
$dbInfo = getenv('DATABASE_URL');
try{
$dbh = new PDO($dbInfo);
echo json_encode(array('outcome' => true));
}
catch(PDOException $ex){
echo json_encode(array('outcome' => false, 'message' => 'Unable to connect'));
}
I have the environmental variable setup properly and can run parse_url to access all of the array items; I also have the amazon-rds-ca-cert.pem located in the config folder.
I'm able to login remotely (via SequelPro) and have run the following in the query manager to try to force SSL cert:
GRANT USAGE ON *.* TO 'username'#'%' REQUIRE SSL;
But when I intentionally misspell the cert name my local database can still connect, which makes me think maybe I am missing something with the requirement.
Figured it out; needed to manually specify the SSL certificate within the PDO connection. Also had minor errors in the PDO syntax.
try{
$dbh = new PDO("mysql:host=$pdohost;dbname=$pdodb", $pdouser, $pdopass, array(
PDO::MYSQL_ATTR_SSL_CA =>'path/to/combined-cert.pem'
));
echo json_encode(array('outcome' => true));
}
catch(PDOException $ex){
echo $ex;
echo json_encode(array('outcome' => false, 'message' => 'Unable to connect'));
}
Also needed to be sure to update the AWS inbound rules to 0.0.0.0/0 to allow for Heroku to access.
So I have written a basic program with PHP and MongoDB and I tested it locally using xampp. This all works fine. Now I want to publish it as a website.
After some research I decided to use Bitnami and I am running an EC2 server on Amazon. I am able to ssh and run commands from the terminal. Now I want to connect to the server and create a Mongo client. I am a bit puzzled and do not know how to do this exactly. I am using the code below. The ssh works fine but I do not know how to set up the mongo client. The '$m = new MongoClient();' works fine locally for localhost, I have also tried to supply to MongoClient my username and password but without success. Thank you very much for any help!
include('Net/SSH2.php');
include('Crypt/RSA.php');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('../../etc/bitnami.pem'));
$ssh = new Net_SSH2('ip_address');
if (!$ssh->login('bitnami', $key)) {
exit('Login Failed');
}
$ssh->exec('mongo admin --username root -p <myPassword>');
$m = new MongoClient();
$db = $m->mydb;
echo "Database mydb selected";
$collection = $db->mycol;
echo "Collection selected succsessfully";
$document = array(
"title" => "MongoDB",
"description" => "database"
);
$collection->insert($document);
Update answer to Jota Martos (unable to write it as comment):
Hi, thank you for your answer. Yes for now I allow access from all ports and IP's for test purposes. I can successfully connect via ssh but now I am stuck. I am running a Mean bitnami application and my website is running on GoDaddy server under PHP. So I want to connect with PHP to my mongoDB bitnami app that is hosted on AWS. So now the problem is that on my GoDaddy server mongoDB is not installed. So running the following code does not work:
$m = new MongoDB\Driver\Manager("mongodb://${bitnami}:${AWSpassword}#hostIp");
Fatal error: Class 'MongoDB\Driver\Manager' not found.
So my question how do I connect with PHP from my GoDaddy server to the EC2 Amazon server and connect to Bitnami mongoDB account. Should I first setup an ssh connection to the server and then try to login to mongoDB server or how should I connect?
Any help is appreciated, thank you in advance!
According to php.net the function that is used is Deprecated, refer this.
Can you try something like:
<?php
$manager = new MongoDB\Driver\Manager("mongodb://myusername:myp%40ss%3Aw%25rd#example.com/mydatabase");
?>
Refer this
Hi Bitnami Engineer here,
Apart from this tip, please note that the database port for the nodes in this solution cannot be accessed over a public IP address by default. For security reasons, we do not recommend making the database port accessible over a public IP address.
https://docs.bitnami.com/aws/infrastructure/mongodb/#how-to-connect-to-mongodb-from-a-different-machine
You can open the MongoDB port in the server by accessing the AWS console and modifying the access group configuration
https://docs.bitnami.com/aws/faq/#how-to-open-the-server-ports-for-remote-access
You will also need to modify the MongoDB configuration file (/opt/bitnami/mongodb/mongodb.conf) to allow the database to not to work only on 127.0.0.1.
Regards,
Jota
If you are looking to connect a tool like Studio 3T to a remote Mongodb instance built using bitnami AMI you can follow the steps below:
1. Open inbound port 27017 on instance security group.
2. Open Instance log of the instance and find the password for user root.
3. Open Studio 3T, server name is instance public ip and port 27017.
4. Got to Authentication and select basic and put in the user as root and password as obtained from instance log.
Click on Test Connection, it should work.
I'm configuring a Magento 1.9.1 to use an external SMTP to send emails, using SMTP PRO (https://www.magentocommerce.com/magento-connect/smtp-pro-email-free-custom-smtp-email.html).
I've setup the configuration (hostname, port, username, password) but when I try to send a test email it fails with a 'Could not open socket' error message. If I dig into the code I see that the error is generated from this piece of code in lib/Zend/Mail/Protocol/Abstract.php:
$this->_socket = #stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
if ($this->_socket === false) {
if ($errorNum == 0) {
$errorStr = $remote.' Could not open socket '.phpversion();
}
/**
* #see Zend_Mail_Protocol_Exception
*/
#require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($errorStr);
}
My PHP environment (5.6.30) has openssl support (see image and snippet below)
[root#ns3023903 httpdocs]# php -r 'print_r(stream_get_transports());'
Array
(
[0] => tcp
[1] => udp
[2] => unix
[3] => udg
[4] => ssl
[5] => sslv3
[6] => sslv2
[7] => tls
)
There are no firewall issues as i can both telnet on the port 465 to the target host or send an email using the same SMTP using phpmailer with the same user I use to run the site virtualhost.
I'm on a CentOS 7 64 bit server, with SELinux disabled and, if that matters, I'm using Plesk 12 to configure virtual hosts.
Name resolution is also working ok (I can ping the SMTP name correctly and the IP address is looked up just fine).
I'm obviously missing something here...but what?
It turned out it was something that changed in the PHP version 5.6.30, in terms of default options assumed by stream_socket_client().
First of all before getting rid of the stupid # in front of the stream_socket_client call in the Magento core code I wasn't actually able to understand what was going on. I'm not even close to a PHP developer so I keep forgotting what that stupid # prefix is for (to be honest I don't even know why it exists).
After removing the # I saw this:
Warning: stream_socket_client(): Peer certificate CN=`*.aruba.it' did not match expected CN=`mail.myclientreserveddomain.com'
I looked a bit into the PHP documentation and I came out with a two line diff to the core code (I know this is not right, I'll refactor it now, but I wanted to share the quick workaround first).
Basically I'm creating a context and using another version of the stream_socket_client call
$context = stream_context_create(['ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]]);
// open connection
$this->_socket = stream_socket_client($remote, $errorNum, $errorStr, 120, STREAM_CLIENT_CONNECT, $context);
Skipping peer name validation is the key. Not sure why/how/when it changed from php pre 5.6.30 to PHP 5.6.30 (have I said I'm not a PHP dev?) but it works. I also tried to run the original code under PHP 5.4.x and it worked without the workaround so it's definitely that.
I am working on a Webservice and I'm using Predis as a redis library and I want the clients to be able to reuse the same TCP socket.
Currently , after running a load test on my service , I found that the number of socket in TIME_WAIT state increase fast on the server and at some point the connexion to Redis server gets refused.
According Redis documentation using PhpiredisStreamConnection with presistant option fixes the problem , but after adding this to my connect code , I m still facing the same issue. Any ideas?
Im using TCP connection as the redis instance are not on front servers.
<?php
include 'autoload.php';
$parameters = array(
'tcp://some.host01:6379?database=0&alias=master&persistent=1',
'tcp://some.host02:6379?database=0&alias=slave&persistent=1',
);
$options = array( 'replication' => true ,
'connections' => array('tcp' => 'Predis\Connection\PhpiredisStreamConnection','unix' => 'Predis\Connection\PhpiredisStreamConnection') );
$predis = new Predis\Client($parameters, $options);
?>
As per the documents Predis works for persistent connections when php process are configured as persistent process . Look at the following for more details :
https://github.com/joindin/joindin-web2/blob/master/vendor/predis-0.8/FAQ.md
http://php-fpm.org/
I followed the post at http://blog.phpdeveloper.org/?p=140 to connect to a remote WebsphereMQ from PHP / Linux using the mqseries extension and was able to get the connection working.
However, the request is being sent with the username of the apache user on the client and the MQ server is rejecting the messages with error 2035. The only way I found to work around the issue is to change the profile under which apache is running to a username that has access on the MQ server.
Is there a way to pass a username when establishing connectivity to WebSphere MQ from php using mqseries? Following is the code I am using to connect:
//define connection parameters
$mqcno['MQCD'] = array(
'ChannelName' => $options['channel'],
'ConnectionName' => "$mq_host_ip($mq_host_port)",
'TransportType' => MQSERIES_MQXPT_TCP
);
// Connect to the MQ server
mqseries_connx($options['qmanager'], $mqcno, $this->_conn, $comp_code, $reason);
if ($comp_code !== MQSERIES_MQCC_OK) {
die ("Cannot open connection to server $mq_host_ip($mq_host_port) : ".$comp_code. " " .$mq_server. " " .$reason. " " );
}
Thanks,
Bhaskar
No, the PHP is just a wrapper around the C based MQI (see the instructions which talk about linking with mqm and mqic - the C libraries), and there's no way of supplying a username from the C client api, sorry.