Apache localhost 403 error with Yosemite - macos

I've just installed Mac OS X Yosemite fresh. I configured Apache and chmodded "users/user/Sites" to 755. When I hit localhost I receive a 403 Forbidden "You don't have permission to access / on this server". The same thing occurs with any other sites I add to my hosts file.
I tried configuring user directories following help from this post. The guys on this MacRumors thread know there is an Apache issue, but didn't offer a lot of suggestions.
My directory permissions look like this
drwxr-xr-x 29 root wheel 1054 Aug 11 07:30 /
drwxr-xr-x 6 root admin 204 Aug 11 07:29 /Users/
drwxr-xr-x+ 26 zachshallbetter staff 884 Aug 11 11:57 /Users/zachshallbetter/
0: group:everyone deny delete
drwxr-xr-x 5 zachshallbetter staff 170 Aug 11 10:16 /Users/zachshallbetter/Sites
Can anyone offer any suggestions or help? Here are links to my hosts and httpd.conf files and error logs for reference.

You do NOT want to open up the entirety of your hard drive to the web server process. In fact, lines 215-217 of httpd.conf say:
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
Apache 2.4 (OSX 10.10 Yosemite) has a different structure from Apache 2.2 (OSX 10.9) for the Directory directive in Module mod_authz_core.
EDIT: If you are setting up Apache from the START, please follow this instruction set to setup apache and php on OSX 10.10 Yosemite.
Assuming you have mod_userdir.so enabled already, your problem is within your user .conf file (/etc/apache2/users/username.conf), edit (or add) the following.
Apache 2.2:
<Directory "/Users/jnovack/Sites/">
Options Indexes MultiViews
AllowOverride All
# OSX 10.9 / Apache 2.2
Order from deny, allow
</Directory>
Apache 2.4
<Directory "/Users/jnovack/Sites/">
Options Indexes MultiViews
AllowOverride All
# OSX 10.10 / Apache 2.4
Require all granted
</Directory>

Edit the file:
/private/etc/apache2/httpd.conf
on line 250 (in Yosemite) change:
Options FollowSymLinks Multiviews
to:
Options FollowSymLinks Multiviews Indexes
then in the Terminal run:
sudo apachectl restart

