Laravel 5.8 , artisan commands error : Failed to parse dotenv file due to an invalid name - shared-hosting

This problem only happens with Laravel 5.8 on my shared hosting.
It is working fine in my shared hosting with Laravel 5.7.
It is working fine in my local environment with Laravel 5.8.
the problem is:
every time I run php artisan commands (on my shared hosting with Laravel 5.8 only) I got this error
The environment file is invalid! Failed to parse dotenv file due to an invalid name.
Failed at [APP_NAME].
my .env first line is : APP_NAME=rased
Also my site after updating to Laravel 5.8 is becoming a white blank page!

This is a general error related to parsing the .env file.
You'll see this is indicated in the error e.g.
The environment file is invalid!
Failed to parse dotenv file due to unexpected whitespace.
Failed at [This will fail].
In this example it was caused by having unescaped whitespace in the APP_NAME field i.e.
APP_NAME=This will fail
To fix, escape with quotes e.g.
APP_NAME="This is better"

This is general Error when we change our app name. To remove this error just do this.
APP_NAME=My Project Name
to this
APP_NAME="My Project Name"
You just need to add "" course around name.
Thanks

I found the cause of this problem.
It was because of line separator in .env file !
It must be CRLF not LF
My .env file was LF
see the screenshot to understand the solution

