Laravel 8 Heroku 404 on Apache - heroku

I created a new Laravel 8 project to test on Heroku; I set the procfile as the manual.
https://devcenter.heroku.com/articles/getting-started-with-laravel
To use Apache, I set the Procfile
web: vendor/bin/heroku-php-apache2 public/
The welcome page shows the following.
404 | not found

I don't know why but in laravel 8 if either one of these is missing from your Config Vars on heroku you will get that error.
There are two solution I found for this.
Set APP_URL to the heroku url or set your APP_ENV to local.

The problem rely on config vars, basically this config vars bellow has to be set.
APP_DEBUG : true
APP_ENV : production
APP_KEY : "your app key"
APP_NAME : Laravel
APP_URL : "the url of your application"

Related

Laravel Project is Serving without .env file

If .env is removed on my Laravel project the command
$ php artisan key:generate
Causes this error
ErrorException : file_get_contents(/folder/projectlocation/.env): failed to open stream: No such file or directory at //folder/projectlocation/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96
{
file_put_contents(
$this->laravel->environmentFilePath(),
preg_replace(
$this->keyReplacementPattern(),
'APP_KEY='.$key,
file_get_contents($this->laravel->environmentFilePath())
));
}
However the php artisan serve command works "Laravel development server started: <http://127.0.0.1:8000>"
I have cleared all the Laravel caches. Why will it serve but not fetch the .env file configuration?
That is correct. All application config comes from the config files in the config/ folder. Each of the options in here is configured to take either the value from the .env file or a default value.
For example, the application key in the config/app.php file:
'key' => env('APP_KEY'),
So when no value is set for APP_KEY in .env, the application key will be null (not recommended!).

How to issue 500 Internal Server Error after true debug in laravel?

I create project with Laravel 5.2, After true debug in .env, show 500 Internal Server Error in localhost:8000 ! and after false debug in .env dont't show any error in localhost:8000.
How to issue this problem?
Type the command php --ini
Open the first file in the list with the name of php.ini
search for ;display_errors = Off and change it to display_errors = On
Then the blank 500 page should now contain text detailing the issue.

How to setup Lumen in Travis CI

I have been trying to setup a Lumen application in Travis CI and i have found the following problem:
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Dotenv: Environment file .env not found or not readable.
Given that this is triggered on phpunit execution i'm trying to load my environment variables from my phpunit.xml instead of a .env file but i don't know how to make it work
Any ideas?
Your .env file should not be checked into source control and as such you dont want to use it to run builds and on production. Therefore take advantage of using Travis CI to set env variables. Refer to https://docs.travis-ci.com/user/environment-variables/.
Dotenv was developed to be used on development environments only. It always expects .env to exist and will throw an error if it doesn't.
One workaround is to check for .env and only then load Dotenv. Here's a sample piece of code that you can use.
$dotenv_var = new Dotenv\Dotenv(__DIR__);
if(file_exists(".env")) {
$dotenv_var->load();
}
You can read up more on this issue here.

Laravel TypiCMS redirects to root

I am using TypiCMS Laravel here : github.com/TypiCMS/Base and I am facing the following problem:
I created a new module named "News" by executing command: composer require typicms/news. I also added providers in config/app.php, have publish views and migrations and migrated the database too.
The only problem I am facing is that whenever the url I given, it redirects me to the root directory of my project, that is, http://localhost/mywebsite/public/
Even, if I give invalid route like localhost/mywebsite/public/foobar, instead of showing me error, it again redirects to the root directory.
I have checked the .htaccess and routes.php file and there is not modifications.
Regards:
Adnan
TypiCMS cannot be installed in a subfolder, the root of your site must be http://localhost.

Laravel subdomain config

Our staging environment on a project uses the same domain AKA staging.mydomain.com. How do I get the Laravel database config to point to a different DB as the config switch is based on the hostname which is the same for staging. and www.?
You can update the detectEnvironment method to use a closure function and run your login in there to determine if your application is local or not.
update bootstrap/start.php like this:
$env = $app->detectEnvironment(function() {
return preg_match('/staging/', $_SERVER['HTTP_HOST']) ? 'staging' : 'production';
});
Now when you are visiting your laravel project from http://staging.xxx URL, it will detect it as staging environment.
Now, you can place the database config specific to staging env in here:
app/config/staging/database.php
This should do the trick.

Resources