I just started learning Redis and do not know how to change the database user. I added a user named redis while installing the redis. Here are few questions.
How can I add a new user and set the password for that?
How can I choose his user for connecting the database?
Redis config file:
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
Laravel config file:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' =>0,
],
],
There's no such facility. Any one connect to Redis can send command to it. So never expose Redis to untrusted clients.
In order to make it safer, you can set a password for Redis (check the requirepass directive in redis.conf). Then the client has to use the AUTH command to do the authentication.
UPDATE
Since Redis 6.0, it supports Redis ACL. With this feature, you can set multiple users with different password on different key spaces. Check the doc for detail.
Related
I am new to networking, Docker and Laravel.
I want to get and read a files placed on a remote host into a Laravel App running in Docker Container.
I want to achieve this using port forwarding.
What is the best way to support this?
The general approach would be to use ssh agent to resolve this, but since my team has asked me to use port forwarding to achieve this, I am not sure how to go about it.
png file of the image
I have tried the following
console
>>> Storage::disk('sftp')->readStream('/home/remote_your_username/test.csv');
League\Flysystem\PhpseclibV3\UnableToConnectToSftpHost with message 'Unable to connect to host: 172.21.166.54'
another console
ssh -N -L 4000:127.0.0.1:22 remote_your_username#192.0.0.1
config/filesystems.php
'sftp' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
'username' => env('SFTP_USERNAME'),
'privateKey' => env('SFTP_PRIVATE_KEY'),
'passphrase' => env('SFTP_PASSPHRASE'),
'port' => env('SFTP_PORT', 22),
],
.env
SFTP_HOST=172.0.0.1
SFTP_USERNAME=your_username
SFTP_PRIVATE_KEY=/home/your_username/.ssh/id_rsa
SFTP_PASSPHRASE=your_passphrase
SFTP_PORT=4000
I have a CentOS 7 server running lampp, with domain name xxx.example.com. I have successfully config the SSL certificate for https://xxx.example.com.
For email notification purpose, I need to send some emails. My smtp server's domain is smtp.example.com. I could send email in my local environment (Windows 10, xampp) with SSL activated. But when I deploy the site on CentOS, it can't send email with SSL option activated. I have to bypass the SSL verification part to send the email:
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
So, how should I set up my CentOS environment to send email with SSL correctly?
I have been checking out a lot of answers here and on GitHub regarding this issue, but whatever I try there is always something wrong. I also donĀ“t get why with the same credentials sometimes I am able to connect other times I am not even able to do that.
So right now I get the following error:
"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed:
nodename nor servname provided, or not known
and I am not able to connect:
My .env credentials:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
My database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'unix_socket' => env('DB_SOCKET'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
...and for the standard connection, I use 192.168.10.10 for the host.
I think your issue is with the DB_HOST parameter. I included a full explanation. Your fix is likely part of the final paragraph!
Laravel ships with a .env.example configured to connect to the Homestead MySQL out of the box. Assuming you are running everything in Homestead, and Homestead is configured properly, you should be able to use the following database configuration to connect successfully.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
If you are trying to connect to the Homestead database from outside of Homestead, the Laravel documentation describes how you can do that as well. You can check that out here.
Essentially what you need to do is connect to 127.0.0.1 as a host but use a different port (as opposed to 3306.) For MySQL, Homestead exposes a port 33060 that you should try to connect to instead. For Sequel Pro this should fix your issue!
Updated October 2020
If you are using MySql 8 there are some issues with that.
I was also not able to connect with the Laravel Homestead DB.
I solved the problem installing Sequel Ace, the successor of SequelPro which is available also on Mac AppStore.
https://github.com/Sequel-Ace/Sequel-Ace
Here a post from the SequelPro issues about:
https://github.com/sequelpro/sequelpro/issues/3705
I am trying to connect, Local Laravel application to GCP mysql instance. I am just trying to use mysql instance for local development and do not want to upload this on App Engine.
Steps follow:
1. Added IP to Authorized networks in mysql instance
2. updated .env file (refer below)
3. Able to connect to db instance with gcloud sql connect -u=root and access database.
4. Tried configuring config/database.php file
5. Used instance IP for connection instead of localhost
6. used DB_SOCKET : /cloudsql/:asia-northeast1:
.env file
APP_NAME=Laravel
APP_ENV=local
APP_KEY=<app-key>
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=<instance-ip>
DB_PORT=3306
DB_DATABASE=<db-name>
DB_USERNAME=root
DB_PASSWORD=*********
DB_SOCKET=/cloudsql/<project-id>:asia-northeast1:<db-name>
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', <instance-ip>),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', <db-name>),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', *********),
'unix_socket' => env('DB_SOCKET', '/cloudsql/<project-id>:asia-northeast1:<db-name>'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
I have another cakephp 2.0 project which runs locally with no problem.
Thanks in advance
Without knowing what error you actually get it's a bit difficult to know why it doesn't connect. If you can post the actual error you're getting that may tell us why the connection fails.
That being said, you may want to connect using the Cloud SQL proxy instead. There's a quickstart available that takes less than 5 minutes to set up the connection for local testing.
While connecting from Compute Engine your don't need DB_SOCKET. I successfully connected using below DB creds inside laravel's .env.
DB_CONNECTION=mysql
DB_HOST=<Mysql instance IP from Google SQL mentioned under "Connect to this instance">
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD="db_user_pass"
I have an app built on app.mydomain.com (Server 1) and a support ticketing system at support.mydomain.com (server 2). How can I establish a connection between both databases in my laravel app? Both are using Laravel Forge and Digital Ocean.
I read this post on SO which looked great but I am getting a "connection timed out error". I believe it has to do with Forge needing the SSH key file (id_rsa.pub) when connecting to a database? Source here
I tried adding this to database.php:
//Server/Site 1
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'support',
'username' => 'user',
'password' => 'mysecretpassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
//Server/Site 2
'mysql2' => array(
'driver' => 'mysql',
'host' => '123.456.789.101',
'port' => '3306',
'database' => 'app',
'username' => 'forge',
'password' => 'mysecretpassword',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
),
And then adding this to my model:
protected $connection = 'mysql2';
When you provision your server with Forge, MySQL configuration restricts external connections for security reasons. Only application at the same server can access your database.
New answer
Since you're using forge it's even easier than I suggested before. If you provisioned both your servers with forge, go to forge -> networking -> server network and select can connect to checkbox and hit update.
Afterwards you need to update DB_HOST= of mysql2 connection with private network IP obtained from digitalocean.
Old answer - manual setup
Now, there are couple of things to be done in order to allow external connections in secure way:
At site2 - edit /etc/mysql/my.cnf and udpate bind-address with your server IP
Since you are using digital ocean, if your servers are in the same datacenter you should be able to use private network ip address of your droplet. This is more secure solution, any connection between servers will not leave datacenter infrastructure. Remember to restart mysql.
At site2 - add new firewall rule
Go to Forge -> Networking -> New Firewall Rule and add a new rule for port 3306 and IP address of your site1, again a private IP if possible.
At site1 - create mysql user for remote connections
Connect with ssh to site1 open mysql console and add new user
CREATE USER 'some-username'#'site1_ip' IDENTIFIED BY 'some_password';
GRANT ALL PRIVILEGES on your_database.* TO 'some-username'#'site1_ip';
FLUSH PRIVILEGES;
For more info refer to this tutorial, it solves similar issue to yours https://www.digitalocean.com/community/tutorials/how-to-set-up-a-remote-database-to-optimize-site-performance-with-mysql
Hope this helps!