I received a similar error while upgrading from Laravel 5.5 to Laravel 5.8.
The environment file is invalid! Failed to parse dotenv file due to an
invalid name. Failed at [//APP_ENV].
5.5 would accept C style comments on APP_ENV:
// env file setup for production environment
//APP_ENV = production
//APP_DEBUG = false
// env file setup for local environment
APP_ENV = local
APP_DEBUG = true
While 5.8 will not. # works for comments:
# env file setup for production environment
#APP_ENV = production
#APP_DEBUG = false
# env file setup for local environment
APP_ENV=local
APP_DEBUG=true
I had tried removing the spaces as a brand new 5.8 application installs without spaces in these definitions. That didn't fix it.
Curiously I still have C style comments other places in the file, so only for APP_ENV?

I changed the encoding of .env and it was solved.
UFT-8 without BOM
Thanks

I recently ran into this same problem on my app for Laravel 6.12.0.
I was able to resolve this issue by adding a blank new line/space at the top of the .env file.
Example .env file:
[add a new line here]
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
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
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

I had exactly the same problem, but a different solution. CRLF made no difference.
This was driving me nuts, and I read somewhere that C style comments were no longer supported. My env file didn't contain any, but in desperation I added the following line to the top of the file:
# getting tiresome.
I don't think the wording is important, but the key thing was there was a comment.
After that, it worked. I don't know why, but it did.
Fast forward a few months, and the problem returned the next time I have to upgrade Laravel. This was kind of weird as the file was the same. This time I had to make sure I saved the file as UTF-8 without BOM.

I have added course "" around the DB_DATABASE path.

MAIL_FROM_NAME=Account confirmation
i was just making spaces between the two words
Just try to avoid it like : Account_confirmation
MAIL_FROM_NAME=Account_confirmation (correct)

In my case, I had an extra line that shouldn't be there.
Header set X-Frame-Options SAMEORIGIN Removed this and IT WORKED

I discover that if you declare the APP_NAME in quotes in the .env file, It will allow spaces in the app name but make sure you restart the server using the command (php artisan serve)
For e.g: APP_NAME='Laravel Login'
That works for me.

delete the .env file and recreate another with the same content

In case anybody else gets here and hasn't solved their problem. I came across this issue and found that it was due to using a hyphen to separate the environment variable name.
NOM-OPEN="2020/01/24"
This was okay up to Laravel 5.7 but fell over for 5.8. To solve it change the hyphen to an underscore.
NOM_OPEN="2020/01/24"
Don't forget to update all references to the variable!

Related

How do I fix code not being ignored by phpcs in VSCode

I'm trying to (temporarily) ignore some errors about not using Nonces. I've tried using // #codingStandardsIgnoreLine. before the line, and I've tried using // phpcs:ignore WordPress.Security.NonceVerification.Missing., I'm still being notified of a nonce problem:
What have I done wrong? I'm using VSCode. I have PHPCS installed using composer, and the PHPCS (and -BF) extensions installed.
Did you add /Users/your-username/.composer/vendor/bin/phpcs as part of the installation? I had a similar issue because I had added another username.
Also, make sure that the following line is at the root of your project in a terminal:
composer require --dev squizlabs/php_codesniffer
To ignore the line, you can alternatively type
// phpcs:disable and // phpcs:enable at the beginning and end of the line.

Expo application doesn't get changes in .env file

I have an Expo managed react native application. I created my .env file in the root of my project, installed react-native-dotenv and set up babel to use it. After a while I managed to get it to work.
I have my environment variable
ENDPOINT=http://127.0.0.1:8000/api
and i use it with
process.env.ENDPOINT
After a while I decided to test the android version of the app, so i changed the endpoint url to my LAN ip and restarted the server. The problem is that even after restarting the server, the cache and the computer, when I call process.env.ENDPOINT it keeps the first url I set.
Here's a list of the things i tried:
restarting the server
restarting the server and the cache
restarting the whole computer
change the variable name to REACT_APP_ENDPOINT as many suggested (I get undefined, it's still stuck to ENDPOINT)
empty expo cache
The strange thing is that I already changed that same variable twice (from 127.0.0.1:8000 to 127.0.0.1:8080 and back for a problem with backend) and had the same problem, but it went away by itself after a couple of minutes (and server restarts).
This time I've been trying to get it to work for 7 hours and nothing has changed.
Any idea?
I had the same issue and managed to run the app with .env changes after using the following command.
expo r -c
reference: https://github.com/goatandsheep/react-native-dotenv/issues/75#issuecomment-728055969
After a couple hundred more tests I gave up and implemented a "custom" solution, without any external library:
Switched .env files to TypeScript files (E.g. .env.development -> env.development.ts)
Set up an object named env that has all environmental variables as properties
export const env = {
VAR1: 'foo',
...
}
Imported this constant inside the application entry point (in my case App.tsx)
Inside the main constructor assign env to global.env
Use global.env instead of process.env
Not sure if this is the best practice, but solved my problem for now, works like a charm and doesn't require me to reload my application at every change. I'm a bit concerned by the security aspect of having the environment in a global variable inside a js project, so any suggestion is still welcome

How to deploy fuelphp website to server

I'm new to fuelPHP, I developed a simple application and when I uploaded the files to my web server I got those errors :
Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /home1/tdfdf/public_html/site/site/public/index.php on line 22
Fatal error: require() [function.require]: Failed opening required '/bootstrap.php' (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home1/tdfdf/public_html/site/site/public/index.php on line 44
I probably miss some configurations here. I also want to remove this "/public" from the url
Can any one help ?
I found the solution. The DIR is not defined for older versions of PHP . I changed my server settings to run on PHP 5.3 and it worked like magic.
Thanks.

After upgrading to rails 3.2 I see ActiveRecord::Fixture::FormatError: a YAML error occurred parsing

I see the following error after upgrading to rails 3.2.12 with ruby 1.9.2.
ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /SampelRails/user_properties.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html
The exact error was:
Psych::SyntaxError: couldn't parse YAML at line 1 column 0
I have doubled checked the yml files and they seem to be indented properly.
according to https://github.com/rails/rails/issues/2731 this issue seem to be fixed in rails 3.1.1.
just experienced the same issue but the problem was that i was saving my VCR cassettes in test/fixtures/vcr_cassettes/*.yml.
ActiveRecord::Fixture gets confused by yml files with content other than AR fixture data.
The link posted by nathanvda really worked.
Try adding this at the beginning of config/boot.rb
require 'yaml'
YAML::ENGINE.yamler= 'syck'
Rails 3 - 'Couldn't parse Yaml'
I just had the same issue. Solved it by removing a dummy fixture file from fixtures directory. That file had nothing but comments in it.

XUL standalone application not starting

I recently took on a project built on XUL (standalone, using xulrunner) - However I can't get it to properly run.
I'm getting this error when I attempt to start it using the command line (xulrunner.exe ../application.ini -jsconsole):
No chrome package registered for chrome://case_scenario_builder/content/case_scenario_builder.xul
The chrome.manifest file looks like this:
content case_scenario_builder file:chrome/case_scenario_builder/content/ contentaccessible=yes
content jslib jar:chrome/jslib.jar!/
skin case_scenario_builder skin file:chrome/case_scenario_builder/skin/
locale case_scenario_builder en-US chrome/case_scenario_builder/locale/en-US/
Any ideas on where I could start debugging?
I figured it out!
In case anyone else runs into this as well:
It was due to the caching system in place by default and the use of .jar containers instead of folders.
The XUL environment had cached both JS and XUL files - and even after disabling those, I had to extract everything that was in the .jar file to the content folder and update the chrome.manifest file.
Thanks for your suggestions on debugging! - they helped the process.
I guess your manifest just isn't getting loaded. To test that I'd introduce an intentional syntax error and check the error console. E.g. if you put
asdfasd
on its own line, you should get a Warning: Ignoring unrecognized chrome manifest directive 'asdfasd'. in the Error console.
(Note to other experts: initially I wanted to suggest dropping 'file:' prefix and avoiding underscores in the package name, but I tested it on a Firefox nightly, and it works fine.)
Your chrome package clearly didn't get registered. From what I can tell, the reason is the bogus file: prefix, you should drop it when specifying relative paths:
content case_scenario_builder chrome/case_scenario_builder/content/ contentaccessible=yes
Btw, I suspect that you copied contentaccessible=yes from somewhere - you should drop it as well unless you know what it does.