Can't install Magento due to permissions, what am I doing wrong? - magento

I've run the following commands on my Magento directory on Ubuntu Server.
chmod 0777 var/.htaccess
chmod 0777 var
chmod 0777 app/etc
chmod -R 0777 media
However, now the Magento installer is still complaining with:
Path "/var/www/store/var/package" must be writable.
I tried:
chmod 0777 var/package
With no luck.
I've also tried this guide for resetting permissions, still without any luck. What am I doing wrong?

You should set permissions recursively:
chmod -R 0777 var

Related

FIle could not be opened in append mode: failed to open stream: Permission denied laradock

I'm setting up laradock (Setup for Multiple Projects) following the official documentation from the Laradock in my local machine.
After installation I installed the laravel through workspace container bash. I did configured the config file for the app in nginx/sites/ directory and in /etc/hosts file.
While visiting the development url I'm getting the following error message:
The stream or file "/var/www/laravel-api/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
This worked for me:
chown -R www-data:www-data "project foldername"
If you are still facing the issue even after changing the permission and owner of file, just check for the OS of you Linux server.
Login to your server
$ ssh user#server-ip
check your OS running on linux server
$ cat /etc/os-release
//output
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
If it is CentOS, you need to disable Security-Enhanced Linux (SELinux) if enabled.
Check for SELinux status
$ sestatus
If it is enabled, then
$ setenforce Permissive
Or
$ sudo setenforce 0
Have a good day!
you have to enter the workspace first by typing "docker-compose exec workspace bash"(without quotes)
To give a write permission to a single file,
chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
or
chmod -R 777 /var/www/laravel-api/storage/logs
or
sudo chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
when the same error appears but different folders or files, do the same thing only change the folder name
example :
chmod -R 777 /var/www/laravel-api/storage/logs
chmod -R 777 /var/www/laravel-api/storage/framework/views
chmod -R 777 /var/www/laravel-api/storage/framework/sessions
If you aren't running your application as root on your web server, then it wont have write access based on the permissions you've provided.
Checked from workspace container bash. storage/logs/ directory has drwxr-xr-x 2 root root 4096 Aug 1 07:37 logs
The error is complaining about permission denial for opening in append mode - it doesn't have permission to write to the file, only root does.
What you need to do is make your web server group the owner of the storage directory:
chown -R www-data:www-data /var/www/laravel-api/storage/
The www-data can be switched out for whatever group your web server is associated with.
To avoid completely repeating an amazing and complete answer, I recommend you give this answer a read:
How to set up file permissions for Laravel?
Give group write access to /storage/logs/
sudo chmod g+w storage/logs
You need to run the following command. It works for me:
step 1:
sudo chmod -R +rwX .
step 2:
sudo chown -R $(whoami) .

"storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied

