Whoops, looks like something went wrong. Laravel 5.0 - php

I installed Laravel 5.0 properly by cloning in git, and composer install, when I ran it to browser http://localhost/laravel/public/, it says
"Whoops, looks like something went wrong."
I did not make any changes after composer install.
Update after copy the env.example to .env this is result
RuntimeException in compiled.php line 5599: OpenSSL extension is required.

The logs are located in storage directory. If you want laravel to display the error for you rather than the cryptic 'Whoops' message, copy the .env.example to .env and make sure APP_ENV=local is in there. It should then show you the detailed error messaging.

This is happening because there is a field in .env file named, APP_KEY, which is blank now, we need some random key for this variable.
Follow these steps to get rid of this problem.
Rename .env.example to .env
Go to your root directory in your command prompt (If you are using windows)/terminal (If you are using MAC or LINUX) where you have installed laravel project/files and run following command
php artisan key:generate
and then run your project.
It's all done.

Give write permission to storage and bootstrap/cache directories
Rename .env.example file to .env
If you get "RuntimeException... No supported encrypter found. The cipher and / or key length are invalid." error, stop the application and generate key from command line "php artisan key:generate"
If your get "OpenSSL extension is required" error, enable the openssl extension by opening php.ini in php installation folder and uncommenting the line extension=php_openssl.dll by removing the semicolon at the beginning

Follow these steps to this problem for all versions of your laravel like laravel 5.5
Step: 1
Rename file .env.example to .env
Step: 2
Go to your Command prompt/terminal and change path to project directory.
Generate key for your application. This is unique for every application so don't make copy paste.
Just run the following command. Key will automatically save to your .env file
php artisan key:generate

Try to type in cmd:
php artisan key:generate
the problems will be solved

Please, try to find something like:
./website/config/app.php and set 'debug' => env('APP_DEBUG', false) as 'true' 'debug' => env('APP_DEBUG', true)

Simply type in terminal in your command prompt go to laravel directory path and type php artisan key:generate then key will be generated. Paste that key in config/app.php key variable. Your problem will be solved. I also did like that inorder to solve the problem...

Try this:
sudo chown -R www-data pathto/.env
BECAUSE IF After Creating the .env file or/and Generating the Key by
php artisan key:generate
just as explained previously by others, and it still persists
Try the following:
ls path/.env -al
if apache doesn't have access to it by displaying
www-data
as one one of the users i mean like
-rw-rwx--- 1 www-data rootuser 575 Nov 4 06:34 pathto/.env
This as stated above should resolve it. Especially when your laravel.log file keeps complaining that the key hasn't been generated or added.
sudo chown -R www-data pathto/.env

In Laravel 5.5, I had the same issue
.env
was added to .gitignore.
So Either remove ".env" it from .gitignore file.
or add it forcefully
git add .env -f
And Deploy it. It will work.
If above does not help. Try generating the Key Again
php artisan key:generate

Check, which PHP version is running on your WAMP,XAMPP or LARAGAN server. It should be greater than 7.0.
Go to project folder like "C:\wamp\www\laravel".
Open the file name of .env.example. (By using any editor like sublime, notepad++ and so on).
Save as a .env
Then run your LARAVEL program. Hope it will work.
You can check whether how to change the PHP version in your current server. xampp, wamp

I renamed the .env.example to .env and ensure
APP_ENV=local
which showed me the actual error. It was related to key.
Then I issued
php artisan key:generate
command and it worked

For windows users, make sure apache's ssl_module is checked.
Please see image below:

First run command composer install
Then check for .env.example and .env files in your project folder.
.env file is your main configuration file for database and .env.example is backup file for .env file.
.env.example file will always be there but sometimes .env file can be missing.
just copy the .env.example file and paste in the same project folder with filename .env .
now run php artisan key:generate command. this will generate key for your application.

You can copy these files from template "blog" laravel

make sure app/storage dir permission is set to 755 and owner is set to admin. and also check permission and owner of files and dir in app/storage too

Create a new .env file and copy the code of .env.example and run the command -> php artisan key:gen

Rename the .env.example to .env
Go to bootstrap=>app.php and uncomment $app->withEloquent();
Make sure that APP_DEBUG=true in .env file.
Now it will work.

This worked for me:
Go to the .env file and be sure APP_DEBUG=true
Here (in .env file) change reemplace 127.0.0.1 for localhost for check if your DB credential are corrects.
Go to the config folder and do. the step #2.

in process of uploading env file to cpanel,
sometimes the dot is taken out and this may raised the error.
this solution worked for me.
go to your cpanel and rename env file to .env

Related

Laravel php artisan key:generate in production

On my production server I set the env var APP_ENV=production. With this config laravel will not use .env file but it will use env var declared on the server.
But I have a problem when I run this command php artisan key:generate because I'll get this error:
In KeyGenerateCommand.php line 96:
file_get_contents(/app/.env): failed to open stream: No such file or directory
Just for this command laravel need the .env file. So actually I create an empty .env file to make it works but it's ugly...
Do you have any solution ? or maybe this command is useless in production env ?
When you push a Laravel project to production, you need to generate a .env file, since that file is not committed. You should have a .env.example, which you can copy and modify as required:
cp .env.example .env
Then you can run php artisan key:generate to set the App Key.
You can also run this :
sudo php artisan key:generate
Before doing it make sure you are in the folder, for example :
cd /var/www/html/your_folder

