I'm trying to get my php test upload script to work and was wondering what the command would be to allow files to be uploaded in ubuntu server in the var/www/image directory
What username will be uploading the files? Usually on Ubuntu the Apache web server username is www-data. You can check for sure by finding the web server process in a process list command and seeing which username under which it is running.
ps aux | grep apache or ps aux | grep httpd should give you that answer.
Then you will usually want to make that Apache username the owner of the directory and all files and directories within it:
cd /var/www/image
# recursively (all subdirs & files) set owner to www-data for current directory
chown -R www-data .
Ordinarily, the above should be enough, but if for some reason the directory, files or subdirectories do not have write permission for the owner username, that's easily fixed by changing the permissions to add that write access, like this:
cd /var/www/image
# recursively add "w"rite permissions for the "u"ser (owner) to current directory
chmod -R u+w .
cd /var/www/image
For file like image you don't need execution permission :
sudo chmod 664 *
If you have directories inside image and you want to apply permission :
sudo find . -type d -exec chmod 755 "{}" \;
This will recursively search your directory and chmod 755 all directories only.
Similarly, the following will chmod all files only (and ignore the directories):
sudo find . -type f -exec chmod 644 "{}" \;
File name with space case (thanks to Nicklas B)
find . -type f -print0 | xargs -0 chmod 644
Change edit group to www-data
chown -R (owner):www-data (folder)
And folder permission to 775
cd /var/www
sudo chmod 775 image
You'll be prompted to enter the admin password - do so, and hit [return].
Change edit group may solve most of the problems of permissions.
Changing do www-data and set permission to 775.
Related
Having a nightmare with permissions on RP3, apache2, php
I can run my php api script from terminal with no problems. I use the browser for debugging and get the 'permission denied' when trying to edit text files from the browser.
I have temporarily set permissions to 777 on /var/www but this is insecure, and i can no longer remember the original permissions that were on /var/www
Can i somehow give the broswer (chromium) permission to edit files in /var/www?
I have tried setting inheritance, but to no avail, as i am copying files over all the time, i have to keep resetting the permissions to 777 (which is not ideal), so i can debug the code in a browser.
Any help would be greatly appreciated
Rgds
Mike
Usually, the permissions for folders are 0755 and for folders are 0644.
To set the permissions for folders:
sudo find /var/www -type d -exec chmod 0755 {} \;
To set the permissions for files:
sudo find /var/www -type f -exec chmod 0644 {} \;
Now about the user/group, Apache is probably using the user www-data with group www-data.
To set the user/group for write permissions:
sudo chown www-data:www-data /var/www -R
A note about security: opening up the option to edit the files from the browser is insecure without any login, allowing anyone to edit your files. Also, the write permissions should only be allowed in a directory where the users upload files and NOT for all your /var/www files.
I use Docker for my project. After installing the 2.2.6 package with sample data, it gives me problems like the following when I execute php bin/magento cache:clean
The file "/var/www/html/src/generated/code/Magento/Backend/App/Request/PathInfoProcessor/Proxy.php" cannot be deleted Warning!unlink(/var/www/html/src/generated/code/Magento/Backend/App/Request/PathInfoProcessor/Proxy.php):
No such file or directory
The generated/code folder can not be deleted and I have to restart my computer then it does let me delete the folder
I use php 7.1.22 , percona 5.6.39 and docker Version 18.06.1-ce-win73 (19507)
This happens due to insufficient permissions on the project folder and files.Also www-data must be owner of the project if using Apache as web-server.
Please execute commands given below:--
sudo chown -R www-data:www-data [path to magento directory]
navigate to root of your magento project
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml
chmod u+x bin/magento
An important mania for people who offer their help is to think that all systems are the same.
www-data is the user as long as there are conditions, which many will not meet, because they prefer to use nginx + php-fpm instead of the generalist model.
Other times, included in that model is not the user running Appache, nginx or in the end, php, is www-data.
So the most correct answer is not:
Change the owner of the entire magento folder to www-data
Neither give permissions 777, this is the most common of all the aberrations in the network.
Lo mas correcto serĂa
Who executes the process you write in the magento directory?
PHP writes as user or globally?
I have consulted the configuration of my php (php, php-fpm, etc.) to verify which user is the one that executes the operations?
Once we have that data then if we can execute
sudo chown -R <user_correct>: <group_correct>
And please, stop paying attention to those who always write chmod -R 777
Or one day they will wake up without their site in a normal way but full of infections that are hardly curable.
Installing magento 2 from the command line of the container in Docker solves the problem of writing permissions in Windows for me
You may need to adjust the parameters:
bin/magento setup:install --base-url=http://local.shop.magento2.com \
--db-host=db_magento2 --db-name=magento --db-user=magento --db-password=magento \
--admin-firstname=magento --admin-lastname=magento --admin-email=user#example.com \
--admin-user=admin --admin-password=admin123 --language=en_US \
--currency=USD --timezone=Europe/Madrid --use-rewrites=1
Just in case anyone stumbles upon this:
Add the following to your docker file
RUN echo "root:root" | chpasswd
This will allow you to switch to root and run chown
su root
password:root
chown -R user:group /folder
I was not able to upload any files in filezilla.. so i changed permission of all files under /var/www/html to ec2-user
I ran this command - chown -R ec2-user /var/app/current
After that Filezilla was working but it burnt the apache.
Now wordpress doesnt create any files in wordpress directory. It says it doesnt have any permission. I guess i killed permission of apache on those files. How can revert back the changes? or atleast how can i give the permissions back as it was?
Add ec2-user to apache group :
sudo usermod -a -G apache ec2-user
Logout and Re-login to instance
Change the group ownership of /var/www and its contents to the apache group.
sudo chown -R ec2-user:apache /var/www
To add group write permissions and to set the group ID on future subdirectories, change the directory permissions of /var/www and its subdirectories.
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
To add group write permissions, recursively change the file permissions of /var/www and its subdirectories:
find /var/www -type f -exec sudo chmod 0664 {} \;
Pleae Refer to this AWS Documentation
I have moved my website project to a linux environment and I have an issue assigning permission.
Command that I run:
sudo chown -R admin01:admin01 /var/www/html/counsyl
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
If I set
sudo chown -R admin01:admin01 /var/www/html/counsyl
where admin01 is the username, and this user is not root. I am able to edit the files and folders but the issue is I can't add images or upload plugins etc from the WordPress admin area.
If I run the following command
sudo chown www-data:www-data -R *
It allows me to upload images or plugins etc. But now I am unable to edit the files etc from admin01 account.
So what might be the correct permission so that I can edit the files with admin01 user(not root) and at the same time upload files and folders from the WordPress admin area? I will appreciate if you can give some explanation also so that I understand what I am doing wrong.
Permissions of folders and files inside WordPress folder after running the command
sudo chown admin01:www-data -R /var/www/html/counsyl
Have you tried with 755 permission mate?
chmod -R 755 /var/www/html/counsyl
I think above will help you
Try adding both owner as admin01 and user as www-data. This will help you:
sudo chown admin01:www-data -R /var/www/html/counsyl
Try this, it should work. Structure is like
chown -R USERNAME:GROUPNAME /PATH/TO/FILE
Thank you
Im trying to create a folder (inside www directory) using php script. I did some configurations on UBUNTU, but still not working.
Ubuntu configuration: (user: admin - group: www-data)
sudo adduser admin www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www
PHP code:
function makeDir($dir)
{
$ret = #mkdir($dir, 0700);
return $ret === true || is_dir($dir);
}
Error: Don't create directory.
Reading some other posts, i found this UBUNTu configuration, but still not works:
sudo chmod 777 /var/www
sudo ls -l /var | grep www
sudo usermod -G www-data admin
sudo chmod 770 /var/www
sudo ls -l /var | grep www
Try this:
shell_exec("md $dir");
It usually depends on what user & group the httpd is running with, and if using cgi or apache mod method. The apache's user needs access to create the directory. My solution - usually - is to allow write access to the group. eg running with nobody (the last line sets file access rights)
chown -R :nobody *
chmod -R 770 *
find . -type f -print0 | xargs -0 chmod 640
After this you can simply create directories & files from within php, but you probably need/want to change their rights so you can 'manually' access them when needed via the hosting account.