I got the following error when entering my site on a production server:
The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied
I tried running the following commands and got Permisions denied in the terminal:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan optimize:clear
I ran chmod -R 775 storage/logs/ and composer dump-autoload and I was able to get onto the home page of my site without any errors. After surfing around the site a bit more I was getting the same error in various areas and not in others:
Again same error
The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied
I deleted the following files and ran php artisan cahce:clear:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php.php
The only other advice I've seen is run:
sudo chmod -R 777 storage/*
Which seems like a bad idea on a production server, but seems to be upvoted answer. Should I just give my storage director 777 permissions and why? Is there another way of fixing this?
Edit:
I'm trying to do this as stated here:
// set current user as owner and the webserver user as the group
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
// set directory permission to be 775
chmod -R 775 storage
chmod -R 775 bootstrap/cache
but when I run sudo chown -R $USER:www-data storage I get this error:
chown: invalid group: ‘myusername:www-data’
Alright I got the answer:
AWS AMI uses webapp as the web user, not apache or ec2-user as the file shows. In that case, the webapp user has no access rights over those files.
sudo chown $USER:webapp ./storage -R
find ./storage -type d -exec chmod 775 {} \;
find ./storage -type f -exec chmod 664 {} \;
Using the console, go to your synced folder (vagrant)
sudo chown -R $USER:www-data storage
chmod -R 775 storage

Chown directory via SSH on server using NPM script

I am trying to chown a directory via an NPM script. The script looks like the following:
chown -R 755 www-data root#XXX.XXX.XXX.XX:/var/www/test.com
But the message I get back is: chown: www-data: No such file or directory even though this exists. Any ideas much appreciated.
chown operates locally, not on remote servers. In your example, chown is attempting to operate on ./www-data and ./root#XXX.XXX.XXX.XX:/var/www/test.com, which don't exist in the directory of wherever you were when you executed the command.
You will need to execute chown as a command through ssh:
ssh root#XXX.XXX.XXX.XX chmod -R 755 /var/www/test.com/
Fixed this with following script.
ssh root#XXX.XXX.XXX.XX chmod -R 755 /var/www/test.com/
(I needed to login to the server first).

Permission denied on file transfer

I have a new instance and everything was going fine, I have the site installed and transferred over my database and uploaded most my wordpress file to the server.
But towards the end of my upload, files stopped being uploaded and I keep getting the message
***Error: Directory /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: no such file or directory
Command: cd "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Response: New directory is: "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Command: mkdir "01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied
Command: mkdir "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied***
I've tried changing the permissions to 755 or 644 but get this error
***Status: Setting permissions of '/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07' to '644'
Command: chmod 644 "07"
Error: set attrs for /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07: permission denied***
Video file transfer: https://www.screencast.com/t/d8BbFnxkp
Video permission fail: https://www.screencast.com/t/2XBr6zwqd
I'm just puzzled why the other transfers worked
Thanks for your help.
I found this solution that appears to work.
sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
sudo chmod -R 775 /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
Then, you can try to upload and check if it works. If it doesn't, you can try doing this instead:
sudo chown -R daemon:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
In my case I had this problem while publishing my application from JetBrains Rider to Ubuntu server via SFTP. As there is no way to use sudo, the easy solution was to set publish folder ownership for user, specified in ssh connection for SFTP.
sudo chown -R username:username /var/www/your-app-publish-folder
Or, if you are already logged in under this user on server:
sudo chown -R $USER:$USER /var/www/your-app-publish-folder

Showing error "Connection string is empty" in magento

When i am installing an extension in my magento admin,it shows Connection string is empty.
I don't know why this problem occurs. I cleared the cache also then also the problem is same.
If anyone knows how to do this,please help me out.
Thanks!
To solve this problem, follow the steps below (I suppose you are using Ubuntu):
1) sudo chmod -R 777 /var/www/html/magentoInstallationFolder/
2) Install Magento Extension
3) Restore correct permissions for directories and files respectively
sudo find /var/www/html/magentoInstallationFolder/ -type d -exec chmod 775 {} \;
sudo find /var/www/html/magentoInstallationFolder/ -type f -exec chmod 664 {} \;
Read more about why 777 permissions are bad and you need to restore good permission code (775) after you install the extension: https://askubuntu.com/a/30635
Magento tries to put the maintenance flag in the root directory. Here is the code that does it:
<?php
//downloader/Maged/Controller.php::startInstall()
if ($this->_getMaintenanceFlag()) {
...
//downloader/Maged/Controller.php::isWritable()
$this->_writable = is_writable($this->getMageDir() . DIRECTORY_SEPARATOR)
If you can't change magento root directory permissions just uncheck "Put store on the maintenance mode while installing/upgrading/backup creation" flag.
There's a couple of suggestions to change the permissions to this:
sudo chmod 777 -R /var/www/html
Which is a really really bad idea. Have a search for 'Magento permissions' and follow the guide instead. Unless you're seeking to get your site hacked wihin a few minutes.
Have to change right recursively (chown -R) to www-data:www-data on a directory containing magento (example : /var/www/magento)
Sorry for bad engish
chown -R www-data:www-data /var/www/your_magento_folder
That did the tick for me, don't change the owner of the www folder
Type the following command in your terminal.
sudo chmod 777 -R /var/www/html/<magento folder name>. Press Enter.
Then it will ask for password if exists for your username.
Once it is done, login and logout the admin and try to install extension which you want
Edited:
Try this for your files:
sudo chmod 777 -R /var/www/html
and follow the above steps.

Resources