Fix permissions in Apache I'm trying to use the built-in Apache server in MacOS mojave.

In my browser, accessing http://localhost/~myusername/mypage.html (in case of user dir) or http://localhost/mypage.html (in case of default dir) both throw the same error in the browser:

Forbidden You don't have permission to access /mysite/ on this server.


I' trying to make both the default dir /Library/WebServer/Documents and an user dir ~/myusername/Sitesworks.
I tried 2 solutions:


I tried to add a vhost in /etc/apache2/extra/httpd-vhosts.conf

&lt;VirtualHost *:80&gt;
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
&lt;/VirtualHost&gt;

I tried to add a myusername.conf file in /etc/apache2/users with the following content

&lt;Directory "/Users/myusername/Sites/"&gt;
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
&lt;/Directory&gt;



Is there a guide to understanding permission errors on Mojave using Apple shipped Apache?

EDIT: It looks like the accepted answer here solved the reading permission for me.
From the answer:


  
  Load the module mod_userdir in /etc/apache2/httpd.conf
  At the end of the httpd.conf make sure to load httpd-userdir.conf
  In httpd-userdir.conf include a local file in /etc/apache2/users/&lt;username&gt;.conf
  Put a directory section into that file, containing the rules for the directory where your webserver files are located:

  &lt;Directory "/Users/&lt;myusername&gt;/Sites/"&gt;
      AllowOverride All
      Options Indexes FollowSymLinks
      Require all granted
  &lt;/Directory&gt;

  


Writing access to files is still a problem: Apache cannot edit a file if the ownership is mine (the admin user). I'm still wondering if there is a proper way to fix the permission without messing up each directory permissions every new project.

This is the script I'm using for testing write permission:

&lt;?php
    echo 'Current script owner: ' . get_current_user();
    echo 'Current user:' . system('whoami');
    $current = file_get_contents('people.txt');
    $current .= "John Smith\n";
    file_put_contents($file, $current);


I get the error: 


  Warning: file_put_contents(people.txt): failed to open stream:
  Permission denied
Apache in macOS Server runs as the _www user. Try granting this user write access to the directory with an ACL entry.

chmod +a "_www allow list,search,add_file,add_subdirectory,delete_child,write,append,file_inherit,directory_inherit" "/Users/&lt;user&gt;/Sites"