I have a localhost set up on my sites folder on a mac which lets me use php, mysql, phpMyAdmin and all sorts of goodies. But I have an issue when my website creates folders or files. All the permissions for _www are 'read only.' When I use a php function such as mkdir("folder path");, it creates folders with permission of 'read only'. How can I configure my sites folder to have 'read & write' permission for every file created or placed in sites folder?
Thank you community!
To activate read/write permission either for you and Apache in global Apache Document Root, do this in Terminal application:
sudo chown _www:_www /Library/WebServer/Documents
sudo chmod 0775 /Library/WebServer/Documents
sudo dseditgroup -o edit -a username -t user _www
To activate read/write permission either for you and Apache in your personal Document Root, do this in Terminal application:
sudo chown _www:_www /Users/username/Sites
sudo chmod 0775 /Users/username/Sites
sudo dseditgroup -o edit -a username -t user _www
Please note: Change username above with your short username.
By these commands, you:
set the owner of directory to user _www (Apache) of group _www;
set permissions of directory to read/write/execute to owner and group members, read/execute for others (you can type 0770 to others/none permission or 0771 to others/execute only);
add you to group _www.
Related
I am confused with file permission and their uses by Linux.
Web server : Apache,
OS : Ubuntu 16.04 LTS
I have a file test.php in /var/www/html/ folder with permissions 644 and owner and group as root. Now, this files does some internal routine work related to database, i.e. it interacts with database and this file is executed through cron job. Now, when I requested for this file through browser by putting www.example.com/test.php, then, to my surprize, the file got executed and did all the job with the database.
Now, here I have some points of confusion.
test.php file was compiled and executed, and for its execution I should set execute bit in the permission, which was not set actually.
When browser requested the file, it sent the request to apache, which is www-data user and this user executed this file. But the owner and group of the file was root. Also, other users except file owner and group have only read permission, then how was it executed.
Note : Even when I gave permission as 000 with root as owner and group then also file got executed when requested through browser.
files 664 and folder 755 and user and group www-data.
$ sudo chown -R www-data:www-data /var/www
$ sudo chmod -R 755 /var/www
And test to http://localhost/test.php
I user my personal user, then add my user to group www-data and change permission to folder 775 and filers 664. and owner personaluser:www-data
$ sudo usermod -aG www-data personaluser
$ sudo chown -R personaluser:www-data /var/www
$ sudo chmod -R 775 /var/www
www-data is a user/group that run the apache. So www-data execute (Interpreter ) the code.
For access with domain "example.dev" or other you have use a virtualhost. Check this: https://www.digitalocean.com/community/tutorials/como-configurar-virtual-hosts-de-apache-en-ubuntu-16-04-es
I'm using WordPress on centos 6.
I try to install a plugin. But I got this error:
Installing Plugin: bbPress 2.5.9
Downloading install package from https://downloads.wordpress.org/plugin/bbpress.2.5.9.zip…
Unpacking the package…
Could not create directory.
How can I resolve this?
P/S: I run this command:
sudo -u root touch /var/www/html/wordpress/wp-content/plugins/test.txt
and it works. But I still get that error.
You only need to change the access permissions for your WordPress Directory:
chown -R www-data:www-data your-wordpress-directory
You can fix this by using the following commands. You should first be in the root folder of Wordpress.
sudo chown -R www-data:www-data wp-content/plugins/
sudo chmod 775 wp-content
sudo chown -R www-data:www-data wp-content/
The user that is running your web server does not have permissions to write to the directory that Wordpress is intending to create the plugin directory in. You should chown the directory in question to the user that is running Wordpress. It is most likely not root.
In short, this is a permissions issue. Your touch command is working because you're using it as root, and root has global permissions to write wherever it wants.
A quick solution would be to change the permissions of the following:
/var/www/html/wordpress/wp-content
/var/www/html/wordpress/wp-content/plugins
Change it to 775.
After installation, don't forget to change it back to the default permissions.. :D
I had to give ownership of /plugins and /upgrade to the server, nothing else.
$ cd /var/www/wordpress/wp-content
$ sudo chown www-data:www-data /plugings
$ sudo chown www-data:www-data /upgrade
Running Apache server on Ubuntu 18.04. Maybe more dirs will need to be changed later. Anyways, I plan to restore permissions once I finish editing, as suggested in this anwser.
If you have installed wordpress using apt, the config files are split in multiple directories. In that case you need to run:
sudo chown -R -h www-data:www-data /var/lib/wordpress/wp-content/
sudo chown -R -h www-data:www-data /usr/share/wordpress/wp-content/
The -h switch changes the permissions for symlinks as well, otherwise they are not removable by user www-data
To solve permission issue on plugins and themes on localhost or production quickly, you just run this
sudo chmod 757 wp-content/themes
sudo chmod 757 wp-content/plugins
if take care permission on production, you can run
sudo chown -R www-data:www-data wp-content/themes
sudo chown -R www-data:www-data wp-content/plugins
If you are mac user , using XAMP
Go to the htdocs folder and open the terminal on the folder , as shown in the screenshot
Then Type the following command on the Terminal
**sudo chmod -R 777 <your wordpress folder Name>/**
E.g sudo chmod -R 777 wordpress/
CentOS7 or Ubuntu 16
1.
WordPress uses ftp to install themes and plugins.
So the ftpd should have been configured to create-directory
vim /etc/pure-ftpd.confg
and if it is no then should be yes
# Are anonymous users allowed to create new directories?
AnonymousCanCreateDirs yes
lastly
sudo systemctl restart pure-ftpd
2.
Maybe there is an ownership issue with the parent directories.
Find the Web Server user name and group name if it is Apache Web Server
apachectl -S
it will print
...
...
User: name="apache" id=997
Group: name="apache" id=1000
on Ubuntu it is
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
then
sudo chown -R apache:apache directory-name
3.
Sometimes it is because of directories permissions.
So try
sudo chmod -R 755 directory-name
in some cases 755 does not work. (It should & I do not no why) so try
sudo chmod -R 777 directory-name
4.
Maybe it is because of php safe mode.
So turn it off in the root of your domain
vim php.ini
then add
safe_mode = Off
NOTE:
For not entering FTP username and password each time installing a theme we can configure WordPress to use it directly by adding
define('FS_METHOD','direct');
to the wp-config.php file.
If anyone using shared hosting and get same problem it may be disk space issue. In that case contact with your hosting support and ask them to increase disk space of your acocunt.
You need to change the permission of the directory
At first change the user HTML folder (replace yourcomputerusername)
sudo chown yourcomputerusername:yourcomputerusername /var/www/html
Next change the permission for the user
cd /var/www/html
sudo chmod -R goa=rwx wordpress
or
sudo chmod -R 777 wordpress/wp-content
I was on XAMPP for linux localhost and this worked for me:
sudo chown -R my-linux-username wp-content
What I end up doing is every time I create a WordPress project. in /www/html
I run below command
sudo chown www-data:www-data wordpress_folder_name -R
hope this will help someone.
For me the problem was FTP server that WP is using to upload update. It had writting disabled in configuration, so just enabling it fixed the problem.
Shame on WordPress for providing such misleading error message.
You could try
sudo chmod goa=rwx -R /var/www/html
None of the above work for me except this one.
sudo chown daemon:daemon /opt/bitnami/apache/htdocs/
Don't forget to change /opt/bitnami/apache/htdocs/ to your directory
Webserver user must have write access to directories to perform such operations, so you can try to change owner of files to webserver user (apache in this example, but can be differ from yours)
chown -R apache YOUR_BLOG_DIRECTORY
If you are using some app that wraps http, you have to set these user in the command.
sudo chown -R [desireduser]:[desireduser] wp-content/
By example, if you are using lampp, the users that init httpd is "daemon" and the command that works will be:
sudo chown -R [desireduser]:[desireduser] wp-content/
You can search in your httpd.conf file
To solve permission issue on ubuntu server, you just run this
sudo chmod 777 -R 'wordpress wp-content file location'
for example.
sudo chmod 777 -R /usr/share/wordpress/wp-content
wordpressProject is the project name.
/var/www/html/wordpressProject sudo chmod -R 777 wp-content
Thanks. It will work.
Absolutely it must be work!
Use this
chown -Rf www-data:www-data /var/www/html
I have a picture folder in the website directory and every time i upload pictures into that directory, they have the wrong permissions and i have to manually change the permissions so that i could alter the images or rotate them, delete, copy etc. Is there a way to automatically change the permissions of the uploaded files in that specific folder. May be there is some permission field in Apache configurations that can be changed. Please help!
Thank you.
Most likely the user running the webapp is www-data (for ubuntu/debian based OS). If the user you are logging in to your box is a different, the best you can do is to setup a group and make that group own /var/www - or only the folder you really need. The group should hold the both users:
add a group:
sudo groupadd <name of the group> // whatever you prefer
Now that the group exists, add the two users to it:
sudo usermod -a -G usergroup <your username> // the one you login with
sudo usermod -a -G usergroup www-data
Now all that's left is to set the permissions on the directory:
sudo chgrp -R usergroup /var/www
sudo chmod -R 775 /var/www
Now only members of the usergroup group can read, write, or execute files and folders within the directory. Note the -R argument to the chmod and chgrp commands: this tells them to recurse into every sub directory of the target directory and modify every file and directory available.
Please note that group assignment changes won't take effect until the users log out and back in.
You can use chmod in PHP to change the permissions.
http://php.net/manual/en/function.chmod.php
Hi anyone can help me for this issue , I have developed a site and it is hosted on my development server but now my client wants to move it to his own production server, and my client doesn't have access to his cpanel for this server. I only have the ftp access, so I have added his database in my own development server, while in development I used my amazon s3 for storing the images , when I push to production I loss the amazon plugin . I can't able to install the plugin , so I moved to upload once again to those images through WordPress, now I face this error while uploading an image : Unable to create directory wp-content/uploads/2014/07. Is its parent directory writable by the server? , and change the ftp file permission access to 755 and changed the uploads file permission to 777 , Still I am not able to upload the images, can some one help me for this issue.
This is a problem of the Apache permissions. I had this problem and i broke my mind for many days to understand what was happening.
The correct way (USE IT):
(the solution that i used, and worked)
You need to give Rewrite permissions to the Apache.
For Ubuntu:
Run via ssh: chown -R www-data:www-data /var/www/the/wordpress/directory
For Centos:
Run via ssh: chown -R apache.apache /var/www/the/wordpress/directory
The Wrong Way (I don't recommend it, but works...)
You can change the permissions to 777 in all the paths that Wordpress need to change. wp-content/plugins recursively on folders to solve install/update problems, and wp-content/uploads recursively on folders to solve upload media problems.
Never use it because you are giving permissions to anyone change your files. A open way for the crackers that don't like you.
run these command to provide proper file permissions
Add existing 'ubuntu' user to 'www-data' group
sudo usermod -a -G www-data ubuntu;
Set the ownership of the files/directories
sudo chown -R www-data:www-data /var/www/html/;
Set group ownership inheritance
sudo chmod g+s /var/www/html/;
Set the permissions of the files/directories
sudo find /var/www/html/ -type d -exec chmod 755 {} ;
sudo find /var/www/html/ -type f -exec chmod 644 {} ;
Give write permissions to the group (for editing files via FTP)
sudo chmod -R g+w /var/www/html/;
I'm new to the mac world and have just been setting up my webserver. I used the following guide: https://alan.ivey.dev/posts/2011/os-x-10.7-lion-development-native-mamp-with-mysql-installer/
I've transferred my sites and databases and everything is going pretty well. The only problem I have is with the writing permissions. For example there is a config file that needs to be written to, and I had to right click, go to Get Info then enable read & write for staff and everyone.
I can't manually go through and enable these write privileges for every file/folder. I didn't need to do this using WAMP and made development much quicker.
So wondering about 2 possible solutions:
a) add my user account to a whitelist for the localhost so that 644 privileges are sufficient
b) set the write privileges recursively
I found the best solution was to change the apache user and group settings. The instructions can be found at: http://paulmason.name/item/change-apache-user-group-in-lion-os-x
Open Terminal and Enter
sudo nano /private/etc/apache2/httpd.conf
Find and change http.conf code from
User _www
Group _www
To
User your_mac_username
Group staff
Note: With earlier versions such as Leopard, capitalize staff to Staff. You can get your username and group by typing "id" and hitting enter in terminal
Restart Apache
sudo apachectl restart
I'm the author of the mentioned blog post. For web server file permissions, you'll want to give write access to the _www user for files. For config.inc.php, you would set it a couple ways:
Have _www own the file and have write permissions:
$ sudo chown _www config.inc.php
$ chmod u+w config.inc.php
Have your user own the file, change the group to _www, and give group write permissions:
$ sudo chgrp _www config.inc.php
$ chmod g+w config.inc.php
Or, if you feel comfortable allowing all users to write, which I would not recommend for security reasons, give all users the ability to write:
$ chmod a+w config.inc.php
If an entire folder needs to be written by the _www user, it can own the folder and all files:
$ sudo chown -R _www:_www folder/
or you can give the folder write and execute permissions by all:
$ chmod a+wx folder/
The reason why chmod 774 gave you forbidden errors was because the _www user fell under the '4' permission, which is 'read-only.' For directories, a user needs 'execute' in order to traverse into the folder. chmod 775 would allow user and group to rwx, and others to r-x. Here's more information on Unix file permissions.
Also, your user could retain full ownership and add certain permissions for the _www user instead of changing the level of access for ALL users by using Access Control Lists.
$ sudo chmod -R +a '_www allow read,write,delete,add_file,add_subdirectory,file_inherit,directory_inherit' folder
$ sudo chmod +a '_www allow read,write' config.inc.php
If you're going to go the route of ACLs, I'd suggest doing some more reading to see what levels of access you really need to provide. Here is a great place to start.
I'm running Apache on OSX and this fixed it for me:
sudo chown -R _www:_www <mywebfolder>
sudo chmod -R 775 <mywebfolder>
Update #1:
Syntax: sudo chown <user>:<group> <file-or-folder>. The Apache user on OSX is _www.
To keep ownership but give Apache r-w-x permissions:
sudo chown -R <your-username>:_www <mywebfolder>
sudo chmod -R 775 <mywebfolder>
Update #2:
I like this method best. Set Apache to run as you.
In terminal type id to get uid=123(Myname).
Open /etc/apache2/httpd.conf and edit it to use your username.
<IfModule unixd_module>
User Myname
Group staff
</IfModule>
Back to terminal: sudo apachectl restart
I recommend settings the Write privileges recursively for your web root.
You can do this via the console / terminal using chmod -R 774 /my/web/root. For me, the owner and group is set to: www-data:myUserName, which can be set by using chown. Don't forget to check who's your web user first.
Edit: For better understanding, why you don't have access:
Chmod 774, each number stands for specific rights: user, group, others. If the user is set to www-data and the group to www-data (most users on a Unix system are in a group that's named by their username). So, if you're not in the group www-data you either have to join it, or you have to change owner (chown) or you have to change the permissions (chmod). There are several tutorials out there, for more information.
Above solutions didn't work for me. What I did was :
Right click the folder -> Get Info
There is a priviledge setting at the very bottom.
Change it to Read & Write for Everyone.