Why stomp can't run in apache? - php

Brief Intro
I'm now using stomp to connect with ActiveMQ based on a PHP site running on apache server.
The Stomp can run in bash but can't run in apache.
Preparation
I install stomp by
pecl install stomp
and modify the php.ini with
extension=stomp.so
I have a 'index.php' like this:
<?php
echo 'runing-';
/* connection */
try {
$stomp = new Stomp('tcp://localhost:61613');
echo 'connecting-';
} catch(StompException $e) {
die('Error! Connection failed: ' . $e->getMessage());
}
$stomp->send('/queue/test', 'Hello from PHP');
echo 'finished.';
/* close connection */
unset($stomp);
?>
Start Working
Firstly, I run with
$ php index.php
And it echo as my expectation:
$ php index.php
runing-connecting-finished.
Then I open it in browser:
http://localhost/index.php
It reports
runing-Error! Connection failed: Unable to connect to localhost:61613
Question
I've searching resolution for this error all day...
I guess apache block the request from stomp since it runs successfully in bash.
What should I do to fix this bug?
Thanks really.

an experienced colleague called Justin get things done!
Though not really understand this situation,
I post my solution here:
Firstly, I run sestatus:
$ sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
Justin told me to change settings in /etc/sysconfig/selinux to
SELINUX=permissive
Then I restart and run sestatus again:
$ sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: permissive
Policy version: 24
Policy from config file: targeted
Finally things work!
Linux stuff still seems a little magical for me.
Who knows something about this please give an explanation about this.
Thanks a lot.

Related

Php script gives different result in browser than terminal

I have a simple php script using to test bind to MS active directory, in order to use it for login to an php application. When it runs on browser, responds error: "Can't contact LDAP server", but in terminal works fine.
OS centos 7
php 5.6.40
$ldad = ldap_connect('ldap://{LDAP}.{DOMAIN.COM}','389')
or die('Cannot connect');
ldap_set_option($ldap,LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldap,LDAP_OPT_REFERRALS,0);
if($bind=ldap_bind($ldap,'{USERNAME}#{DOMAIN.COM}','{PASSWORD}')) {
echo "\n\nSuccess Binding!\n\n";
ldap_unbind($ldap);
}
else {
echo ldap_error($ldap);
}
Any suggestions?
Solution found and has to be shared:
SElinux was enabled. I found better to run
semanage boolean -l
to find out if it was on or off, httpd_can_connect_ldap was off so I alter to on using
setsebool -P httpd_can_connect_ldap on
I hope I helped someone with familiar problem.

php command is not recognized in wamp

I'm working on websocket. I came across this article, and simply downloaded their file and try running it in my localhost.
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
What I understand is, they want to sue local server's websocket server.
But I have problem in starting up the server. I'm using windows 10 with wamp 2.2. As I checked webscket is enabled in my php.ini's extention.
I followed this example to cmd the right path to start it but to no avail:
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket/comment-page-1#comment-5593
It says 'php.exe' is not recognized as an internal or external ...
I then searched online again, thus set the path to my php folder in the system's environment variable. The path is: C:\wamp\bin\php. Then I closed the cmd and relaunched. Nothing worked out. The same error shows up.
This is what I did on cmd:
1) cd C:\wamp\bin\php
2) php.exe -q C:\projects\myfolder\server.php
Please help me to connect to wamp server's websocket to run the example I've downloaded.In the console, the error shown is:
WebSocket connection to 'ws://localhost:9000/demo/server.php' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I found the answer from this site: http://rodrixar.blogspot.my/2011/07/how-to-run-php-sockets-in-wamp.html
I did the following,
1) open cmd
2) cd C:\wamp\bin\php\php5.6.19
3)php.exe -q C:\projects\mysite\server.php
4) Firewall open up and allow access for CLI
5) now connection made already..

Neo4J: test from php cmd line works but web doesn't?