How to resolve no supported encrypted found while doing 'composer install'?

I'm new to laravel and I want to learn it. I am trying to clone a github repository. The repository tells me I need to clone it, and then to run the 'composer install' command. But I get the following error:
[RuntimeException]
No supported encrypter found. The cipher and / or key length are invalid.
Script php artisan clear-compiled handling the post-install-cmd event returned with error code 1
I tried searching for this error on google and it told me to change the cipher to 'AES-256-CBC'. But when I checked the cipher it has the 'AES-256-CBC'.
Does anybody know how to resolve this problem?
you need .env file:
You can download env.example, rename it to .env and edit it. Just set up correct DB credentials etc.
Note: If you already have .env.example, just rename it to .env
Don't forget to When you use the php artisan key:generate it will generate the new key to your .env file
check your .env file,it has this APP-KEY filled!,if not there-then run this command.
php artisan key:generate
And after that check your .env file, there should be this type of line
APP_NAME=Laravel
APP_ENV=local
APP_KEY = ***keys_go_here***
....
and in your config/app.php,is there present this code of line.
'key' => env('APP_KEY')
After that do what you supposed to do previously.
You need to copy .env.example file and make new file in same directory name as .env
and then run
composer install
Try this in your console.first copy the .env.example
sudo cp .env.example .env
php artisan key:generate
if php artisan key:generate give permission error then giv permission to your .env
sudo chmod -R 777 .env
then
php artisan key:generate
first, install the Composer, then go to the project folder in cmd and run this command:
composer update

How add Artisan cli to existing laravel project?

I have issue with Artisan usage on Windows 10 with Xampp.
What have I done:
clone project from git repositiory
run composer install
In directory with project i trying run:
php artisan
but i get errror:
Could not open input file: artisan
But if i run command
php bin/console i get list of command like cache, debug, eloquent... so some tools are there... But none artisan...
How i can add/use artisan into existing project?
Check if artisan file exists in your project root folder. If it does, then you're probably on the wrong folder. If it doesn't exist, you can just download it from the official repo.
To configure an existing project, you'd typically check those things first :
You should goto app/config/database.php check file and verify username and password.
After check in Project Folder vendor folder and composer.json file exist then remove it (that remove old configuration now we going to fresh configuration).
Then after back to command prompt and fire command composer update and that download some dependent file download.
Now Run php artisan serve

Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

