artisan key generate error - php

I am trying to duplicate a laravel project on my local machine (windows, wamp, laravel 5.4)
I copied all the files and folders beside the vendor folder to a new folder.
I ran composer install, artisan cache:clear and composer dump-autoload
But, when I ran artisan key:generate I get this error:
file_put_contents: failed to open
stream: Permission denied.
Why is that and how do I solve it?
Thank you

You need to run:
chmod -R 777 storage/*
sometimes sudo chmod -R 777 storage/*
then php artisan cache:clear
then php artisan key:generate
This is due to the file permissions not being writeable. Seems to be quite a regular occurrence this happens but the steps above will rectify your problem.
To utilise more of these commands on a windows you can use a program called Git Bash. It's a very neat and handy tool: Git Bash
If you do not wish to use git bash you can take this approach:
Locate the Storage folder within your file explorer. Right click and press permissions and change the security permissions to allow write access.

Related

Getting Error 500 after composer update from ssh

I used to use forge for deploying my laravel application to production. I recently deregisted forge and I wanted to deploy via ssh to ubuntu server on my own.
I did composer update and I pull changes to my server via ssh; but after these my application started to give error 500. I did every thing I searched may be useful such as commands below but nothing worked.
does any one know why am I facing is this error? in local environment every thing works properly and my laravel project worked properly before ssh and composer update.
these are the steps I have go through but nothing worked:
deleting vendor folder and reinstalling composer
changing permisions for bootstrap and also for the whole project :
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
run composer dump-autoload
php artisan config:cache
composer update and sudo composer update
I also tried these commands but none of them worked:
php artisan view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I am using laravel 8
my .env file also exists and every thing are set there
when I turn on debug mode the error of the application page is like this:
Target class [hash] does not exist.
please helpme if any one has any experience on this problem.
From russia /ivorycoat
delete vendor
composer update
.env.example copy and create .env
php artisan cache:clear
php artisan config:clear
php artisan key:generate
php artisan serve

No such file or directory error (Laravel/Homestead)

I use laravel on homestead. I tried a lot of different commands in order to clear cache and other stuff and nothing helped.
I keep getting this error:
file_put_contents(/Users/Victor/Sites/pft/pft-back/storage/framework/cache/data/05/9f/059f793d8b638b8c21ead7edbba382b9e9183fac): failed to open stream: No such file or directory
What I've tried is:
Set 777 for storage folder
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
composer dump-autoload
No idea why it's happening but I'm pretty sure because of homestead since I've just recently started using it.
Also I tried all commands both from homestead user and mac user (I'm running homestead on mac)
The problem is the underlying storage maps, could check if storage/framework, storage/framework/cache and storage/framework/cache/data have r/w permission and otherwise create them?

Laravel throws 'The bootstrap/cache directory must be present and writable' error after update

I used 'composer update', which updated a few packages. During the updating process the website still functions. However, after it says 'The compiled services file has been removed', the website doesn't load and instead says:
Exception in ProviderRepository.php line 190:
The bootstrap/cache directory must be present and writable.
The weirdest thing is, when I run 'composer update' again, the website starts to work again, until the compiled services file is removed, at which point it throws the same error again. I have already tried the usual things that should be done when this error appears (chown -R everything to the right user/group and chmod all the files and folders 664 and 775 respectively).
I don't know what to do anymore, as the error doesn't seem 'correct'..
Try this after you have run the composer update:
php artisan cache:clear
On your Laravel directory file, run:
sudo chmod -R 777 bootstrap/cache/
The best way to resolve this error is:
Open your project folder
Move to the bootstrap directory
Create an empty folder named as cache
Then do PHP artisan cache:clear
This will work for sure
Short version: If uploading using something like AWS eb cli Verify if bootstrap/cache folder (not talking about its contents) is being deployed.
Some background behind my answer
I am using Amazon Web Services' Elastic Beanstalk to host my Laravel project. As I just started using Laravel I do not have much idea about its functioning. Two days back My new deployments were all crashing midway with OP's error message.
Earlier that day, I realised that I was not using
php artisan config:cache
to cache configurations to make things faster. And I added the same in composer.json's "post-install-cmd" and "post-update-cmd" clauses.
And I also added statement in .ebignore file to not upload the content of /bootstrap/cache (as its content is environment dependent a.k.a my localhost configurations have no meaning on my production server)
And facepalm I did not realise that this will stop the bootstrap/cache folder from being uploaded (as Like git, eb cli ignores empty folders).
So, when I started to deploy at night The deployments were meant to crash.
So, now I have just placed empty-placeholder (say) .gitkeep file in bootstrap/cache. And deployments are working once again :)
(Though the problem was so simple I realised the reason after ssh-ing and digging an EBS EC2 instance for some sweet sleep hours ~.~ )
For me, I manually created the cache folder inside bootstrap.
Try this too after you have run the composer update:
php artisan config:clear
Im using cmder on windows 10 in non elevated mode (Non-Admin).
command php artisan cache:clear did not work for me.
The folder bootstrap/cache did not exist.
I created the folder and removed readonly from both bootstrap and bootstrap/cache folder.
Both composer install and composer update are working now.
sudo chmod -R ug+rwx storage bootstrap/cache
hopefully, this will solve the problem.
it work for me run in project folder
sudo chmod -R 777 bootstrap/cache
than run
composer update
than run
cache:clear
First make sure bootstrap/cache dir is exist if not create a new one
mkdir -p bootstrap/cache/
Then run php artisan config:cache
Simple. There are applications that can block the directory. Like google drive synchronizer, One driver synchronizer, or any other application that is using windows explorer.
Delete cache folder. Create this again.
Try executing the following commands in your project root directory
composer update
then do
composer dumpautoload
this will avoid the necessity of messing with cache files
which may lead to whole new sort of issues
I don't imagine what I got done wrong with that before and no games around with that cashclearings had sense. But as it claims there was no 'cache' folder inside /bootstrapp . Had to have create it manually. Now it all rocks ok again
I had to create these five folders to be able to run artisan again.
mkdir bootstrap/cache
mkdir storage/framework
mkdir storage/framework/cache
mkdir storage/framework/views
mkdir storage/framework/sessions
Answer was found in this related question:
"Please provide a valid cache path" error in laravel
In my case, I've found out that the bootstrap/cache is missing in my project during a fresh clone.
Re-adding the cache directory manually solved my issue.
Then running composer install now works fine.
If a web server (e.g. Apache or Nginx) is being used as a front-end the solution is to make the directory bootstrap/cache owned by web server group. For Nginx:
$ sudo chgrp -R nginx bootstrap/cache

cloning laravel project from github

I'm new to GitHub and I found this site very useful for a lot of us. I came upon storing my Laravel project here in GitHub, but there's a problem every time I will clone it to be able to go to production, when I'm about to clone it at first, it always shows this error.
Warning: require(C:\xampp\htdocs\tourismPortal\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tourismPortal\bootstrap\autoload.php on line 17
Fatal error: require(): Failed opening required 'C:\xampp\htdocs\tourismPortal\bootstrap/../vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\tourismPortal\bootstrap\autoload.php on line 17
I know this will be solved by using composer update on it, but is there any way to prevent this error so that every time I clone it, I will go to production without encountering this error? Thanks, by the way, I'm using tortoisegit to clone, pull and push.
Clone your project
Go to the folder application using cd command on your cmd or terminal
Run composer install on your cmd or terminal
Copy .env.example file to .env on the root folder. You can type copy .env.example .env if using command prompt Windows or cp .env.example .env if using terminal, Ubuntu
Open your .env file and change the database name (DB_DATABASE) to whatever you have, username (DB_USERNAME) and password (DB_PASSWORD) field correspond to your configuration.
Run php artisan key:generate
Run php artisan migrate
Run php artisan serve
Go to http://localhost:8000/
Yes you can, but that is not recommended at all.
You can delete everything in .gitignore file and push them from a working project. Then it will work perfectly where you git clone them.
But there are so many drawbacks in this way.
I recommend you not to do that.
Run `git clone 'link projer github'
Run composer install
Run cp .env.example .env or copy .env.example .env
Run php artisan key:generate
Run php artisan migrate
Run php artisan db:seed
Run php artisan serve
Go to link localhost:8000 OR 127.0.0.1:8000
You guys missed a step here, after this command
php artisan key:generate
Don't forget to run npm install && npm run dev
If you have any front-end environment setup, this command will clear all the dependencies...
Thanks for everyone's great help I also run the command to make the project work.
composer update
Run the following commands:
git clone --single-branch --branch [TAG_VERSION] https://github.com/laravel/laravel.git [CUSTOM_PROJECT_NAME]
composer install

Laravel setup on Mac in XAMPP

When I try to run laravel app using XAMPP localhost, it gives me a white screen of death. However, when I use artisan serve, the app works fine.
Here are the steps that I did:
1. I installed composer globally.
2. Install laravel using the zip file and also through composer. Through zip file, I ran composer install.
When I run localhost/my_app/public, it gives me blank white screen.
Seeing previous answers, I did some things
Added this to bash_profile:
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
On running which php, I get this:
/Applications/XAMPP/xamppfiles/bin/php
Not able to figure out what would be the exact issue.
I think there is a problem with the storage directory access rights. You can change it's mod to 777 or assign the user(with which apache runs in XAMPP) the ownership of the storage directory.
Here is an example of the command to use:
sudo chmod -R 777 storage
Similarly, for assigning ownership:
sudo chown storage [user]:[group]
have u tried pointing to htdocs and run ?
composer create-project laravel/laravel myproject --prefer-dist
Try:
php artisan cache:clear
then
chmod -R 777 your_laravel_folder_path/storage
finally
php artisan dump-autoload
If you trying in XAMPP then your_laravel_folder_path will
/Applications/XAMPP/htdocs/YOUR_PROJECT_FOLDER . That folder contains storage directory.

Categories