From Boldcore's wiki
Jump to: navigation, search
Line 8: Line 8:
  
 
== Solution ==
 
== Solution ==
1. Create special user for web content management (for example admin)
+
* 1. Create special user for web content management (for example admin)
2. Change his umask
+
* 2. Change his umask
  
  

Revision as of 02:42, 8 March 2017

Change umask (privileges) for files modified by Apache

Intro

By default, umask is set to 022, which means 755 for folders and 644 for non-executable files.
In this case, only owner can change the contents of the file.

So let's imagine, that You've uploaded some stuff. By default, only You will be able to change the content, and apache will be shooting error messages.

Solution

  • 1. Create special user for web content management (for example admin)
  • 2. Change his umask


echo "umask 002" >> /home/admin/.bashrc echo "umask 002" >> /home/admin/.bash_profile


Here comes systemd part :))

3. vim /usr/lib/systemd/system/httpd.service 
4. Paste
UMask=0002
in to [Service] section
5. <ESC>, : , write <ENTER> , quit <ENTER> 
 :)) 5. systemctl daemon-reload 6. systemctl restart httpd.service 7. Test !

Test of solution

1. Create php file
<?php
  $file = fopen("testfile.text", "w") or die("ERROR !");
  $text = "Check privileges now !\n";
  fwrite($file, $text);
  fclose($file);
  sleep(1); // Simple DDoS protection
?><br>
2. Check if privileges of testfile.text are correct
-rw-rw-r--  1 apache  apache    23 Mar  8 08:41 testfile.text