I have a project on Laravel 5 and I work with it at the office and at home too. It works fine, but recently at home it stopped working. Laravel show me two ErrorException
file_put_contents(G:\project\storage\framework\views/751d8a0fd8a7d4138c09ceb6a34bb377aa2d6265.php):
failed to open stream: No such file or directory
and
file_put_contents(G:\project\storage\framework/sessions/aIXycR4LIAUBVIqZu0T590paOMIpV8vfZGIroEp0):
failed to open stream: No such file or directory
I'm searching problem decision with Google and find information about correct rights. All advice is about Linux, but I'am work in Windows at the office and at home too.
When I try to clear application cache and view cache, artisan talk to me - ...cleared. But cache data and views are present in storage.
How can I fix this problem?
The best way to solve this problem is, go to directory laravel/bootstrap/cache and delete config.php file. or you can rename it as well like config.php.old
And your problem will be fixed.
You should typically run the php artisan config:cache command as part of your production deployment routine. As a solution to your problem, I suggest you recreate the cache file, for faster configuration loading.
To do this, run the following Artisan commands on your command line
php artisan cache:clear
php artisan config:cache
You can programmatically execute the command by adding the following to your routes:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
And then call the clear-cache route from your browser.
After some research I understand - I have very similar, but different root project locations and its cached in /bootstrap/cache. After cache clearing project started.
Actually I faced this issue when I moved my project from server to local.
in
storage/framework
four basic folders are required cache, sessions, testing, views
In My case sessions was missing might be in gitignore.
So I manually created session folder and refreshed browser and it was working.
So any of the missing folder if we delete this problem can be solved.
I solved this problem via creating storage\framework\sessions folder.
Apache + WSL on windows
This is a silly mistake, and a different answer compared to the others, but I'll add it because it happened to me.
If you use WSL (linux bash on windows) to manage your laravel application, while using your windows apache to run your server, then running any caching commands in the wsl will store the linux path rather than the windows path to the sessions and other folders.
Solution
Simply run the cache clearing commands in the powershell, rather than in WSL.
$ php artisan optimize
Was enough for me.
This type of issue generally occurs while migrating one server to another, one folder to another. Laravel keeps the cache and configuration (file name ) when the folder is different then this problem occurs.
Solution Run Following command:
php artisan config:cache
https://laravel.com/docs/5.6/configuration#configuration-caching
Try with these commands that have been useful with those errors
path\project\storage\framework\views...
php artisan view:clear
path\project\storage\framework/sessions...
php artisan config:cache
I deleted the file /public_html/bootstrap/cache/config.php
Then I ran php artisan config:cache
In case of shared hosting when you do not have command line access simply navigate to laravel/bootstrap/cache folder and delete (or rename) config.php.
This happens when you shift your website from local to live server or vice versa.
Simply go to bootstrap/cache and delete config.php.
The reason is related to cache or permission.
Firstly, go to directory laravel/bootstrap/cache and delete all files from cache.
php artisan cache:clear
php artisan config:clear
php artisan config:cache
If the errors still happen. It may relates to permission
Let's try command below (In my case user&group of laravel is nginx)
sudo chgrp -R nginx storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
If you are running laravel inside docker then access its filesystem
$ docker exec -it name-of-laravel-container /bin/bash
Next navigate to your laravel projects root directory. Make sure that you have inside storage/framework folder:
cache
sessions
testing
views
And they should be both readable and writable.
If nothing work try the following in the production environment
1-
composer install --optimize-autoloader --no-dev
2-
php artisan cache:clear
3-
php artisan config:clear
4-
php artisan view:clear
5-
php artisan config:cache
6-
php artisan route:cache
Works for me
Changing name of /bootstrap/cache/config.php to config.php.old doesn't work for me
neither clearing cache with the commands artisan
php artisan config:clear
php artisan cache:clear
php artisan config:cache
And for some weird reason I can't change permission for the owner on the directories, so my solution was running my IDE (Visual Studio Code) as admin, and everything works.
My project is in an F:/ path of another disk.
The reason for this problem is the cache files in localhost. According to that I've tried several things as follows to clear the cache on my project, but every time I've failed.
Tried to clear cahe commands by changing web.php file (with artisan codes)
Tried to clear cache by connecting SSH (via PUTTY)
Tried to host my project in Sub domain within create a new Public directory
So I've found a solution for this problem after each and every above steps failed and it worked for me perfectly. I deleted the cache.php file in host_route/bootstrap/cache directory.
Maybe there is an issue with your composer file. You could try:
composer install installs the vendor packages according to
composer.lock (or creates composer.lock if not present),
composer update always regenerates composer.lock and installs the
lastest versions of available packages based on composer.json
composer dump-autoload won’t download a thing. It just regenerates
the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project. Ideally, you execute composer dump-autoload -o , for a
faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticeable)
source
In my case it was not anything that could be fixed with php artisan commands. The issue was folder permissions for the /storage folder. The error did not make that clear.
The solution that worked for me is to just serve the app as admin
if you are
On mac or linux use sudo php artisan serve
On Windows try to open CMD as an adminstrator and then go to project directory and run php artisan serve
Clearing the contents of storage/framework/cache did the trick for me.
I had similar problems because of .gitignore for the /storage folder on first machine, then cloned repository on second machine and laravel was revision to write down sessions cache
So, manually creating folder /storage/sessions might be an solution..
This did the magic for me. chmod -Rf 0777 storage
In my case, I set APP_DEBUG=false since it is a production server, I decided to set it back to true and then it showed Missing BC Math or GMP extension
That is how I solved my own issue, setting APP_DEBUG=true might not work for everybody.
I used Laravel 8, This is my solution:
Goto:
storage/framework/cache/data
set permission directory data is 777
I went all the way, but I did not get the answer.
I just rename cache folder in storage/framework/ to cache1 and solved my problem.
I solved it clearing the content of:
/laravel/storage/framework/views
Then all the views were created again in that folder.
In my case these commands didn't fix it:
php artisan view:cache
php artisan route:cache
php artisan config:cache
I'm using Laravel 8 and in my case it seems that it was an issue with the permissions.

laravel content management system

I tried to install this CMS https://github.com/murattanriover/basecms-laravel, I followed the install instruction, I created new database and I modified database.php file with my host data and I followed these instructions:
composer install
php artisan key:generate
Create a database and inform .env
php artisan migrate to create tables
php artisan db:seed to populate tables
But when i try to run: localhost/projectname/public/
I got the following error:
You need to set APP_KEY in .env
Set it to a random 32 character string
OR
Run php artisan key:generate in the root folder of your project.
This sets a random 32 character string for the encryption key.
In config\app.php change:
'cipher' => 'something stands here(delete it)',
to
'cipher' => 'AES-256-CBC',
If that doesn't work, you'll need to manually add the key laravel generated to your .env file.
open the console and
php artisan key:generate
then you'll get the new key
Application key [xlhF31NeOlibJcoOW9tvZg7TkHcAZI3a] set successfully.
then go to projects and
~/projects/ nano .env
Manually add the key laravel generated to your .env file
APP_KEY=xlhF31NeOlibJcoOW9tvZg7TkHcAZI3a
As you are using WAMP server, please do as follow:
Open your wamp's php.ini (in my case it's in: C:\WampDeveloper\Config\Php\php.ini)
Find this line and uncomment it (remove front “;”).
From ;extension=php_sockets.dll to extension=php_sockets.dll
Save file. Restart Apache.
Do a php artisan key:generate.
Then make sure that your config/app.php has a line as follow:
'cipher' => 'AES-256-CBC',
Reference to WAMP specific solution.

Categories