Write Privileges - localhost - Mac OSX - php

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.

Related

Laravel permissions on nginx

I am deploying a project to Ubuntu on Digital Ocean, using these
instructions.
I am running into permissions issues whereby if I give these permissions
sudo chown -R www-data.www-data /var/www/project/storage sudo chown -R www-data.www-data /var/www/project/bootstrap/cache
I get access to my login page (though a 500 error on every other route), but I also get The stream or file "/var/www/project/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied whenever I try to run php artisan optimize, route:clear, etc.
If I set the permissions to this
sudo chown -R $USER /var/www/project/storage sudo chown -R $USER /var/www/project/bootstrap/cache
I get the opposite problem, wherein I can run artisan commands and write to the log, but no pages are accessible.
Any help would be appreciated
In addition to chmod -R www-data.www-data /var/www/project which sets the group and owner, you might also need to change the specific dir permissions.
sudo chmod -R 775 /var/www/project/storage/
sudo chmod -R 775 /var/www/project/bootstrap/cache
If you're trying to perform operations in your /var/www/project directory on the server, ensure that the user you are logged onto the server as is in the www-data group.
You can check the groups you're in simply by typing groups in your shell. If you don't see www-data in the list returned, add yourself.
usermod -aG www-data $USER
Once you've added yourself to the www-data group you will need to relog for the change to take effect.
You need to change boostrap cache folder and laravel.log file into read, write, and execute. Go to your laravel project, and put this code
sudo chmod 777 bootstrap/cache/
sudo chmod 777 storage/logs/*.log

The stream or file "/var/www/alphacomodate/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

Hello i created a linux server on microsoft Azure to host my Laravel application , it works perfectly on my local machine but it doesn't work on the server. I changed the permission to 0755 but nothing seems to be working. i still get the same error. please can someone give me any suggestions or a suitable alternative.
Thanks in advance
Do not change octal permission numbers. By default Laravel have setted up that. You need to just give the right ownership for "storage/" folder, and for "bootstrap/cache" folder as well for addition. Like this:
# One-time command for your PC
# give sudo-privileges your current username
sudo usermod -a -G www-data $USER
# Here keep in mind that you need to replace "www-data" to the actual webserver name.
# For some many cases it's the "www-data", but it could be "apache", "httpd" etc for other cases for Apache, or something else
#
# Setup ownerships/permissions
sudo chown -R $USER:www-data storage/ bootstrap/cache/
sudo chgrp -R www-data storage bootstrap/cache/
sudo chmod -R ug+rwx storage bootstrap/cache/
For detailed explanation read this

Mac localhost site folder permission issue

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.

Permissions of uploaded files in /var/www

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

How to set root access for all files put inside my Apache2 root directory?

I am learning PHP at the moment on Linux. I have an Apache2 server running locally. Whenever I tried to save a PHP file into the root directory of Apache2 server ( /var/www/html/), I was told that permission denined.
So, I searched around and found that by default, the admininstartor do not have the root access unless explicitly request for it (like sudo su). I have also seen some posts which ask me to use gksu nautilus. However, my linux 14.04 LTS Ubuntu doesn't comes with it. (I know I can use apt-get gksu but at the moment, downloading it from internet is not an option).
Is there anyway that I can change the permission to my Apache2 server root directoy so that I can use any text editor to save/edit to that directory directly. Only the ways that do not need downloading stuffs from internet are feasiable for me at the moment.
For linux open the terminal with root login then go to the root folder and run the following command chmod 777 following is the example :-
To change all the directories to 777 (-rwxr-rwxr-rwxr):
find /opt/lampp/htdocs -type d -exec chmod 777 {} \;
To change all the files to 644 (-rwxr-rwxr--rwxr--):
find /opt/lampp/htdocs -type f -exec chmod 777 {} \;
If this will not work then try the following :-
Create a new group
groupadd webadmin
Add your users to the group
usermod -a -G webadmin user1
usermod -a -G webadmin user2
Change ownership of the sites directory
chown root:webadmin /var/www/html/
Change permissions of the sites directory
chmod 2775 /var/www/html/ -R
Now anybody can read the files (including the apache user) but only root and webadmin can modify their contents.
Hope this will help you in solving your problem.
You can set the DocumentRoot in your /etc/apache2/httpd.conf file to a place where Apache has write access. For example, you could set it to /tmp/www if you made a directory there. (If you still don't have access, you can always give everyone read access by running chmod a+r /tmp/www, but you should probably be fine.)
Obviously leaving your Apache Document Root as /tmp/www is a bad idea, so you can change it to something like /home/chris once you've got it working.
One important note: after you make a change like this, you must restart the Apache server. This can be done by running apachectl restart; ironically, you might have to have administrator rights in order to execute this (or even edit the config file in the first place), so make sure you prefix your edit & restart with sudo just in case.

Categories