I have installed redis packages on my AWS ubuntu server and everything is working fine from the command line.
I have run the below things from command line and it shows me correct response.
netstat -nlpt | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 23504/redis-server
so my redis server is running correctly on 6379 port also I have added this port on aws security group so firewall is also not blocking.
Also when I check my redis log it also seems to be fine. below is my log.
The server is now ready to accept connections on port 6379
But when I run the below code from my PHP and I get the below error.
$redis = new Redis();
$redis->connect('localhost');
$redis->set('param',999);
echo $redis->get('param');die;
Error I am getting...
The mcook.co.in page isn’t working
mcook.co.in is currently unable to handle this request.
HTTP ERROR 500
I have tried the below solution mentioned in stackoverflow.com but none of are working for me.
Redis - Connect to Remote Server.
Related
The title might make this seem like a duplicate of some existing questions here on SO, but its kind of not in a way, in my opinion.
8140863, 30617357, 27749691
But I can't for the life of me make the answers to these threads work, instead of asking questions on those threads, I would like to create my own question, I'd like to discuss my setup and then my problem, and then what I've tried
My server setup is this, I have a local(an actual physical machine) and a VPS I'm renting, both are running at Centos7.x, PostgreSQL10, Php 7.x, and Python-2.x, BOTH can ping and ssh each other through a VPN just fine.
Both can connect to their own respective databases just fine through PHP, Python, PSQL Terminal
On my VPS Server, I can connect to my Local Server's PostgreSQL database using Python(psycopg2), PHP(php-pgsql) and Terminal(psql) totally fine.
On my local server, I can connect to my VPS PostgreSQL using Python(psycopg2) and Terminal(psql) EXCEPT through PHP(php-pgsql)
Whenever I connect to VPS's PostgreSQL through PHP, I'm getting this error like everyone else
pg_connect(): Unable to connect to PostgreSQL server:
could not connect to server: Permission denied
Is the server running on host "123.456.0.789" and accepting TCP/IP connections on port 5432?
Here are what I've done.
On postgresql.conf set listen_address = "*" -- this is OK
Added pg_hba entries for both -- this is OK (python and terminal can connect on both)
Port 5432/tcp is both enabled and allowed -- this is OK
Selinux is disabled -- this is the answers for the thread referenced above, but it doesn't work for me even after reboot of course.
these are the result of my netstat
#netstat -na | grep 5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp6 0 0 :::5432 :::* LISTEN
tcp6 0 94 ::1:55110 ::1:5432 ESTABLISHED
tcp6 0 0 ::1:5432 ::1:55060 ESTABLISHED
tcp6 0 0 ::1:5432 ::1:55110 ESTABLISHED
tcp6 12 0 ::1:5432 ::1:55108 ESTABLISHED
tcp6 0 12 ::1:55108 ::1:5432 ESTABLISHED
tcp6 0 0 ::1:55060 ::1:5432 ESTABLISHED
unix 2 [ ACC ] STREAM LISTENING 31102 /var/run/postgresql/.s.PGSQL.5432
unix 2 [ ACC ] STREAM LISTENING 31104 /tmp/.s.PGSQL.5432
iptables
#iptables-save | grep 5432
-A IN_public_allow -p tcp -m tcp --dport 5432 -m conntrack --ctstate NEW,UNTRACKED -j ACCEPT
getenforce
#getenforce
Disabled
Selinux
#/usr/sbin/sestatus | grep SELinux
SELinux status: disabled
#sudo setsebool -P httpd_can_network_connect_db 1
setsebool: SELinux is disabled.
postgresql.conf
listen_addresses = '*'
port = 5432
pg_hba.conf (i just changed the ip for posting here) I tried using trust, but its still the same
# "local" is for Unix domain socket connections only
local all all password
# IPv4 local connections:
host all all 127.0.0.1/32 password
host all all 123.456.0.1/32 password
host all all 123.456.0.11/32 password
host all all 123.456.0.20/32 password
# IPv6 local connections:
host all all ::1/128 password
edit start: My PHP pg_connect code (I just changed the IP just for this post, but it points to the VPS IP)
$pgcon = pg_connect("dbname=database1 user=some_user password=some_password host=123.456.0.789");
edit end : ==
I would like to emphasize that BOTH servers can connect on each others and their own PostgreSQL database through other means, with the exception of my Local Server, it couldn't connect to VPS PostgreSQL using PHP.
VPS To Self(localhost connection)
VPS to Self via PHP is OK
VPS to Self via Python is OK
VPS to Self via PSQL(Terminal) is OK
VPS To Local Server(Connecting using Local Server's VPN IP)
VPS to Local Server via PHP is OK
VPS to Local Server via Python is OK
VPS to Local Server via PSQL(Terminal) is OK
Local Server to Self(localhost connection)
Local Server to Self via PHP is OK
Local Server to Self via Python is OK
Local Server to Self via PSQL(Terminal) is OK
Local Server to VPS(Connecting using VPS's IP by VPN and Public IP)
Local Server to VPS via Python is OK
Local Server to VPS via PSQL(Terminal) is OK
Local Server to VPS via PHP Is NOT OK
I'm really sorry for the long thread, I wanted to give as much information as I can.
Let's split error by types. I'd made several tests with your case and what I found:
If we mess with connection parameters (i.e. wrong port, or IP address) we get the error "could not connect to server: Connection refused" or "Operation timed out
Is the server running on host "128.0.0.1" and accepting")
If we mess with credentials, we get the error "FATAL: password authentication failed for user ..."
Permission denied can be thrown only if you have not permissions to open a TCP connection from your PHP library.
Pls, double-check if you disable SElinux on your Local Server as for me, this is still the closest workaround for your problem.
My vps system verion is Ubuntu 16.04.1 x64.
Mysql version is 5.5.48
I have tried various methods to support 3306.
I have updated "etc/my.cnf" file to commented "'skip-networking" and have the "bind-address" to be 0.0.0.0;
and I use "netstat -an | grep 3306" to check the port status, I got the result:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:35498 127.0.0.1:3306 TIME_WAIT
I had shut down my firewall, when I type "ufw status", I got:
Status: Inactive
But after all the step and reboot my vps, I type "telnet 128.XXX.XXX.27 3306" on other vps, I got:
telnet: connect to address 128.XXX.XXX.27: Operation timed out
But the strange thing is when I type "telnet localhost 3306" on the local vps, it works fine.
So What could be possible problems? I could provide more details you want.
Thanks a lot!
I solved it.
It was a problem with the firewall.
Although I turned off the firewall, but the rule of the iptables are still affect all network requests, and use "iptables -L", I found that:
DROP tcp -- anywhere anywhere tcp dpt:mysql
The beginning is "DROP", and the end is "mysql".
After I removed this line, everything is fine.
I am trying to connect to my Amazon EC2 website from my PHP server hosted on Godaddy. So using HTTP_Request2, I use the following:
$request = new HTTP_Request2('http://XX.XX.XXX.XXX:3007/something/something', HTTP_Request2::METHOD_GET);
This returns the following:
Error: Unable to connect to tcp://XX.XX.XXX.XXX:3007. Error: Connection refused
Now I know the port on my Amazon server is open and works when using jQuery to connect to it from my own machine or even my Godaddy website. However when trying to do the same thing except with PHP, it isn't working. I have made sure that I have installed request2 package on my Godaddy server.
Found out the problem. The problem is GoDaddy doesn't allow using custom ports (such as 3007 port I was trying to use) with curl or request2. A workaround to use on another server you are trying to connect to (if you manage/own that server):
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
was posted at https://stackoverflow.com/a/16573737/4553140
I have setup my wercker.yml file with the following step midway:
- script:
name: Serve application
code: php -S localhost:8000 >> /dev/null &
That appears to run, however, in another step when I try cURL to http://localhost:8000 I get the following:
curl: (7) Failed to connect to localhost port 8000: Connection refused
It does it for all ports, not just 8000. Has anyone else managed to get PHP's in built server working in wercker, or open any ports?
Assuming you're using the wercker CLI and trying to set up a development pipeline, you need to use wercker dev with the --publish 8000 argument. This will forward the traffic from your host on port 8000 to the container on port 8000.
Also, if you're using boot2docker, you can't specify localhost, since boot2docker spins up a VM that runs docker. In that case you'll need to use your boot2docker IP, which you can find by running the boot2docker ip command.
I have installed Sphinx on my server and everything seems to working, except that when I run the test.php from web browser, I am getting this error:
Query failed: connection to localhost:9312 failed (errno=111, msg=Connection refused).
I have searched online, including stack overflow, almost all suggestions were make sure the searchd service is running, and it's listening on the right port. I can say yes to both questions because if run the same test program directly in command line, everything works. I understand that the hosting provider may not have opened the port, but the port should be listening with the server, right? The fact that it works under command line should confirm that the service is listening on that port and the php program is able to get through to it. So I don't understand why the same program run from the web browser rejects the connection.
I have also enabled fsockopen in php.ini.
Any suggestion to help understand why the connection is rejected or even better how to solve it is very welcome!
Thanks
You can try this:
check your sphinx.conf and make sure that 9312 is your spinx's port (my default port was 3312)
change localhost to 127.0.0.1
If this doesn't work for you check if port is open, you can do it with nmap
sudo apt-get install nmap
nmap 127.0.0.1 -p 9312