could not connect localhost with cassandra? - php

my cassandra is working well in CLI. and thrift also installed well. i already started apache server and cassandara..but when trying to execute php file that is not executed on browser.it shows the error as:
TException: Error: TSocket: Could not connect to localhost:9160 (Permission denied [13])
and the 12th and 13th line is:
$socket = new TSocket('localhost', 9160);
$transport = new TBufferedTransport($socket, 1024, 1024);
i gave 127.0.0.1 instead of localhost.even it is not working.
can any one please help me?

hi every one i solve the problem....
selinux is cause for that problem.....
TException: Error: TSocket: Could not connect to localhost:9160 (Permission denied [13])
To resolve it, you need to change an SELinux boolean value (which will automatically persist across reboots). You may also want to restart httpd to reset the proxy worker, although this isn't strictly required.
setsebool -P httpd_can_network_connect 1
http://wiki.apache.org/httpd/13PermissionDenied

Related

mysqlnd gives 'permission denied' for all connections to a remote host

This is not about 'localhost'. Both the command line version of 'mysql' as well as a script I wrote in Perl (using perl-DBD-MySQL) can login, get to this database and work with it. Only PHP gives the permission denied error, and that error is not reported in any of the various log files. I even went as far as creating a simple test user in the database to avoid any issues with special characters in the password:
create user 'web'#'%' identified by 'Iamnotarobot';
and again the command line can login with this credential but PHP says permission denied.
I don't know what is throwing the error so I can't address it. I'm literally lost.
Relevant info:
RHEL 8 = 4.18.0
php 7.2.11
nginx 1.14.1
And here's the actual code that's failing:
<?php
$host="core";
$user="web";
$pass="Iamnotarobot";
$db="mydb";
$conn = new mysqli($host,$user,$pass,$db);
if( $conn->connect_errno ) {
exit($conn->connect_errno);
}
?>
It turned out to be an selinux issue. Here's how I fixed it:
setsebool -P httpd_can_network_connect_db 1
Now with setenforce back to '1', the page can connect to the database.
Check with php-mysql package installation.
If perl can connect remotely and php could not...the issue is with php-mysql installation only.

CentOS 7 unable to connect clamd.sock file (Permission denied error)

I am trying to scan uploaded files on PHP server using clamAV. I've installed ClamAV on my server (Centos 7). Currently, I am using PHP 7, so I am using Clamd socket connection to scan uploaded files. I've enabled PHP sockets, clamd.sock file is present at /var/run/clamd.scan/ folder with apache owner.
My Socket connection code -
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
if(socket_connect($socket, '/var/run/clamd.scan/clamd.sock')) {
return $socket;
}
When I try to run above code on the browser I am getting error as socket_connect(): unable to connect [13]: Permission denied, But if I run the PHP code through command line with a user as root it is working fine.
I know there is some issue with SELinux policy with Centos as if I disable SELinux policy everything is working fine from the browser as well. I have checked httpd_can_network_connect --> on and antivirus_can_scan_system --> on both are on.
The issue is with accessing anything inside /var/run/ folder for apache user, there is something (some policy) from SELinux which is stopping apache to connect to clamd socket file. Any ideas?
After debugging, got to know that this is SELinux policy issue.
You need to enable daemons_enable_cluster_mode policy in SELinux.
To Enable daemons_enable_cluster_mode:
setsebool -P daemons_enable_cluster_mode 1
This will allow executing ClamAV scan through another service like Apache in my case.

php pdo in linux, not able to connect to remote mysql server but in wamp it's working fine [duplicate]

I am facing a weird problem here
we have a server A where the app files are stored
and B server with database
Tried to connect via command prompt from server A to B using the command
mysql -h xx.xx.xx.xx -u root -p password - and it worked
NOw i tried to create a php script in server A to connect to server B
the command is
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password');
Connection failed: SQLSTATE[HY000] [2003] Can't connect to MySQL
server on 'xx.xx.xx.xx' (13) Fatal error: Uncaught exception
'Exception' with message 'SQLSTATE[HY000] [2003] Can't connect to
MySQL server on 'xx.xx.xx.xx' (13)'
Unable to find a solution on this.
Can any help on this?
thank you
I got it working by running a command in the database server :)
setsebool httpd_can_network_connect_db=1
thanks for the replies yycdev
Try specifying the port in your connection string and ensure the database server is set to allow remote connections and the port is open on your firewall (both of these I suspect are already done as you are able to connect via the terminal but it never hurts to verify and check things).
Change your PDO connection and add the port=3306 or if you're using MAMP use port 8889
$this->db=new PDO('mysql:host=xx.xx.xx.xx;port=3306;dbname=databasename','root','password');
Another thing to check is if – SELinux is blocking network connections. Login as root and run
setsebool -P httpd_can_network_connect=1
I don't know much about that, but try to place the port in back of the script:
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password',3306);

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

Can't connect to remote MySQL server (uses default server instead)

I'm trying to connect to an AWS MySQL server from my VPS, but no matter what I try, I just get access denied, my user has privileges to connect from any host.
If I try to connect via PHP:
$db = new mysqli('mysite.cufncdsjslka.us-east-1.rds.amazonaws.com', 'my_user', 'my_pass', 'my_db');
Gives me: Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'my_user'#'XXXX.myhost.com' (using password: YES) in /home/me/shopify/libraries/db.lib.php on line 4
If I try to connect via the MySQL CLI:
mysql -h mysite.cufncdsjslka.us-east-1.rds.amazonaws.com -umy_user -p
Gives me:
ERROR 1045 (28000): Access denied for user 'my_user'#'xxxx.myhost.com' (using password: YES)
This command works flawlessly on my PC, but not on my VPS.
I'm assuming it's some sort of security setting preventing MySQL from using external servers?
My VPS is running Debian squeeze with the LAMP components all from the standard Debian packages except for PHP which I manually updated to 5.4.
I'm posting this as a new question since most similar questions I've found on SO were a permissions issue (I've given my MySQL user priveliges to connect from any host) or a SELinux issue (which AFAIK doesn't apply to Debian)
OK.
I have seen this problem number of times for many different reasons. Since I cannot see your server or your logs so I am guessing from the information that there could be bind address issue.
In my.cnf check
bind-address=YOUR-SERVER-IP
change it to the the ipaddress of your mysql server for example 81.92.33.45
restart mysql after this. And if you are still unable to connect then let me know with the error info from log and I will look again.
Secondly make sure iptables are not causing problems.
iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

Categories