Mac OSX Apache Write Privileges [closed] - php

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
So here is my problem. Its started when I discovered that I couldn't install plugins or themes in WordPress from the admin panel, it just kept asking for my connection info ( http://cl.ly/DLdH/o ).
I found a blog post which suggested changing the ownership of the wordpress folder to the Apache user, i.e. _www like so
sudo chown -R _www ./
That did, partially, fix the problem as I was able to install plugins and themes as well as writing to the directory through PHP which was all good but then I couldn't add/delete/edit any of the files in my text editor or even in Finder. It just keeps asking for my user password in order to process the action.
Changing the ownership back fixes the password issue but then I cant do any writing to the directory though PHP anymore.
Is there a way to allow me do both things at the same time?
EDIT:
I came across this cmd
sudo dscl . -append /Groups/_www GroupMembership [myUsername]
which added me i.e. my username to the group _www, then I executed
sudo chown -R _www .
sudo chgrp -R _www .
then it worked!

Have the user own the files. Change the group to _www. Give write permission to group.
chown -R <username> .
chgrp -R _www .
chmod -R g+w .

Related

Is it safe to give ownership of files to "daemon"? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I am running apache2 in Ubuntu 14.04. I have been having trouble with permissions with FTP clients and CMS that use backend FTP. I never seem to be able to get the permissions right. Should www-data be the owner of /var/www/html and root as a user assigned to that group?
Some CMSes and Wordpress is especially bad about that because it's actually in the code to use the web user.
BTW you should never need to use root for ftp. www-data the default apache user on ubuntu should own your web files/directory to work properly with many cmses.
So this is what has worked before and what we did for clients with the same issue. chown the whole web root as www-data for both user and group.
So if your document root is /var/www/html, cd or change directory to /var/www and run this to change ownership on all files and directories.
chown -R www-data: html/
while still in the /var/www directory add write permissions to the group for files and directories by running this command.
find html -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
Finally add your FTP user to the www-data group.
usermod -a -G www-data username
Replace usename with your FTP client username
Now this setup should allow you to use manage files and still allow the CMS ftp backend to still function and write to the direc. Let me know how that works for you.
This command worked for me:
sudo chown $(whoami) your_folder_name

chown on mapped CIFS share not working [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have mapped to a Windows share using cifs/samba on CentOS. Using this command:
sudo mount -t cifs -o username=Username //path/to/share /var/share
My PHP application now needs the ability to create directories and upload files to /var/share (which is now the mapped cifs share). All of the files there all belong to root:root. When I attempt to do a chown to change the files to apache:apache, there are no errors thrown by Linux, but when I do an ls -l, it still shows the owners to be root:root.
Is there a way to get around this so my app can write to the share?
The username in your mount command is the "Windows" username, with the authentication being managed by Samba. By default, the exported volume has everything owned by root. What you need to do is to specify the *NIX user and group names in your mount command. Here's what I do to mount my Mac on my Ubuntu box, using Apple's CIFS implementation:
sudo mount -t cifs //192.168.1.3/Shared /media/Shared -o username=mike,password=XXXX,uid=1000,gid=1000,nounix,sec=ntlmssp
You can use textual names instead of numbers for the uid and gid. the "nounix,sec=ntlmssp" is needed for compatibility with recent versions of the Mac OS X CIFS server.

You don't have permission to access /folder/index.php on this server. Apache/2.2.22 (Ubuntu) Server at localhost Port 80 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am using ubuntu 12.04
When I am running my index file like"localhost/index.php" its working fine.
at the same time when I am running my script like "localhost/mypage/index.php" then it return a error called
You don't have permission to access /mypage/index.php on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
Please help me to overcome the problem ../thanks
Assuming you have your files in /var/www and have installed the default stack that Ubuntu provides, the proper way is to add your user to the www-data group and then chown that folder. Open a terminal and type:
sudo useradd -g www-data myuser
sudo chown -R www-data /var/www/
Perhaps the web user doesn't have permission to access sub-directories? You can CHMOD/OWN to the user apache run's as?
Find out the user read this article: https://stackoverflow.com/questions/2509334/finding-out-what-user-apache-is-running-as
Using CHMOD:
sudo chmod -R /folder/path/
sudo chown -R _www_user:_www_group /folder/path

Windows: Setting PHP file permissions before deploying to Amazon Beanstalk

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 14 hours ago.
Improve this question
I've recently converted over to Amazon's Elastic Beanstalk which has been great but I have one problem I haven't been able to fix or find a decent solution to.
When deploying via GIT with
$ git aws.push
My files are deployed but all my folders and files do not have the correct permissions. Currently running Win 8 with xampp for local development. For example on a recent WordPress deployment, all my folders were 777 once deployed to beanstlak. It is an NTFS partition the files are in too.
It is easy enough to SSH in and run:
$ sudo su
$ find /var/www/html/ -type d -exec chmod 755 {} \;
$ find /var/www/html/ -type f -exec chmod 644 {} \;
However I'd rather fix my permissions before upload however I don't think this is possible with Windows. I'm sure I can setup a script or some type of service hook to run these on deployment but I was hoping there may be an easier way.
Any insight from the SO community on setting windows file permissions to match Apache's?
It's actually not that hard to setup a hook to fix the permissions after your code is extracted onto your instance(s) but before it is considered "deployed". You could create a file called .ebextensions/00permissions.conifg, the name isn't important as long as it's in the right folder with the extension .config - the config scripts execute in alphabetical order. The contents would be like:
container_commands:
00fix_permissions_dirs:
command: "find . -type d -exec chmod 755 {} \;"
ignoreErrors: true
01fix_permissions_files:
command: "find . -type f -exec chmod 644 {} \;"
ignoreErrors: true
Note the default directory for a container_command is the directory the deploy files have been extracted to, so no need to set an explicit path.
You can see more info about the kinds of commands you can run on your instances in the Elastic Beanstalk documentation.
container_commands:
00fix_permissions_dirs:
command: "find /var/app/ondeck -type d -exec chmod 755 {} \;"
ignoreErrors: true
01fix_permissions_files:
command: "find /var/app/ondeck -type f -exec chmod 644 {} \;"
ignoreErrors: true
This will change the file permissions of the application. Currently there is no way to run commands when the app is fully deployed, but you can take advantage of the "ondeck" folder which is the folder where beanstalk put your app files before deploying them.

Write Privileges - localhost - Mac OSX

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.

Categories