Change default root document in xampp/lampp from /opt/lampp/htdocs to one of the home directory - apache

I just install xampp for linux I want to change default root directory from /htdocs to /home/roshan/projects . So I tried creating a vhost with projects directory
<VirtualHost *:80>
DocumentRoot "/home/roshan/projects/test"
ServerName test.development
but this didn't work I got 403 Access forbidden! error but if use same thing with default directory /opt/lampp/htdocs/test then it works .So I tried to changing the DocumentRoot in httpd.conf I changed these 2 lines from /opt/lampp/htdocs
DocumentRoot "/home/roshan/projects"
<Directory "/home/roshan/projects">
also tried with changing
<IfModule unixd_module>
User roshan
Group roshan
I got 403 every time can anyone tell me what missing here . I restart Apache every time I made change in settings and folder have correct permissions.
Thanks for advice.


Apache2 keeps redirecting to default page

I've installed some software for users to be able to change their ldap password on they own named self service password on this path: /usr/share/self-service-password/htdocs.
In sites-enabled my configuration is as follows: (file named 000-default.conf)
<VirtualHost *:80>
ServerName <IP>
DocumentRoot /usr/share/self-service-password/htdocs
DirectoryIndex index.php
AddDefaultCharset UTF-8
LogLevel warn
ErrorLog /var/log/apache2/ssp_error.log
CustomLog /var/log/apache2/ssp_access.log combined
(same thing is "configured" at sites-available").
I've made sure this .conf file (000-default) is enabled by a2ensite, and made sure everything else is disabled, and restarted apache2.
However, When browsing to my IP:81 , it keeps redirecting me to Apache default welcome page under /var/www/html .
I'm trying to find a solution for it for the past 2 hours and couldn't find the reason behind it.
Thanks for anyone willing to assist.
As per your configuration your VirtualHost is accepting connections on port *:80
<VirtualHost *:80>
But then you are testing on IP:81.
Could you please adjust your test to IP:80
Adjust the VirtualHost port to *:81
They must match to work.

Prevent access to files through ip address - apache 2.4

I have asked a similar question before
Restrict access to directories through ip address
at that time the problem was solved for apache 2.2. Recently I re-installed the OS (to Debian 8) and it comes with apache 2.4.
I want to restrict access to files - when the request comes "by" IP. Mainly if in the browser I try to open it should show error - 403 forbidden. Directory test is in www directory of apache. However I should be able to access that image if I type - considering that points to that test directory.
With apache version 2.2 I would simply put this lines in my default site config file - and the problem was solved
<Files ~ ".+">
Order allow,deny
Deny from all
Now, trying the same thing does not work: I am getting 403 forbidden even if I try to open any site by the domain name.
Considering the changes in 2.4 I also tried this, but again getting the the same 403 forbidden when trying to open some site.
<Files ~ ".+">
Require all denied
My goal is to prevent any kind of access to directories and files - if they are being accessed through ip address. I have also this lines in my default site's config to prevent the directory access and this works fine.
<Directory /home/username/www>
Options -Indexes
AllowOverride All
Require all granted
So, the question is - how to prevent file access through IP address. Also I need to achieve this by apache config, by htaccess is not a solution for me. And I need to achieve this for all the directories/files inside www recursively, so specifying the exact file names and/or directories is not a solution either.
When you use name based virtual hosts, the main server goes away. Apache will choose which virtual host to use according to IP address (you may have more than one) and port first, and only after this first selection it will search for a corresponding ServerName or ServerAlias in this subset of candidates, in the order in which the virtual hosts appear in the configuration.
If no virtual host is found, then the first VHost in this subset (also in order of configuration) will be choosen. More.
I mention this because it will be important you have only one type of VirtualHost directive:
<VirutalHost *:80>
I'll use the wildcard in the example.
You need a directory like /var/www/catchall with a file index.html or similar, as you prefer.
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
# It will be used as the catchall.
# Giving this DocRoot will avoid any request based on IP or any other
# wrong request to get to the other users directories.
DocumentRoot "/var/www/catchall"
<Directory /var/www/catchall>
# Now you can add as usuall the configuration for any other VHost you need.
<VirtualHost *:80>
DocumentRoot "/home/username1/www"
<Directory /home/username1/www>
<VirtualHost *:80>
DocumentRoot "/home/username2/www"
<Directory /home/username2/www>
Debian specific :
For Debian, you ideally put one VHost configuration per file, and put the file in the /etc/apache2/sites-available directory.
Name the files as you like, only the file containing the catchall vhost should be named something like 000-catchall, because they will be read in alphabetic order from the /etc/apache2/sites-enabled directory.
Then you disable Debian's usual default site :
a2dissite 000-default
and you enable the new catchall site and the other VHosts if needed :
a2ensite 000-catchall
An ls /etc/apache2/sites-enabled command should show the catchall as the first of list, if not change its file name so that it will always be the first. Restart Apache: service apache2 restart
Of course you could do all this changes in the original default VHost config file, but I usually prefer keep an original model.

vhosts dont appear to be working on OS X Mavericks Apache installation

I am trying to set up the Apache server which comes with OS X Mavericks with vhosts so that a domain name resolves to my user level document webroot. I have followed this tutorial which guided me through setting up the apache server with php:
as well as this one which guided me through setting up the vhosts:
Following these tutorials, if I type localhost in my browser it correctly resolves to the system level root (/Library/WebServer/Documents/ folder). If I use localhost/~myusername it correctly resolves to my user level root (/users/myusername/Sites/).
However, whenever I navigate to my domain, I get redirected to the system level root rather than my user level root.
My vhosts file reads as follows:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
<VirtualHost *:80>
DocumentRoot "/Users/myusername/Sites/mydomain"
<Directory "/Users/myusername/Sites/mydomain">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Any ideas?
Have you enabled Virtualhosts?
NameVirtualHost *:80
And included your vhosts directory
Include <path>/vhosts/*
On a Macbook, you may need to include /private/ at the beginning of any absolute path, so that Apache can read it correctly off the file system.
For others who have the same problem...
It was frustratingly simple - I had missed the "" around the localhost directory.
How annoying!
Try starting apache manually with the -S option to see what the problem might be:
/usr/sbin/httpd -S

Accessing to a file and folder in Apache from Localhsot

I want to create a virtual folder with a file in it in Apache, and to see that file from my browser : how can i fix it ?
the error i get when i try my local host in browser:
You don't have permission to access / on this server.
I tried:
1) created a folder in etc/apache2/sites-available
2) checking the default Apache settings which is not blocking my IP which is
Assuming that you are trying to serve /yourfolder. Change the permission of the folder to give access right to others (755 for example) and add following to site conf you have created.
<VirtualHost *:80>
DocumentRoot /yourfolder
# Change according to your folder path
<Directory /yourfolder>
Order Allow,Deny
Allow From All
Options -Indexes

Apache: 3 virtual hosts working perfectly, 1 is not, but settings seem to be the same (Mac)

(OSX Leopard 10.5.8)
I've been using virtual hosts with no problems until now, when I tried to make a new block of code for the next one. The offender is called project1.
I've got an index.php sitting in the project1/html/ folder, just like all the others. But every time I try to go to http://project1/ in the browser I get a 404.
Here's the contents of httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Users/sebu/_SERVER/"
<VirtualHost *:80>
ServerName skeleton
DocumentRoot "/Users/sebu/_SERVER/skeleton/public_html/"
<VirtualHost *:80>
ServerName pickle
DocumentRoot "/Users/sebu/_SERVER/pickle/"
<VirtualHost *:80>
ServerName project1
DocumentRoot "/Users/sebu/_SERVER/project1/html/"
Here's what I've checked already:
I restarted Apache (every time I change something).
I tried clearing the browser cache.
I tried rebooting.
I made sure the file permissions are exactly the same as the other working vhosts (dirs and files).
I've got the line Options Indexes +FollowSymLinks -MultiViews in httpd.conf (turning Multiviews off was the solution to an earlier problem).
I ran httpd -S to check the syntax and it said everything was OK.
I tried pinging project1 just to check and sure enough it says cannot resolve project1: Unknown host
(Not sure if it's worth mentioning, but when I did a ls -la in _SERVER/ I noticed that project1/ had permissions written as drwxr-xr-x# with the # on the end. I read that this meant it was a quarantined file and would wait for me to open it so I ran open project1/ and it went away.)
do you have an entry in /etc/hosts for skeleton, pickle, but not project1? If so, add an entry for project1 and that should resolve your issue.