laravel deployment failed on heroku - laravel

Some months ago I succeeded in deploying a Laravel 5.5 application on Heroku.
I tried to do the same today with a Laravel 6.12 application, and I have a lot of problems. I added the .env vars, I added the Procfile. But I have this error:
Did something change between Laravel 5.5 and 6 for deploying to Heroku? How can I get this working?
My post-install-cmd is:
"post-install-cmd": [
"php artisan cache:clear",
"php artisan config:cache",
"chmod -R 777 storage",
"php artisan passport:keys"
]

You're using the default file session driver, but this isn't a good fit on Heroku. Its filesystem is ephemeral and local to each dyno.
Try using a different session driver by setting the SESSION_DRIVER environment variable:
heroku config:set SESSION_DRIVER=cookie
cookie is probably simplest, but memcached or redis would work well too if you have either of those set up.
The default session driver didn't change between Laravel 5.5 and 6, but I wouldn't recommend using file with Laravel 5.5 on Heroku either.

Related

APP_URL not refreshing after a change

I'm building a Laravel 9 app using Docker.
I'm just starting, so I merely updated the APP_URL variable in the .env (from "http://localhost" to "http://mydomain.local").
After this, I ran the following commands:
php artisan cache:clear
php artisan config:clear
php artisan route:clear
composer dump-autoload
and I restarted the Docker container of the app.
Yet, when I access http://mydomain.local in my browser, the app doesn't load. It still loads properly when I user http://localhost as originally configured.
What am I missing?
This is because you probably didnt edit the vhost..
Just changing the APP_URL in the .env file doesnt change how the browser resolves a domain name.
See this thread to learn how to edit a vhost file: WAMP Server virtual hosts configuration

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.

Problem with executing laravel migrations on Elastic Beanstalk

I deployed my laravel application using Elastic beanstalk, and I need to execute php artisan:migrate command on the remote database.
Based on Maximilian's tutorial I created init.config file inside .ebextensions with contents:
container_commands:
01initdb:
command: "php artisan migrate"
The status of the deployment is Healthy, but it didn't create any table!
any clues, please?
run php artisan config:cache then run migrate command
As you did not include any relevant logs. I am guessing you need to run your migration within the staging folder.
An example of how you can run migrations:
04_run_migrations:
command: "php artisan migrate --force"
cwd: "/var/app/staging"
leader_only: true
--force is needed cause php artisan migrate asks you if you are sure to run it on a production environment
leader_only is needed if you use horizontal scaling.
Source:
https://github.com/rennokki/laravel-aws-eb/blob/master/.ebextensions/01_deploy.config

Laravel-Php artisan serve url (127.0.0.1:8000) vs localhost/laravelproject/public

I want to access my laravel project.I run php artisan serve and access the 127.0.0.1:8000 in browser.
But i learned that I can also check my project using the localhost/laravelproject/public url whithout running php artisan serve.
Question: What is the point of using php artisan serve?
No point in two different methods like you mentioned run laravel by "php artisan serve" and by "project url" followed by localhost. But advantage of "php artisan serve" is you can run you laravel project without putting in htdocs/www directory i.e servers root directory. You can put laravel project anywhere where you want and run through the artisan command.
I found some information you may find interesting:
https://www.quora.com/How-can-I-use-php-artisan-serve
But in simple words, php artisan serve is an easy way to create a php server and that is what laravel needs to run.
You could do the same with "php -S 8080 (which would start a php web server (single threaded) in the current directory on port 8080)"
Also if you have already a php server running with apache or nginx it would not be necessary any of the commands.
Hope you find this helpful.
The `Serve command is just a shortcut for the PHP Builtin Webserver, something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). But if you already have Nginx installed, there is no point at all, just use it.
It's not wise to use the Builtin Webserver in production.

Laravel Forge, suddenly env is empty

I've deployed a Laravel app on Digitalocean using Laravel Forge. Site runs fine for a day or two, then suddenly the .env file gets wiped, all variables deleted and file is 0 bytes.
php artisan env returns
Current application environment: production
But the file itself is empty. Owner is forge and chmod is 755
I've tried running php artisan config:cache but from time to time the .env file suddenly is completely blank, turning my app to become unavailable of course.
Digitalocean runs nginx.
Does anybody know what could be wrong?

Resources