Enable a CentOS 7(LAMPP & Laravel) server send email via SSL - laravel

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?

Related

Loading files placed on remote hosts in Docker Container using port forwarding

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

Problem with SMTP on my VPS with Laravel 9

I have a problem with SMTP on my Virtual Private Server with Laravel 9.
Here is an error message:
Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed"
And my SMTP settings on .env file:
MAIL_MAILER=smtp
MAIL_HOST=smtp.i4ware.fi
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=noreply#i4ware.fi
MAIL_FROM_NAME="${APP_NAME}"
What it the problem. Can anyone help me?
I have Ubuntu Server 20.04 LTS.
You can use cerbot to get ssl certification
https://www.inmotionhosting.com/support/website/ssl/lets-encrypt-ssl-ubuntu-with-certbot/
Or you can diable ssl verification
Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint such as Gmail, and you'll be vulnerable to a Man-in-the-Middle Attack.
Be sure you fully understand the security issues before using this as a solution.
You can add below code in /config/mail.php
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],

Rocket port override from environment variable not working in Windows

I'm trying to run a rocket-rs application while overriding the port configuration using environment variables as described in the documentation.
I've set the variable ROCKET_PORT:
setx ROCKET_PORT 4444
I've checked it was set with an echo. When I run the application (with either cargo run or ./application.exe) it still uses port 8000:
🔧 Configured for development.
=> address: localhost
=> port: 8000
=> log: normal
=> workers: 16
=> secret key: generated
=> limits: forms = 32KiB
=> tls: disabled
🛰 Mounting '/':
=> GET /mine
=> POST /transactions/new application/json
=> GET /chain
=> GET /nodes/resolve
=> POST /nodes/register application/json
🚀 Rocket has launched from http://localhost:8000
I know the port can be configured in Rocket.toml, but the idea is to be able to run in a different port for each console session by setting the environment variable.
Why would this not be working?
Setting the variable like this did the trick:
$Env:ROCKET_PORT=4444

Laravel Forge how to establish connection between 2 databases on 2 separate servers

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!

Expected response code 220 but got code "500" when sending mail in Laravel 5.4 in local environment

I'm migrating a Laravel 5.0 app to 5.4 and am trying to test the mail in my local environment. I've always used Anitix SMTP Imposter for this. Here's what my mail configuration looks like in my .env:
MAIL_DRIVER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPT=null
This has always worked in all previous versions of Laravel (4, 4.2, 5.0), but suddenly with 5.4 I'm getting the following error:
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 220 but got code "500", with message "500 Command not recognized
"
I've tried disabling Avast, using alternative programs like Papercut, playing with the config by using SSL or TLS, but I can't figure out what's causing this. Any ideas?
Late answer, but I came here myself running into the same issue.
MailHog does not support TLS encryption. Adding MAIL_ENCRYPTION=null to my .env file fixed my issue.
First try: php artisan config:cache and restart your local server, perhaps Laravel use the old mail data.
For development purpose https://mailtrap.io/ provides you with all the settings that needs to be added in .env file. Eg:
Host: mailtrap.io
Port: 25 or 465 or 2525
Username: cb1d1475bc6cce
Password: 7a330479c15f99
Auth: PLAIN, LOGIN and CRAM-MD5
TLS: Optional
Otherwise for implementation purpose you can get the smtp credentials to be added in .env file from the mail (like gmail n all)
After addition make sure to restart the server
You can use https://mailtrap.io/
it will provide you all necessary details for you to check mail functions in your local machine including username,password,port,host,etc.
if still have same issue issue,
use these details in config/mail.php file in your project instead of using .env file.
return array(
"driver" => "smtp",
"host" => "mailtrap.io",
"port" => 2525,
"username" => "mailtrap.io_your_username",
"password" => "mailtrap.io_your_password",
"sendmail" => "/usr/sbin/sendmail -bs",
"pretend" => false
);
it is work for me.
MAIL_DRIVER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
I am use a mailhog docker container.
mailhog:
image: mailhog/mailhog:v1.0.0
ports:
- "1025:1025" // smtp
- "8025:8025" // web

Resources