I'm trying to use the built-in Apache server in MacOS mojave.
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
I tried 2 solutions:
I tried to add a vhost in
<VirtualHost *:80> ServerName localhost DocumentRoot /Library/WebServer/Documents/ </VirtualHost>
I tried to add a
/etc/apache2/userswith the following content
<Directory "/Users/myusername/Sites/"> Options Indexes MultiViews AllowOverride All Order allow,deny Allow from all </Directory>
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
- At the end of the
httpd.confmake sure to load
httpd-userdir.confinclude a local file in
Put a directory section into that file, containing the rules for the directory where your webserver files are located:
<Directory "/Users/<myusername>/Sites/"> AllowOverride All Options Indexes FollowSymLinks Require all granted </Directory>
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:
<?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