This might be very late answer but i did followed most of Stack Overflow solutions, None of them helped me for various reasons. So i did reset my device as a fresh Yosemite OS to get this localhost working on Mac Yosemite (with Symlinks too),
Steps I did exactly :
sudo nano /etc/apache2/httpd.conf
Uncomment the following lines:
#LoadModule php5_module libexec/apache2/libphp5.so
to
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule userdir_module libexec/apache2/mod_userdir.so
to
LoadModule userdir_module libexec/apache2/mod_userdir.so
#Include /private/etc/apache2/extra/httpd-userdir.conf
to
Include /private/etc/apache2/extra/httpd-userdir.conf
Save and Exit (Ctrl+X press Enter and press Y and enter again)
sudo nano /etc/apache2/extra/httpd-userdir.conf
and uncomment the following line at line 16:
#Include /private/etc/apache2/users/*.conf
to
Include /private/etc/apache2/users/*.conf
Save and Exit (Ctrl+X press Enter and press Y and enter again).
Now go to apache Users folder to check your configuration file exist or not
cd /etc/apache2/users/
if you do not have configuration file in this folder, create one by
sudo nano /etc/apache2/users/<**YOUR USERNAME**>.conf
Replace <YOUR USERNAME> with the name of your machine (type whoami in terminal and enter that name).
after creating .conf file , copy below lines into that file
<Directory "/Users/<YOUR USERNAME>/Sites/">
AddLanguage en .en
LanguagePriority en fr de
ForceLanguagePriority Fallback
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from localhost
Require all granted
</Directory>
save and Exit
Now restart your apache
sudo apachectl restart
Now go to your browser and type localhost, it should work as expected,
Just as a Note: if it does not work even after try restarting your computer
create index.html as exactly index.html.en that you should find here:
open /Library/Webserver/Documents/
right click on index.html.en and duplicate it to index.html leaving original as it is
try again in browser and if you have success, you can delete the duplicated file
Just to be clear, leave the original file index.html.en where it is, untouched and unharmed throughout this step.
Not sure why I had to take this mysterious detour - probably something local to my machine, but if you're having trouble after following the guide above, see if it helps.
SymLinks :
if you have success, in Browser you should see
It works!
Now create symlink to any your project.
ln -s <Path_to_your_Project(index_file)> <Path_to_webroot>
For example if you have project folder in your Documents folder ,then point webroot to your index file by
ln -s /Users/<YOUR USERNAME>/Documents/project/ /Library/Webserver/documents/projectlink
you might need permission to create symlink (Use above command with Sudo)
Configure apache to follow symlinks ( Thanks to tomvon, i do not enough points to vote you)
sudo nano /private/etc/apache2/httpd.conf
on line 250 (in Yosemite) change:
Options FollowSymLinks Multiviews
to:
Options FollowSymLinks Multiviews Indexes
then in the Terminal run:
sudo apachectl restart
Now go to localhost/projectlink to see if your project index file shows here on browser.
Happy Coding..

The advice in this article helped me.
Specifically the "Yosemite Only" section:
First, there is a directive that helps secure your machine by denying access to the entire file system by default. I’ll show you how to remove this directive, since I find that easier on a machine meant for development. The section of code runs from line 220 through 223. You can comment out (place ‘#’ in front of each line) or just remove this section.
And the section is ...
<Directory />
AllowOverride none
Require all denied
</Directory>
Note:
As others have followed up on this with more details, the method outlined above can be insecure.

There are 2 possibility why your localhost is forbidden, first it may be because your apache setting is not correct and second, may be because you set vhost and you forget about set localhost too
sudo nano /etc/apache2/extra/httpd-vhosts.conf
Add this code
`
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Users/username/Sites"
<Directory "Users/username/Sites">
Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all
</Directory>
</VirtualHost>
Save it and restart your apache
`
sudo apachectl restart
it should be works :)

Suggestions might focus on your own user specific conf in apache but by default this configuration might not be loaded at all.
Edit the userdir module configuration:
sudo vi /etc/apache2/extra/httpd-userdir.conf
Uncomment the include of the user directory configuration files:
Include /private/etc/apache2/users/*.conf
Make sure you have a user directory configuration according our own username:
sudo vi /etc/apache2/users/.conf
Make sure you have good configuration for your home directory:
DocumentRoot "/Users/<username>/Sites/"
<Directory "/Users/<username>/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
Restart apache (webserver)
sudo apachectl restart
Check your site!

Just create the 'Sites' folder in your user folder. Go to
cd ~
mkdir 'Sites'

Related

Apache stop webdav directory listing on windows

I'm working on a server which has to serve a few files publically via WebDav. The public availability and WebDav is a must have, so I can't just change them. Windows support (sadly) is another must thing...
It would be great if I could disable directory listing, so the person who I give the webdav link would only be able to either guess the link or use only the one I gave.
In default case it's quite easy to disable directory listing, and in the browser the current configuration perfectly stops dir listing, but when I open it via windows explorer, I can easily see the whole directory and its content. My current config is:
<VirtualHost *>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/web1/web/
<Directory /var/www/web1/web/>
Options MultiViews
AllowOverride None
Order allow,deny
allow from all
<LimitExcept GET PROPFIND>
Require valid-user
</LimitExcept>
</Directory>
Alias /v1 /var/www/web1/web
<Location /v1>
DAV On
AuthName "webdav"
</Location>
</VirtualHost>
If I wont allow PROPFIND method, windows thinks that the host is unavailable (unsure if linux can access it, that's not my target).
Is it possible to stop directory listing on windows? For me it seems the PROPFIND is what causes this, but I'm unsure if I can somehow bypass this problem. Do you have any idea how should I modify my config file?
I know this question is old, but in your VirtualHost file (the file in /etc/apache2/sites-available/[yoursite].conf), you need to add something. This is in your directory tag. Supply it with DirectoryIndex disabled. Like this
<Directory [yourdirectory]>
(...)
DirectoryIndex disabled
</Directory>
Sincerly, Chris Fowl

localhost/~username/ not working

So i have stuck on this thing since last week . i am new to web development , and wanted to learn php , as soon as i started i had to setup apache server , for root directory it works fine but for localhost/~username/ it can't connect to server "localhost".
here are the files i had been messing up
(sudo apachectl configtest : Syntax OK )
httpd-userdir.conf file
https://www.dropbox.com/s/3zmuc2jetpo3i0i/httpd-userdir.conf?dl=0
httpd.conf file
https://www.dropbox.com/s/vlrzqr95ge2qy3c/httpd.conf?dl=0
username.conf file
https://www.dropbox.com/s/f13cgfgfb56esi7/mfaizanulhaq.conf?dl=0
(OS X el Capitan
10.11.5 (15F34)
&
Server version: Apache/2.4.18 (Unix)
Server built: Feb 20 2016 20:03:19
)
If this is still relevant and you are fed up with trying to find a solution you can change Documents root folder to your user Sites folder. This will prevent everyone but you from accessing localhost from your machine, but it's a hotfix solution. I've had a deadline and I had to finish the site, so this worked for me.
Go to httpd.conf change
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
to
DocumentRoot "/Users/username/Sites"
<Directory "/Users/username/Sites">
To look up your username in the terminal use whoami.
NOTE: Bear in mind you also need to change the following lines in httpd.conf it's located just below DocumentRoot within <Directory> tag you changed earlier.
Whatever it says in your file modify to this (that should be true for ALL configurations of the Apache2)
Options FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride All
Require all granted
This is a really bad solution since your Users/username/Sites folder will be accessed directly when you type localhost in the browser, but when something goes wrong, or you've done something wrong this is the best solution so far especially if you are 100% certain you are not going to have more than 1 user access your localhost directory.
i hope no one faces this problem. In my case i had updated php to php 7 but in httpd.conf it was trying to load php 5 so by commenting out that line my problem was solved.

OSX El Capitan Apache Forbidden when excluding ~username from URL

I'm trying to set up my Mac as a web server as a leaning experience; everything is working perfectly except one small thing.
If I go to here, it works:
http://mywebsite.ddns.net/~username/
If I go here (without ~username), I get error message "You don't have permission to access / on this server":
http://mywebsite.ddns.net/
I'm guessing it has something to do with my httpd.conf or username.conf settings. I've adjusted them as recommended from other answers but I'm still getting errors, here are the relevant settings from each:
httpd.conf:
DocumentRoot "/Users/username/Sites"
<Directory "/Library/Users/username/Sites">
username.conf:
<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
Are there any other settings i should be looking at, or perhaps the Sites folder itself has incorrect permissions? Here are the folder:
drwxr-xr-x 40 username staff 1360 27 Mar 19:24 Sites
Any help greatly appreciated!

AWS laravel forbidden

I would like to install Laravel in an AWS/EC2 instance. I first tried to install in my home directory. The laravel new command worked well, and installs the subdirectory. I changed /etc/httpd/conf/httpd.conf in the document root and directory sections (see below) to reflect the path to the public subdirectory of the laravel installation. I restarted the apache server. I changed the permissions (recursively) on the storage subdirectory of the Laravel installation to 777. I realize the eventually this change to 777 needs to change to 775 with a chown to the web user, but I would like to get this to work first.
This configuration produces a "forbidden You don't have permission to access / on this server." response.
I tried to install laravel in /var/www . I renamed the "html" directory. The "laravel new html" command produces the error
PHP Warning: file_put_contents(/var/www/laravel_42427584d5fd657ed6d5af1886e70011.zip): failed to open stream: Permission denied in /home/ec2-user/.composer/vendor/laravel/installer/src/NewCommand.php on line 114
This appears to be a permissions issue, so I tried sudo laravel new html. This produces "sudo: laravel command not found". I added ~/.composer/vendor/bin to my path.
My preference would be to install Laravel in my home directory, but installation anywhere that works would be fine.
Searches in stackoverflow (and the general web) produced solutions suggesting changing the ownership of the laravel installation directory apache:apache (produced the same forbiden error) and reviewing the apache error log (permission denied to enter /var/log/httpd even with sudo, chmod for this directory did not change result).
I have included the httpd.conf file. Thank you in advance for your help.
httpd.conf file (relevant parts)
#DocumentRoot "/var/www/html"
DocumentRoot "/home/ec2-user/laravel_dir/public"
#
# Relax access to content within /var/www.
#
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
#<Directory "/var/www/html">
<Directory "/home/ec2-user/laravel_dir/public">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch
ExecCGI MultiViews
#
# Note that "MultiViews" must be named explicitly --- "Options All"
...
#AllowOverride None
AllowOverride All
...
Require all granted

Cannot get site loaded with Apache on Mac

I'm running El Capitan and trying to get my website hosted locally for development with Apache (that came with the OS). I followed the instructions here exactly. I made an anthony.conf file and put the Directory text in there, I replaced the actual directory with /Users/anthony/dev/web/unfinished-asteroids/ and then placed my web files in there. I started apache and navigated for localhost/~anthony but I get the
Not Found: The requested URL /~anthony was not found on this server.
standard 404 error. When I navigate to localhost it works fine and I get the "It works" from the index.html that is located in /Library/WebServer/Documents, I even changed that index.html file and it works fine.
Any ideas why I'm not able to see my website using apache? All I did was download this github repository and place it in my unfinished-asteroids folder, the index.html is at the root.
So it looks like there are a couple of extra steps that you need to do. There isn't really anything too special about apache that comes with OSX, so your standard apache configurations will work. but to get Userdir (~username) working on El Capitan,this is what I had to do
Edit /etc/apache2/httpd.conf
on (or near) line 166, uncomment
loadModule userdir_module libexec/apache2/mod_userdir.so
then on line 493 uncomment
Include /private/etc/apache2/extra/httpd-userdir.conf
then edit file /etc/apache2/extra/httpd-userdir.conf
uncomment line 16
Include /private/etc/apache2/users/*.conf
then in /etc/apache2/users/anthony.conf
<Directory "/Users/anthony/Sites/">
Options Indexes MultiViews
Require all granted
</Directory>
then sudo apachectl restart
That should make http://localhost/~anthony point to your sites directory.
Logs are stored in /var/log/apache2
Now if all you want is web access to say your dev directory you can do something like this.. (don't make any of the changes listed above)
in /etc/apache2/other/ create a file called mydev.conf (name doesn't really matter, save it needs to end in .conf')
and put this in that file
Alias /dev /Users/anthony/dev/
<Directory "/Users/anthony/dev">
Options Indexes MultiViews
Require all granted
</Directory>
and reload apache (sudo apachectl restart)
then you will be able to access your dev folder at http://localhost/dev and should be able to access your page at http://localhost/dev/web/unfinished-asteroids/
you can adjust the paths at will above, just need to make sure that the user or group _www has access to it, and that paths in the alias and the directory match.

Resources