OSX El Capitan Apache Forbidden when excluding ~username from URL - macos

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!

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.

Apache localhost 403 error with Yosemite

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'

can't set up alias for lab directory but can set up alias for phpMyAdmin in lion

I am using mac with osx lion
I set up alias for my apache using the following setting:
Alias /phpMyAdmin/ "/Users/jason/Sites/phpMyAdmin/"
<Directory "/Users/jason/Sites/phpMyAdmin">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /Lab8/ "/Users/jason/Sites/Lab8/"
<Directory "/Users/jason/Sites/Lab8">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
My Lab8 directory and phpMyAdmin Directory are placed in the same place (/Users/jason/Sites)
I can access the phpMyAdmin though localhost/phpMyAdmin/
But when I want to access the Lab8 directory though localhost/Lab8/
It give the following message:
Forbidden
You don't have permission to access /Lab8/ on this server.
I don't know what wrong with my setting.
I cannot access my Lab8 directory though localhost/Lab8
even I set permission 777 for the Lab8 directory and all files under it.
Could it be that you have directory listing off, and there is no index.php/index.html file in the Lab8 directory?

Enable directory/file listing in XAMPP

How to enable directory and file listing in XAMPP ? In WAMP it is by default enabled.
My Xampp httpd.conf already had the Indexes option under the xampp directory entry
Removing all the default #comment lines, it looks like this:
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
But, I have my local root mapped to a different directory, outside of 'htdocs', (as per this post Make XAMPP/Apache serve file outside of htdocs ) so to enable this for all directories, I had to find the entry just above that, and add the word "Indexes" to it.
<Directory />
Options FollowSymLinks Indexes
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Note I would never enable this for all directories on a production server, but locally it is quite useful.
Just delete or rename index.html and index.php files
There is a XAMPP Directory Browsing UI app, that will help you to browse projects inside htdocs in XAMPP.
Open apache/conf/httpd.conf and search for Indexes in httpd.conf
And comment complete line like this:
#Options Indexes FollowSymLinks Includes ExecCGI
#Options - Indexes FollowSymLinks Includes ExecCGI
Uncommenting First will enable the indexing of directories.
Uncommenting Second will disable indexing of directories
Removing the comment will enable the Directory/file listing of hosted path.
Rename the 'index.php' file that sits in your htdocs folder to something like 'MODIFIED_index.php' (if you want to be able to revert to it later) - this index.php file is only used to point to xampp's admin controls that are found in 'localhost/xampp/' anyway.

Resources