I'm trying to install Prestissimo to an Ubuntu 16.04 server, but that leads to an error:
$ composer global require "hirak/prestissimo:^0.3"
Changed current directory to /home/kramer65/.composer
[ErrorException]
file_put_contents(./composer.json): failed to open stream: Permission denied
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...
I'm logged in as user kramer65, so I wouldn't know why it can't write to my home folder. My normal reaction to a permission denied is to use sudo, but composer then always says:
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Any idea how I can solve this?
I had this problem to install laravel/lumen.
It can be resolved with the following command:
$ sudo chown -R "$(id -un)" "$(composer config --global home)"
What this command does: Execute as privileged user (root) the command to change file owner (not group) to the current user (by name) recursively to the COMPOSER_HOME directory.
As the user-name as well as the composer home directory can be different on each system, the following two commands are in use to obtain the ...
... username: id -un
... composer home directory: composer config --global home
This is an old question, and so a reader of the answer may want to become aware of the following:
Prestissimo was dedicated to be used with Composer 1
As of today, Composer 2 has been released which already didn't benefit from Prestissimo any longer.
But even further as of today, Composer 2.2 has been released which is a Long Term Support (LTS) version you should replace Composer 1 with immediatly if you deemed it to require Presstissimo in the past as it is in general and overall much more faster than Composer 1 ever was - with or without Prestissimo.
How to continue:
Remove Prestissmo from any of your systems.
Replace Composer 1 with Composer 2.2 on any of your systems.
Enjoy.
To resolve this, you should open up a terminal window and type this command:
sudo chown -R user ~/.composer (with user being your current user, in your case, kramer65)
After you have ran this command, you should have permission to run your composer global require command.
You may also need to remove the .composer file from the current directory, to do this open up a terminal window and type this command:
sudo rm -rf .composer
For me, in Ubuntu 18.04. I needed to chown inside ~/.config/composer/
E.g.
sudo chown -R $USER ~/.config/composer
Then global commands work.
In my case I don't have issues with ~/.composer.
So being inside Laravel app root folder, I did sudo chown -R $USER composer.lock and it was helpful.
I faced this issue as well but in my case, I was in wrong directory. Check the directory you are working
In my case, .composer was owned by root, so I did sudo rm -fr .composer and then my global require worked.
Be warned! You don't wanna use that command if you are not sure what you are doing.
In my case all the permissions were correct at all the locations manetioned in other answers here, but I was still getting this error.
Turned out there were some vendor directories that were owned by root. Composer writes composer.lock files all over the place when it's doing an update or install.
So solving my case - and this is specifically for a laravel sail container - all ownerships were switched to user sail in the project:
Enter the sail container as root:
vendor/bin/sail root-shell
Set the file ownership for all files in the project:
chown -R sail:sail /var/www/html
You may just want to do the vendor directory only as a first try:
chown -R sail:sail /var/www/html/vendor
The ownership was wrong after switching from a hand-rolled docker-compose.yaml setup to Laravel Sail, which IMO handles file ownership and permissions in a sensible way, separating root from the application user sail.
This might be super edge case, but if you are using Travis CI and taking advantage of caching, you might want to clear all cache and retry.
Fixed my issue when I was going from sudo to non sudo builds.
I was getting the same exception, but in my case I am using PowerShell to run commands
So, I fixed this with an instruction to unblock multiple files first.
PS C:\> dir C:\executable_file_Path\*PowerShell* | Unblock-File
and then use the following to load the package
& 'C:\path_to_executable\php.exe' "c:\path_to_composer_.phar_file\composer.phar "require desired/package
I was getting the same error when using it with WSL Windows 10. I used the following command to solve it:-
sudo chown -R $USER /home/<username>/.config/composer
I had same issue in windows version of composer that has installed in
C:\composer
When I was trying this command
C:\composer require aws/aws-sdk-php
then simply I got into composer installed folder and try it again
C:\composer>composer require aws/aws-sdk-php
the package installed quickly .
In my case I used sudo mkdir projectFolder to create folder. It was owned by root user and I was logged in using non root user.
So I changed the folder permission using command sudo chown mynonrootuser:mynonrootuser projectFolder and then it worked fine.
I was facing the same issue when I was running the composer require inside /var/www/html ,the default root folder of the apache web server and I was able to solve it by making the current user the owner of this html directory by
sudo chown -R $USER /var/www/html
But you definitely want to set the permissions
chmod 755 -R /var/www/html
There are 2 components to consider.
Composer wants you to run it as the logged in user. However, your webserver wants to have permissions over your application.
The solution is to add your user to the webserver group, then update the permissions of your application.
For Ubuntu running Apache webserver, use the following command to add yourself to the Apache group, replacing <username> with your username
sudo usermod -a -G www-data <username>
Now you need to update your permissions on your application. Navigate to the root folder of your application and use the following command
sudo chown -R $USER:www-data .
Composer now has the necessary permissions to pull in the packages you need and Apache has the necessary permissions to deliver your application.
Related
I am trying to install create a new app in Ruby on Rails and I cannot get passed this error:
$ gem install pg
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/stormyramsey/.rbenv/versions/2.3.2/lib/ruby/gems/2.3.0/gems/pg-0.21.0/.gemtest
Its a permissions issue. You could fix it with this:
sudo chown -R $(whoami) /Library/Ruby/Gems/*
or possibly in your case
sudo chown -R $(whoami) /Users/stormyramsey/.rbenv/versions/2.3.2/lib/ruby/gems/*
What does this do:
This is telling the system to change the files to change the ownership to the current user. Something must have gotten messed up when something got installed. Usually this is because there are multiple accounts or users are using sudo to install when they should not always have to.
It's likely there's a permissions problem somewhere along the .rbenv path. You might try turning on write privileges for your user with:
$ chmod -R +w ~/.rbenv
That will recursively (-R) change the file mode (chmod) to write permission (+w) for all files and directories under your user's .rbenv path. There's no particular reason for not having files set to write.
For Mac M1 systems try,
Allowing full disk access to terminal.
Apple->systemPreferences->Security&Privacy->privacy(Tab)->'+' button, check in Terminal application.
Then Restart terminal
2.Try using,
sudo chflags noschg
Delete the pod folder, reinstall it again. If it doesn't work use this command:
sudo pod install --allow-root
It really doesn't matter on mac how you configure your eyaml create the dir and config manually, add some public key location to it, and its works just fine after adding full disk access to the terminal as Kewin suggested ^ ^. Thumbs up.
No need to change permission, just export GEM_HOME:
export GEM_HOME="$HOME/.gem"
please run:
sudo gem install pg
I have a Laravel project that I copied from my Ubuntu server and now I am trying to run it my local machine (XAMPP on Mac) I have been struggling with this for a few days now and I feel like I am going insane.
When I paste my project in XAMPP htdocs folder I get this error:
View [welcome] not found
Which php artisan cache:clear makes that go away, then I get this error:
The bootstrap/cache directory must be present and writable
Then I do this, php artisan cache:clear which gives me a new error:
Class view does not exist
Then after that no matter what I do either in terminal or viewing the web browser, I always get the error
Class view does not exist
Then I have tried composer update still the same error.....what am I doing wrong?
This has been a nightmare.
Last time i checked Laravel doesnt run on XAMPP but rather on the PHP installed when installing XAMPP so the project can be saved anywhere on the computer.
Given this being the fact, you will need to just have an active PHP installation and then you copy only the relevant files of the project onto the new computer (such files that you will get when you push your project onto GitHub). It doesn`t come with cache issues then all you need to do afterwards is to
php artisan key:generate
then composer install or composer update to get the vendor packages from online
My money right now is on picking the relevant files and reinstall with them
According to my own installation when changing the computer this is the list you will have to copy
I just tried to reproduce your issue on my mac. So i have installed XAMPP with the PHP version 7.1.25 which is the equivalent version of my local PHP version
So I installed the XAMPP and started server.
Downloaded my laravel project folder from my ubuntu server and copied it to htdocs (XAMPP)
When i tried to run http://localhost/myproject/public it shows the exception like
There is no existing directory at "/Applications/XAMPP/xamppfiles/htdocs/myproject/storage/logs" and its not buildable: Permission denied
Then i gave full permission to the storage folder
chmod -R 777 storage
And changed ownership for the files inside myproject folder.
Here i just checked the ownership of the dashboard directory which is running perfectly and given the same user ownership of myproject directory.
chown -R root:admin .
Then following commands
composer install
php artisan cache:clear
php artisan view:clear
php artisan route:clear
After this my laravel code runs perfectly.
Class view does not exist
is probably a ownership issue of the directory
For me (when developing on xampp, what I do for all my projects) - I'd not recommend to put your stuff in the htdocs folder. Laravel expects to not be hosted on a subfodler e.g. (localhost/my-project). So you should set up a virtual host in order to make it work easily (e.g. my-project.test) which is a bit annoying.
Simple solution is using the php artisan serve command in order to simply setup a local server on port 8000.
Don't forget to start xampp for the mysql server.
Some typical tips were already mentioned:
delete vendor folder & run composer install (install composer if you haven't)
run composer dump-autoload
run php artisan key:generate
ofcourse don't forget the migration php artisan migrate
and clear your full cache php artisan cache:clear
Usually you do not need to set any file permissions afaik
chmod -R 777 storage/
If you have a different user for apache2 (usually www-data), also do:
chown -R www-data storage/
You could also check if it runs with the built-in server:
php artisan serve
You can create .htaccess file and add below data into .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
After create .htaccess file, set laravel root path in terminal and run below command in terminal
php artisan serve
Since your Apache is already serving then you have permission problems only. And since you're using Mac, the default user name and group in Apache conf is _www for Mac and not www-data that is for Ubuntu. You can see it in the httpd.conf file :
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User _www
Group _www
</IfModule>
Now, use terminal, get in your project directory let's say cd /var/www/laravel-project1 and make sure that the group _www (or the user too in some case of your App environment logic` has access (read and write) to :
All public directory and sub-directories containing assets if you have.
sudo chgrp -R _www public
sudo chmod -R 774 public
Storage directory and sub-directories specified here (storage/framework -> all, storage/logs -> all, storage/app -> public directory only), and bootstrap/cache directory and files
sudo chgrp -R _www storage/framework storage/logs storage/app/public bootstrap/cache
sudo chmod -R 774 storage/framework storage/logs storage/app/public bootstrap/cache
That should get rid of all of your permissions problem to access pages.
BUT now if on using the page, sessions and logs files that are created you get other problems, there might be a last problem of permission which is called UMask, which tell Apache or Web Server like Nginx what permission to assign to newly created directory or files for the user _www. By default Apache umask is 0002, which give 0775 for directory and 0664 for new file. If ever umask value was changed to 0022 like it's the default in Nginx, then the equivalent permissions 0755 or 0644 will not be sufficient for your Apache group _www to write in the directories that have group _www. So you can either change umask to 0002 or change owner to _www :
sudo chown -R _www public storage/framework storage/logs storage/app/public
So that depends on your configs.
I ran into the same problem as you, but not moving from ubuntu to mac, it was from windows to linux, I was in a total mess, but only git rescued me, it might give you a bit of pain, but it is going to save you in the future.
Here is the steps you need to do.
Create empty repository on the mac using this command git init --bare.
Clone the repository to the ubuntu using git clone.
Copy your laravel code to the clone you made in step 2.
Push the files from the ubuntu to the MAC.
Test the project.
The directory you will create in the mac, it can be inside the htdocs of the xammp.
I know it might be painful task to do, but it is quite worth it.
Sources for more information:
git-scm
Getting Git on Server
If you need more help, I'll be more than happy to discuss it with you.
Note: The following works for Laravel 5.x but also 4.2, not tested with other versions
Why not using Git?
(If you are not familiar with it, have a look at the official website, there are also tons of tutorials on the web)
Usually, copy-pasting entire projects is not a good idea, because of some file/directory permissions and other not-so-good stuff.
That's what I did to move my project from Windows to my Ubuntu Server:
Put your project on a git repository (GitHub, GitLab, or whatever), the .gitignore files provided with the Laravel apps are, in most cases, good enough
On your new machine, clone your repository
Do a
composer dump-autoload
composer install
To migrate your db, do
php artisan migrate
and if you have seeding, do this
php artisan db:seed
Then, if you have problem with file/folder permissions, do not EVER do a chmod -R 777 path/, if you have to do this to solve your problem, you are doing something wrong.
This command grants all privileges to anyone to all the files and folders in the path folder.
In your case, you have to do the following:
First, find which username is apache using to run the server (usually it's www-data)
ps aux | egrep '(apache|httpd)'
Then, change the project directory owner to apache's user (example for www-data apache user)
sudo chown -R www-data:www-data /var/htdocs/your-project/
Set folders permissions
sudo find /var/htdocs/your-project/ -type d -exec chmod 755 {} \;
Set files permissions
sudo find /var/htdocs/your-project/ -type f -exec chmod 644 {} \;
To fix the bootstrap/cache and storage/ permission problem, do
sudo chown -R www-data:www-data /var/htdocs/your-project/
Laravel 5.x
sudo chmod -R ug+rwx /var/htdocs/your-project/storage /var/htdocs/your-project/bootstrap/cache
Laravel 4.2
sudo chmod -R ug+rwx /var/htdocs/your-project/storage /var/htdocs/your-project/app/bootstrap/cache
Then, you should be good.
Doing that way, you can easily move your project from a machine to another without struggling with permission fixes or anything.
More info and source for files and folders permissions command-line instructions, see Laravel 5 Files Folders Permission and Ownership Setup
Go to your project folder add run these commands from terminal
sudo chmod -R 777 your_projrct/storage
sudo chmod -R 777 your_projrct/bootstrap/cache
sudo chown -R :www-data your_project
sudo chmod -R g+s your_project
then php artisan key:generate and composer install
when user/group www-data are unkown; most Linux distributions use apache:
chown -R apache:apache dirname
while on OSX, this would be user/group _www:
chown -R _www:_www dirname
adding the current user to group _www might make life easier, in general.
To isolate your issues:
Get your code into a repository(bitbucket or github)
Clone the repository into your local environment
Run composer install
Run php artisan serve. This way you rule out xampp as an issue.
In your browser go to localhost:8000
If you already have your entire codebase on your local box(including the vendor folder) then skip steps 1 and 2. Step 3 wouldn't hurt, but you can probably skip that too.
Once you get everything working, switch to xampp.
First of all:
composer update
composer dumpautoload
php artisan cache:clear
And then just configure a virtual host
1. Create a local domain for your app
Edit hosts file and redirect all requests from your domain to 127.0.0.1:
127.0.0.1 lara.vel
2. Configure a Virtual Host
Edit \xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost lara.vel:80>
DocumentRoot "C:\xampp\htdocs\laravel\public"
ServerAdmin laravel.dev
<Directory "C:\xampp\htdocs\laravel">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Done! Open up your domain in your browser, You'll see your project there!
The other way is simple, Just run artisan serve.
Please vote up if you found this answer useful.
I think if you copied the project from Ubuntu so it is a permissions problem.
first get users on your Mac machine by typing this in terminal
users
then copy the user you just got for example (username) and use it in this command
sudo chown -R username project-directory
then check for yourproject-directory/bootstrap/cache if it not exists, go create it. else run this command:
sudo chmod -R guo+w project-directory/bootstrap/cache
then
sudo chmod -R guo+w project-directory/storage
then clear composer autoload and cache and config using artisan command
composer dump-autoload
php artisan cache:clear
php artisan view:clear
php artisan route:clear
now try to run the project if the problem still exists,
you need to check config/app.php if it contains Illuminate\View\ViewServiceProvider::class
the view service provider.
if it is not there, so add it
AM using ubuntu linux in my development
I was installing yii2 advanced template via
composer create-project nenad/yii2-advanced-template advanced
Which starts the installation upto the point when the vendor directories are being installed and it fails with the error
After some research i found out that i need to instal global asset plugin via
composer global require "fxp/composer-asset-plugin:~1.2.0"
But now am getting an error of
Changed current directory to /home/myusername/.composer
[ErrorException]
file_put_contents(./composer.json): failed to open stream: Permission denied
I understand its a permission issue and i have
sudo chomd 0777 -R /var/www/html/yii2/advanced
but this havent solved the file_put_content error
I have tried
sudo chmod 0777 -R /home/myusername/.composer
but this also fails
What else do i need to do
Using 777 as permission mask is a bad idea. I'd recommend to use chown command instead.
sudo chown -R $USER:$USER /home/$USER/.composer
This will make composer directory owned by your user and you can use 755 for directories and 644 for files.
To make it clear, what problem composer exactly stumbled upon, try running require command with -vvv option. This allows you to run composer in full verbose mode and get debug information.
composer -vvv global require "fxp/composer-asset-plugin:~1.2.0"
Look into ~/composer folder and doublecheck file permissions and owner with ls -al
I followed the documentation on https://getcomposer.org/doc/00-intro.md#globally to install composer globally on arch linux. When I do composer self-update, I get this message:
[ErrorException]
rename(/home/hannes/.composer/cache/composer-temp.phar,/usr/local/bin/composer): Permission denied
The permissions in /usr/local/bin/ (I changed them to 777, but it did not help):
-rwxrwxrwx 1 hannes users 1104202 30. Mai 18:07 composer
In my home directory I did this:
sudo chmod -R 777 .composer/
In /etc/php/php.ini, the open_basedir looks so:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/usr/local/bin/
I also tried sudo composer self-update but it did not work as well and is possibly not the right way. (?). What else could I try to make this work?
On Ubuntu server >= 16.04
FIRST
sudo rm /usr/local/bin/composer
AND
cd ~/.cache/composer
chmod 755 composer-temp.phar
sudo mv composer-temp.phar /usr/local/bin/composer
this might be the case if you have downloaded composer.phar directly ,
but not by running php composer-setup.php
make composer.phar executable with following command before moving it to /usr/local/bin/composer or after moving
sudo chmod 755 composer.phar
composer-setup.php will make this change for us by default
You should check the permissions of the directory /usr/local/bin/, not just the file within. The process has to write both, the file and into the directory which both must be granted.
Apart from that, a general hint: do not always set everything to 777. There is no reason for that and it makes your system vulnerable.
According to the line you posted in the last comment the directory is currently writeable only for the root user himself. That would explain the error you get. You should not make your own user account the owner, Linux systems are multi user environments. Instead think about one of these approaches:
add the account that is meant to execute the composer to the group root (a user account can belong to several groups) and make the directory group writeable
change the groups ownership of the directory to a group that account is a member of and make the directory group writeable
use the sudo utility to install and update the composer utility
The last option is the typically chosen and preferred one. It leaves permissions as they are (conservative) and only uses raised privileges for system maintenance jobs like installation and upgrade.
Use sudo command for any command which writes to root files of folder. It worked for me.
use sudo "your command"
Even after moving the file via sudo mv composer.phar /usr/local/bin/composer I was getting a permission error when trying to run the composer command. sudo chmod 755 /usr/local/bin/composer fixed things for me.
You could temporarily add the rights to your working user, then update composer w/o errors and then get back the rights.
sudo chmod 777 /usr/bin/
composer self-update
sudo chmod 755 /usr/bin/
Now, there is a package for composer in arch linux which works for me:
sudo pacman -S composer
This did the job for me on Centos 7
chown -R apache:apache path/to/composer
chmod 755 path/to/composer
make sure composer already at /usr/local/bin and then do following things
chmod 755 composer
if permission denied, add sudo
For those who are using shared server here are the steps.
Let's first download composer file.
cd ~
curl -sS https://getcomposer.org/installer | php
Now we can access composer by:
~/composer.phar
Assuming you have /public_html in root directory, here are the steps to use latest composer.
cd public_html
~/composer.phar update
In future, if you want to update composer:
~/composer.phar self-update
Hope this is helpful.
My solution on macOs was the following:
First delete the directory yo created. Somehing like '/usr/local/bin/composer' using this command: rmdir /usr/local/bin/composer.
Now try to install composer again using Homebrew :
Step 1: brew install composer.
Step 2: brew link composer.
Now you can run composer in terminal.
For composer 2
sudo composer self-update --2
For composer 1
sudo composer self-update --1
if permission denied you should use the command with sudo like:
sudo composer self-update
This is going to be easy one I guess. On my OS X - Yosemite I have copied composer.phar to my /usr/bin directory. I have been using it for a while but today I needed to run "composer update". It didnt work of course so I ran "sudo composer update". Then I got the message "command composer not found". Chmm
I copied composer to /usr/local/bin according to the documentation and now "sudo composer" works like charm. BUT when I run "composer" without sudo, it still uses the old one in "/usr/bin" directory. So I deleted it.
Now composer works only with sudo command. I get "Could not open input file: /usr/bin/composer.phar" otherwise. What should I do to point command "composer" to the new location in /usr/local/bin?
Another alternative to get a nice composer command instead of composer.phar:
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin
$ ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
Edit:
/etc/bashrc
Add this to that file:
alias composer="php /usr/local/bin/composer"
run:
source /etc/bashrc
Composer should now run without sudo.
Okay, I encountered issues of having to run composer commands with sudo as well, but in order to get it working without throwing this kind of error (in Ubuntu 15.10):
[ErrorException]
copy(/home/randomuser/.composer/cache/files/barryvdh/laravel-cors/056068736ff8f002514178e1416c7665732eaddc.zip): failed to open stream: Permission denied
What simply solved the issue for me is:
Navigating to my home directory $ cd
Changing the ownership of .composer with: sudo chown -R $USER:$USER .composer/
Then composer install works smoothly.
PS: this might be different for other situation.
Hope this helps :)
i will answer you how i solve it in my Ubuntu 16.10 and you can compare yours
my composer folder set in
/home/abdallah/.composer/
i only give this file the 777 permission so can be reached by any user group
sudo chmod -R 777 /home/abdallah/.composer/
and that is it
i hope this helpful for you
Judging from other answers it seems the solution can vary depending on your system. This is how I fixed the problem on Mac 10.12.
My composer executable in /usr/local/bin/composer had a different group than ~/.composer/ config and cache files.
/usr/local/bin/composer myusr admin
~/.composer/ myusr staff
The primary group for myusr is staff so I changed the group for /usr/local/bin/composer to staff.
/usr/local/bin myusr$ chgrp staff composer
Cache files that had been created when running composer as sudo in the past were still causing problems so I deleted those. Composer cache files are located here: ~/.composer/cache/
If updating hangs during composer update for a project check/empty cache files in the .composer directory for the project.