Email verification link using localhost in a production environment - laravel

I have a Laravel 6.7.0 app deployed on AWS Elastic Beanstalk.
The environment variables are set using Elastic Beanstalk config files (not .env file).
I have set the env variables to production including the APP_URL. The env('APP_URL') and the config('app.url') are returning the correct value (which is my live domain name) except for the email verification link which is returning localhost. The APP_URL is working fine in all other emails including the password reset email.
I tried cache:clear and config:clear on the server but still no luck. Any ideas on how to debug this?

I guess you should run
php artisan queue:restart
if you are running queues for sending e-mails

Your Email verification link display local host on production because url is wrong change url to {{url('/verificationlink')}}

Related

Laravel route returns localhost despite I changed the env variable

I have APP_URL env variable set to domainname.com and I have url set to the same domain in config file as well. route('route.name') in artisan tinker returns the proper domain. yet when used in the applicaiton code, it returns localhost. Any thoughts from you would be appreciated.
Edit: My environment is Github codespaces
Try running php artisan optimize:clear command to clear cache,
routes etc all in one go.
If you have separate frontend then change it there as well to hit the
right backend with your provided domain name.
Restart your docker containers if you are using Docker.

Install laravel passport in laravel vapor environment

Installing Passport worked for the local environment of Laravel Vapor. But after deploying it to production an error occured:
After searching the error message it seems that we need to run php artisan passport:install like mentioned here.
How can we do that with Laravel Vapor? Is there a way to get access to the server via ssh?
Vapor doesn't have a permanent filesystem; each HTTP request hits a new Lambda instance.
The docs have some info on deploying Passport keys. On Vapor, your best bet is going to be using Vapor's "secrets" system to put them into the environment, then doing:
php artisan vendor:publish --tag=passport-config
which will then provide the option to load the encryption keys from your environment variables:
You'll want to name your secrets PASSPORT_PRIVATE_KEY and PASSPORT_PUBLIC_KEY in Vapor.

Laravel on AWS: APP_DEBUG not respected

I initially deployed my Laravel app with APP_DEBUG set to true, but now we're in production I don't want it to whoops! every time there's an error.
I've changed the contents of our EB .config file so that APP_DEBUG: false and I can see the change in Elastic Beanstalk's environment properties:
But Laravel itself is still dumping everything to the screen when there's an error.
I've tried ssh-ing into our server and running php artisan config:clear to see if it was that, but it still didn't work.
I don't understand why Laravel isn't respecting the updated configuration on deployment. Can anyone explain the logic here?
Update: I updated the security settings on the instance and noticed that it was giving our custom error screen. Can anyone explain what happened? Was restarting the server after running php artisan config:clear what did it?
I had issues like this before where I changed something in the console's environment properties which did not correspont with what I got using tinker. You can find the env file on your instance here:
/opt/elasticbeanstalk/deployment/env
if you open the file you see that variables set in .env are not quoted so if you have a password with for example a hashtag or a name with spaces it can result in unintended problems.
I would suggest to stop using environment variables via .yaml config files and start deploying your .env to the elastic beanstalk S3 bucket and fetching it on deployment. This will result in you having more control over the content of the file.
Example of this can be found here:
https://github.com/rennokki/laravel-aws-eb/blob/master/.ebextensions/00_copy_env_file.config

Mailhog Setup in Laravel 6.x

Using Laravel 6.0, I have configured my .env file to utilize Mailhog in my local environment as explained in the Docs.
MAIL_DRIVER=smtp
MAIL_HOST=0.0.0.0
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
I can go to http://localhost:8025 and see the Mailhog interface.
However, when I try to send an email either through a controller method or on my local file system via php artisan tinker, no mail gets through.
The only time mail does get through to Mailhog is if I vagrant ssh and run php artisan tinker from inside of there.
This is all I'm trying to send: Mail::raw('FROM HOME CONTROLLER', function ($message){ $message->to('contact#contact.com');});
I have tried using MAIL_HOST=localhost, 127.0.0.1, 192.168.10.10. I've tried different user/pass combos (testuser, password, testpass, etc), to no avail.
The reason it was not going through was a simple route misconfiguration (accessing the wrong route in my web.php router file).
Still unable to get it working via php artisan tinker locally though, which I would imagine has to do with PHP mail not actually being present without being inside of the vagrant instance.

Lumen not working out of the box

Just installed Lumen framework.
hit the link http://localhost/lumen/public/ in my browser and got this following error, anyone got any idea about it?
Traced it back to the app.php file in bootstrap folder.
if You want to access lumen project without "php artisan serve"
$app->run(); replace with
$request = Illuminate\Http\Request::capture();
$app->run($request);
from this path yourlumenproject/public/index.php
Open your terminal in the root folder run the following command php artisan serve.
Lumen development server started on http://localhost:8000/
if you want to serve your app in local development you can do this :
php -S localhost:8000 -t public/
and it will serve in localhost in port 8000. hope this help.
Note : I'm using Laravel Framework version Lumen (5.2.4) (Laravel Components 5.2.*)
At the moment Lumen only runs in the domain root.
(I've submitted a PR that fixes this but it has yet to be merged)
You have to create a Virtual Host on your local webserver and point the document root of that to the public directory. After that you can access your app with something like: http://lumen.dev.
Guide for Virtual Hosts with nginx
Guide for Virtual Hosts with Apache
A simple alternative to setting this up manually is Laravel Homestead. It is an official Vagrant box made for Laravel, that allows you to easily get your development environment up and running.

Resources