How to securely connect to Azure Cache for Redis from Laravel - laravel

Azure Cache for Redis provides secure port for connecting over TLS.
How to setup Laravel Redis config for connecting securely?

Use 6380 port and add tls:// to host.
.env file:
CACHE_DRIVER=redis
REDIS_HOST=tls://RESOURCE_NAME.redis.cache.windows.net
REDIS_PASSWORD=password
REDIS_PORT=6380

Related

Laravel: connecting the AWS ElasticCache Redis is timing out

I am working on a Laravel application. I using Redis and I am using AWS ElasticCache service for that. I am trying to connect to the Redis from my Laravel application. But it is timing out. This is what I have done.
I installed the Predis library by running the following command.
composer require predis/predis
Then I created a Redis instance in the ElastiCache service console enabling AUTH setting my password token.
Then I set the variables in the .env files.
CACHE_DRIVER=redis
REDIS_CLIENT=predis
REDIS_HOST=master.laravelredistest.8sm3xo.euw1.cache.amazonaws.com
REDIS_PASSWORD=mypassword
REDIS_PORT=6379
When I run the code to connect to the Redis, I got the following error.
Operation timed out [tcp://master.laravelredistest.8sm3xo.euw1.cache.amazonaws.com:6379]
What is missing with my configuration and how can I fix it?
I also updated the security group of Redis to allow the EC2 instance's security group in the inbound rules as follows:
I am getting this error this time:
I edited the SG of Redis to add the following inbound rule too.
The security groups are in the same VPC too as you can see in the screenshot:
This sounds like a security group issue causing the timeout.
Elasticache clusters are always private so if you're using a public ip address, this will need to be updated to be the private ip address range of your instance/subnet/VPC.
An Elasticache cluster is a resource in your VPC, therefore network transit needs to be allowed for the cluster to be accessible.
More information is available in the Accessing Your Cluster page.
Additional Configuration
This is the issue. I also needed to delete the existing Redis instance and create another one without AUTH token enabled.

Connect local Laravel environment to Google Cloud SQL - MySQL

I try to connect my Laravel project into my local development environment to Google Cloud SQL (MySQL).
For this, I connected from my OSX Terminal with the Cloud SQL-Proxyclient to the remote database with port 3307.
I can connect with my MySQL Workbench to the remote database, and I can see/change tables, ...
Into my Laravel project into .env I changed the settings:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
DB_DATABASE=mydatabasename
DB_USERNAME=mydatabaseusername
DB_PASSWORD=mydatabasepassword
When I open my project into the browser, into terminal I can't see, that something tries to use the connection.
Into the browser I get an error message:
SQLSTATE[HY000] [2002] No such file or directory (2002)
I think, the project can't connect to the remote database
How can I solve this problem?
Thanks for help!
While the Cloud SQL Proxy connects to your database on port 3307, you want to connect to the Cloud SQL proxy on port 3306 (this is the default mysql port). You can also specify a custom port by updating the instances argument:
./cloud_sql_proxy -instances=my-project:us-central1:sql-inst=tcp:3306 &
I added now the public IP address of the server, and I added my local IP address to allowed IP adresses for the MySQL server. Now it works.
Make sure you have config for right DB_HOST. Let get an IPv4 Read this for more informations:
https://cloud.google.com/sql/docs/mysql/connect-external-app#appaccessIP

Connect Google Cloud Postgres From Shared Hosting

I just created a google cloud postgres with very basic authorization by whitelist the ip.
Google Cloud Auhtorization
I successfully connected to the google cloud postgres (35.240.xx.xx) from my home (139.193.xx.xx) using pgadmin and successfully created tables and inserted initial ddl.
pgadmin
When I want to use it in the shared hosting (119.81.xx.xx) that hosts laravel php application, I changed it in the .env file as below.
DB_CONNECTION=pgsql
DB_HOST=35.240.xx.xx
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=[google cloud password here]
But it didn't connect when I run the website with laravel.log as below.
[2018-07-12] ERROR: SQLSTATE[08006] [7] could not connect to server:
Connection refused Is the server running on host "35.240.xx.xx" and
accepting TCP/IP connections on port 5432? {"exception":"[object]
(PDOException(code: 7): SQLSTATE[08006] [7] could not connect to
server: Connection refused
Can anyone help me? Thanks.
It turns out that the shared hosting needs to also whitelist google cloud external ip address. It's working now.

Is it possible to use a proxy server in redis-cli?

From time to time I have to use a proxy server to get access to every web page. Is their a way to tell the redis client (redis-cli) to not use the normal connection but to use a proxy?
Or are there any other clients, which allow a proxy?
You can create a SSH tunnel between your machine and the one hosting the Redis server:
ssh -L 6379:localhost:6379 user#remotehostname
(6379 is the default port for Redis)
You can also use Redis Desktop Manager or Fastoredis, they support SSH tunneling too.
Alternatively, if you do not have the posibility to open an ssh tunnel, you could install Webdis on the same host than Redis and command Redis from you web browser.

Connecting to server behind VPN with Heroku and Ruby

I'm writing an application in Ruby/RoR that will be hosted on Heroku.
One of its requirements is that it connects to an (Active Directory) authentication server which is behind a Sonicwall VPN.
How can I establish this VPN authentication using Ruby to access this server?
Heroku is just a service built on top of EC2 that manages deployment using a linux env. You don't have root access on on which means you can connect out to any service using any TCP protocol. But you can only listen for HTTP connections. Unfortunately this rules out setting up VPNs and SSH tunnels. You can do this on Amazon EC2.

Resources