After using below command .env file no created in root
composer create-project --prefer-dist laravel/laravel project
and getting error while accessing url
Whoops, looks like something went wrong.
Is there any wrong with this command or any other setting ?
any idea please share
You should create your .env file using the .env.example file to configure the database and everything else as needed. Be sure to generate a key with the artisan command key:generate as well. By default, laravel uses the configuration files inside the config folder.
Its simple to resolve, just copy .env and copy content from .env.example
or
run bellow command:
cp .env.example .env
You can just make one in a text editor. There's nothing special about them. Just lookup an example of one and make sure you fill in all the necessary env variables.
vim .env
or
nano .env
from your app root and add the following:
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
Here's an online example if you need it.
EDIT
If you're worried about the file permissions, sudo chmod 644 .env should be fine. Make sure you add .env to your .gitignore file if it's not already there. You should never track your environment variables in version control.
Related
I have a huge problem with .env file in Laravel. When I make a change in .env file, it is not changed. I think all of you know what I'm talking about. I run this php artisan config:cache, but yet, nothing changed! I echo out a variable in .env file and nothing changed. What can I do for that?
When you cache the configuration all calls to env will return null because it does not load the .env any more. You should not have any calls to env outside of the config files.
You use the configuration system to get the values you want, which is why the config files make calls to env to get values from the environment.
If you using php artisan serve you have to reload it after changing .env file
When trying to retrieve the APP_URL from the Laravel config it returns the wrong URL for development only.
My env file has the following:
APP_URL=http://127.0.0.1:9000
However when I call env('APP_URL') it returns me:
'http://localhost'
Which will not work with my current docker set-up it has to be 127.0.0.1:9000
In my config/app.php file I have the following:
'url' => env('APP_URL')
I have tried php artisan config:cache and php artisan config:clear but I still get the same result of http://localhost
Any ideas on where it could be getting http://localhost from other than the .env or config/app.php?
Thought it would be worth noting using config('app.url') also returns http://localhost
I found out there is an undocumented feature when loading .env files. If you have a .env.dev file in your project folder it will load this config over everything else if your application is in dev mode. It's documented that .env.testing is used in testing which makes sense but it also does it for dev with .env.dev
The application I was working on had a .env.dev and it was this file that had the http://localhost string inside of it.
Just in case anyone is having this issue in production, these are the steps that worked for me:
Make sure that the .env file is specifying that the app is in production. APP_ENV=production
Run php artisan optimize:clear
"localhost" is probably the default value. You error indicates that the .env file is not read at all. Make sure you're not editing .example.env, check if other env variables are accessible, check for typos, check file permissions on .env and if it's located in the root folder of the project.
In Laravel 6 Documentation second paragraph of Application Key written like this
Typically, this string should be 32 characters long. The key can be
set in the .env environment file. If you have not renamed the
.env.example file to .env, you should do that now. If the application
key is not set, your user sessions and other encrypted data will not
be secure!
Why did they ask to rename it? I also found this paragraph in the Laravel older version. Is there any difference between those since they have the same content but different name?
If you've install Laravel using composer command.
composer create-project laravel/laravel projectname
you don't need renamed the .env.example file to .env. If you installed Laravel via Composer or the Laravel installer, this key has already been set for you by the php artisan key:generate command.
If you clone project using git clone some folder is ignored by git so you might not get env file as well as vendor folder. Therefore, they will have to manually enter php artisan key:generate for their app to function correctly.
More info SO answer
Laravel need to use .env file to define a database connection, some general setting like application key as well. So if you have no .env file, your Laravel has not a setting for now.
Like they said, If the application key is not set, your user sessions and other encrypted data will not be secure! You need to create / copy /remove the .env.example to the new .env for this reason. for letting our Laravel knows about general config.
By the way, do not use the .env.example like copy-and-paste because it's an example. you need to change the value config to your own.
The simplest way is move it on your server with Filezilla or another FTP program. Rename file, and re-download it on your computer. It works for me last time :)
The .env.example the file is just an example of the .env file. It is not used by the app. It is used to serve as a base for you to edit and rename.
In a fresh Laravel installation, the root directory of your application will contain a .env.example file. If you install Laravel via Composer, this file will automatically be renamed to .env. Otherwise, you should rename the file manually.
Today I tried uploading my first website,but i'm getting an error.On the local server it works fine but when I uploaded it to the live server,i'm getting an error that is saying "Whoops, looks like something went wrong".To be more specific it's showing twice on the same page.Check the image bellow.
Steps followed while uploading project to live server:
Zipped the file
Created a new folder at the root directory.
Unzipped the file in the new folder.
Moved all the files from public folder to /public_html/
Edited the locations on the index.php file.
Note: Other than index.php I haven't altered any other file.
I followed a lesson on youtube and with these steps, his project worked but mine is throwing an error.
I have also noticed that after unzipping the folder in the cpanel the .env file is missing.Could this be the issue?
Make the .env file is there .
Then don't forget to generate the application key
php artisan key:generate
There are some times that the .env file isn't being read by the server. You may try to edit the .env file and supply the necessary credentials according to your server such as the following:
APP_URL= *
APP_KEY= *
DB_CONNECTION=mysql
DB_HOST= *
DB_PORT=3306
DB_DATABASE= *
DB_USERNAME= *
DB_PASSWORD= *
The lines with the asterisks are the ones you typically need to fill up. The APP_KEY can be set by using the php artisan key:generate command in your local workspace, then copy the value to your live server.
If the .env can't be read and it still shows an error, try to edit the config/app.php file and change 'key' => env('APP_KEY'), into 'key' => yourgeneratedkey,. Try to also change the values in your config/database.php file into the same one as your .env file
Follow the installation guide https://laravel.com/docs/5.6
Check the server requirements(check if all the required extensions are installed).
Check if all the files are there.
Check Configurations
check config.php file
check directory permissions.
generate application key (php artisan key:generate)
Check if .env exists or not
thanks to all of you who replied.I found the solution.It turns out the cause for the error was a simple spelling mistake in my .env file.
This is caused by missing ".env" file, copy the content of ".env.example" file and create a new ".env" file in the same directory as your "example.env" file.
then run: php artisan key:generate
How to run laravel project from github on localhost when .env file is missing in the laravel project?
You can rename the .env.example to .env and then run php artisan
key:generate and it'll function as it should.
If you're using a command line simply type cp .env.example .env and
run the key:generate command.
If you are missing the .env files completely, you may take the .env.example file from: https://github.com/laravel/laravel/blob/master/.env.example
Then simply create a new file named .env within your project. You will still need to run php artisan key:generate once you have created the file.
Copy .env.example
Change the name with .env
Make your own settings in .env file.
After that run "php artisan key:generate"