Using the following bits:
<?php
require('vendor/autoload.php');
$client = new Everyman\Neo4j\Client('localhost', 7474);
print_r($client->getServerInfo());
?>
If I run this as php test.php I get the expected output.
If I run this via http://server/test.php I get connection errors.
[24-Jun-2014 05:49:52] PHP Fatal error: Uncaught exception 'Everyman\Neo4j\Exception'
with message 'Can't open connection to http://localhost:7474/db/data/' in
/var/www/html/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Transport/Curl.php:91
Clearly I've monkeyed up something with either my PHP config or the installation of this library. Suggestions on where to look?
Installed per these instructions.
Running on CentOS 6.4 (x64), PHP 5.3.3
NOTE: I've made successful connections from other machines back to this server so I know the neo4j server is working. It just doesn't seem to want to let me connect locally when called via browser.
I had same issue, it was caused by SeLinux
Try disabling it by:
echo 0 >/selinux/enforce
then recheck connection.
If solved configure SeLinux permissions.
In my case httpd_can_network_connect should be on
setsebool -P httpd_can_network_connect on
echo 1 >/selinux/enforce
Helpful manual:
http://wiki.centos.org/TipsAndTricks/SelinuxBooleans

SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XXX.XXX.XXX.XXX' (60)

I'm developing a Web Application under PHP with a remote database, in which I have the following test script:
try {
$dbh = new PDO('mysql:host=XXX.XXX.XXX.XXX;dbname=db_app;', $user, $password);
$date = ($dbh->query('SELECT NOW()');
print_r($date);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
exit();
and when I run it I get the following output:
Error!: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '10.16.50.87' (60)
I can still connect to the target database using MySQL workbench and through Command Line Interface.
From this question I get that the remote server configuration "could have been" the problem. However, we have a "brother" PHP application connecting to the same server without problems, the only difference beetwen the two is the username and password, and even when running tests on my application using the "brother" PHP application credentials, the same error is shown. So it seems that only my PHP seems to have the problem.
I'm running tests on PHP 5.5.3 and the target server is running MySQL 5.5
Both My Application and the Brother Application are running on the Staging Server A, and both should be connecting to MySQL in Staging Server B. The Brother application is also written in PHP and is able to connect, but mine isn't. I'm guessing it could be a MySQL-relative PHP configuration.
My application uses PDO, while the brother application uses
mysqli.
The brother application runs on the same server as my application,
and connects to the same target server.
Any help would be appreciated.
For me it was SELinux causing the issues:
[root#server ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
[root#server ~]# setenforce 0
[root#server ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
Run below as root:
setsebool -P httpd_can_network_connect=1

Can't connect to MongoDB through PHP

I just wanted to take a look at Mongo-DB. But i just don't get it running. I've installed it with PECL and my phpinfo() tells me that the extension is loaded, but when i try to get a connection with
$mongo = new Mongo();
I get this:
Fatal error: Uncaught exception 'MongoConnectionException' with
message ': Transport endpoint is not connected'
Anybody have the same Problem? ... Or any Idea on this?
Please don't take this the wrong way, but have you actually got the server running? Only it looks like your error relates to a failure to connect and you've made no mention of the server or where it is located (localhost on the default port for example)
any server start method, such as "/etc/init.d/mongodb start" or "service start mongodb" will fail, if a stale lock file still exists. In Ubuntu/Debian this is /var/lib/mongodb/mongod.lock. Look for this and delte it, if it exists and seems to be an old one.
check out whether server is running or not..
/etc/init.d/mongodb start
then go to
root#kannan-desktop:~# mongo
MongoDB shell version: 1.6.3
connecting to: test
>
Don't forget to change the IP in your mongod.conf if it's a new installation.
custom string looks like that
mongodb://username:password#host:port/database
First Change the Default db path by following command
$ sudo mkdir -p /data/db/
$ sudo chown id -u /data/db
and then the final command is..
$ mongod --journal
Do not close terminal until you are working with mongoDB
It works for me...
just write mongod in your terminal and will work well

Categories