Cannot composer dump-autoload - file put contents error? - laravel

I'm trying to:
composer dump-autoload
On a Ubuntu 16.04 server.
I get the error:
file_put_contents(/var/www/example.com/site/vendor/composer/autoload_namespaces.php): failed to open stream: Permission denied
I have:
Change permission of storage dir to 755
Made sure the www-data user has correct usage rights
I still get the error. Any ideas on a fix?

First of all
After installing Laravel, you should change the permission of some specific directory.
Use these commands.
// If your project's directory is owned by root then,
sudo chown -R <username> path_to_laravel_project_directory
// Then change these persmissions (from the root of the laravel project directory)
sudo chmod -R 777 storage/
sudo chmod -R 777 bootstrap/cache/
// At the end please generate your project key
php artisan key:generate
// Now you can use
sudo composer dump-autoload
I hope this works.

Try to set these permissions:
sudo chmod -R 755 bootstrap/cache/
sudo chmod -R 755 vendor/composer
sudo chmod -R 755 storage

Related

ErrorException failed to open stream: Permission denied on composer install

I had a laravel app on github and I want to clone on other computer .
After I cloned the repository and run composer install command it shows me this error:
[ErrorException]
copy(/Users/cosminciolacu/.composer/cache/files/symfony/debug/824e1c185cf2cd
10402999589458f4be7ef980e1.zip): failed to open stream: Permission denied
what I missed?
You may need to change the ownership and permissions of the directory you have installed the project in.
cd /path/to/project
sudo chmod -R 775 .
sudo chmod 660 .env
If the first answer did not work, do sudo composer install instead of composer install.
Warning: well, said in comment section.

Error on php artisan migrate, Illuminate\Database\QueryException

I try to do php artisan migrate , but I get an error.
I check the database,user name, password, I tried with sudo, but nothing worked.
I found out the solution.
First thing: (to access laravel.log)
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Second one:
sudo apt install php7.2-pgsql

Im getting an error "No such file or directory" when installing Composer Globally

I am trying to install Composer globally but I get an error when I do
sudo mv composer.phar /usr/local/bin/composer
The error reads
mv: composer.phar: No such file or directory
When I try and instal Laravel
composer global require laravel/installer
And after I try to run
Laravel
I get
zsh: command not found: laravel
After composer is installed, I used the following command to create a alias for the composer file. So now its running globally.
alias composer='/usr/local/bin/composer'
Now can try to run
composer
From the docs:
To quickly install Composer in the current directory, run the following script in your terminal.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
You can place the Composer PHAR anywhere you wish. If you put it in a directory that is part of your PATH, you can access it globally.
After running the installer following the Download page instructions you can run this to move composer.phar to a directory that is in your path:
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, you may need to run it again with sudo.
sudo mv.composer.phar /usr/local/bin/composer
Note: On some versions of macOS the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create the directory manually before proceeding:
mkdir -p /usr/local/bin
Note: For information on changing your PATH, please read the Wikipedia article and/or use your search engine of choice.
after installing composer as stated above, you have to move the composer.phar to the /usr/local/bin directory. to do this, first create the new directory by running the command:
sudo mkdir -p /usr/local/bin
after that, move the composer.phar to the new path with:
sudo mv composer.phar /usr/local/bin/composer
This command worked in creating a new directory:
sudo mkdir -p /usr/local/bin
After I moved the composer.phar to the new directory using :
sudo mv composer.phar /usr/local/bin/composer
This command didn't work for me:
alias composer='/usr/local/bin/composer'
sudo mv composer.phar /usr/bin/composer

Laravel error when creating new project: proceed without cache

I'm just starting with laravel. I'm following this laravel guide. My environment is an aws server running php 5.6, I have already installed composer.
https://laravel.com/docs/5.2/quickstart#deleting-tasks
When I type:
composer create-project laravel/laravel quickstart --prefer-dist
I get the following error:
Cannot create cache directory /home/ubuntu/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
How can I fix this? Is this a major problem? If I proceed would I run into trouble after?
Also, is it bad practice to use sudo?
When you installed composer pretty sure you used $ sudo command because of that the ~/.composer folder was created by the root.
Run this to fix the issue:
$ sudo chown -R $USER $HOME/.composer
You can try this method which I used for my project on a LAMP server
sudo composer create-project laravel/laravel quickstart --prefer-dist
After that, you change the permission back to www-data user & group
sudo chown www-data:www-data quickstart\ -R
sudo usermod -a -G www-data ubuntu_user_name

Why does Composer create-project execution for Laravel fail?

It appears that unless I use sudo my composer command fails to create a Laravel project.
Without sudo it gives me the following error:
[ErrorException]
copy(/Users/H/.composer/cache/files/laravel/laravel/73094f2633f1b90f3ef
6de4a8a5b610532510e0e.zip): failed to open stream: Permission denied
What am I missing here?
If you ever execute:
sudo composer <anything>
Some of your composer home files (~/.composer/) will be written by the root and if you can't delete or write over them again unless you use sudo to become root, so you have 2 options:
1) Change the user of those files back to your own:
sudo chown $USER:$USER -R ~/.composer
Or on a mac
sudo chown -R $USER:staff ~/.composer
2) Delete the whole folder (and lose your cache) to restart from scratch:
sudo rm -rf ~/.composer/cache
or even
sudo rm -rf ~/.composer

Resources