caché
I have a Laravel application already mounted on Google Cloud, the needs of the project forced me to use redis
. Everything works fine on my local machine but when I push changes to make it work in production but I get the errorConnection timed out [tcp://ip_redis:6379]
My settings in yaml
which is like env
but for Google Cloud:
REDIS_CLIENT: predis
REDIS_HOST: ip_redis
REDIS_PASSWORD: null
REDIS_PORT: 6379
I have created the server redis
in Google Cloud too, with the following characteristics:
Nivel
Básico
Ubicación
us-central1-a
Red autorizada
default (my_project)
Rango de direcciones IP
rango_ip/29
And when initializing the command configuration gcloud init
I made sure to configure it in the same zone as the redis server ( us-central1-a
) and I deployed the application.
I kept getting the same error.
So I did some more research and went in Redes de VPC > Firewall
and created two rules to see if that was what was wrong.
The configuration of the first rule was (note that I put the same range that the server gave redis
):
The second rule is identical except for traffic type, now I set it to outgoing traffic.
I even created a VM to test the connection using telnet
and yes I have an answer, yes the server works correctly redis
.
Also, I have implemented CloudFlare
what made me think that I could probably be blocking it somehow, but I added an exception rule with the server IP ( ip_redis
) to allow the connection, but it did not work, apparently CloudFlare
it does not influence this connection.
Also, I saw this answer , about modifying the part of post-install-cmd
the file composer.json
, but my file didn't have that part, I decided to add it to the scripts
anyway, it didn't work either. mark the same error
But still after all this I haven't been able to get the Laravel app to connect to the redis server.
What was needed was a special connector, which is created in VPC Network > Serverless VPC Access.
And click on create connector:
With special care in setting the region, to make it match the region of your application.
On the network, default.
In the IP range, we can put the hint below.
It is also very important to activate the option
AUTH
for the serverRedis
, otherwise authentication errors will appear. Once the option is activated, you have to copy theString AUTH
one that Google Cloud gives you when you see the details of your serverRedis
. We paste that stringyaml
into the variableREDIS_PASSWORD
.Now, we must color a setting the
yaml
to dodeploy
:Now it only remains to run the command to do
deploy
:It must be used
beta
since sometimes the normal command can ignore the section ofvpc_access_connector
.And ready.