# Apache2 403 Forbidden Error with Virtual Hosts

## Rukie

I followed the gentoo-wiki guide on how to create an apache server with name-based hosting, along with email (which I haevn't finished yet).

Anyways, whenever I try to get to my site http://www.rukie.ath.cx:5000/ or http://www.cchs.ath.cx:5000/ or even http://localhost I get the 403 Error, Forbidden in Directory /.

Here are some of my vhost files..

00_default_vhost.conf

 *Quote:*   

> 
> 
> NameVirtualHost *:80
> 
> NameVirtualHost *:443
> ...

 

Here's 01_rukie.ath.cx_vhost.conf

 *Quote:*   

> 
> 
> NameVirtualHost *:80
> 
> NameVirtualHost *:443
> ...

 

And here is the httpd.conf in /etc/apache2

 *Quote:*   

> #
> 
> #  This is a modification of the default Apache 2 configuration
> 
> #  file by Gentoo Linux.  .... [insert more]
> ...

 

And here's an ls -l of /var (same settings (recursive, -R) for everything in the directory)

(in /var)

lrwxrwxrwx  1 rukie  root     8 Jan 18 20:22 www -> /web/www

(in /var/www)

drwxr-xr-x 6 rukie apache 144 Mar 26 09:50 cchs.ath.cx

drwxr-xr-x 7 rukie apache 168 Mar 26 09:50 gpromm.ath.cx

drwxr-xr-x 7 rukie apache 224 Mar 23 21:44 localhost

drwxr-xr-x 6 rukie apache 144 Mar 26 09:50 rukie.ath.cx

Any assistance at all would be helpful

----------

## badchien

Don't bother setting DocumentRoot and ServerName for rukie.ath.cx in httpd.conf. You need named-based virtual hosting, so this is no good.

You have started to create a virtualhost section for rukie.ath.cx, but you haven't set DocumentRoot, etc properly. Fix 01_rukie.ath.cx_vhost.conf so it looks like this:

```
# !!!Comment-out or remove these two lines. They are already set in 00_default_vhost.conf and should not be set again.

#NameVirtualHost *:80

#NameVirtualHost *:443

################################################

# Rukie.ath.cx

#################################################

<VirtualHost *:80>

ServerName rukie.ath.cx

DocumentRoot /var/www/rukie.ath.cx

DirectoryIndex index.php index.cfm index.html index.htm

ErrorLog /var/log/apache2/rukie.ath.cx-error

CustomLog /var/log/apache2/rukie.ath.cx-access combined

</VirtualHost>

<VirtualHost *:443>

ServerName rukie.ath.cx

DocumentRoot /var/www/rukie.ath.cx

DirectoryIndex index.php index.cfm index.html index.htm

ErrorLog /var/log/apache2/rukie.ath.cx-error

CustomLog /var/log/apache2/rukie.ath.cx-access combined

SSLEngine On

SSLCertificateFile /etc/apache2/conf/ssl/rukie.ath.cx/rukie.ath.cx.cert

SSLCertificateKeyFile /etc/apache2/conf/ssl/rukie.ath.cx/rukie.ath.cx.key

</VirtualHost> 
```

Start with this, and restart apache. If you are still having trouble, check your error_log to see what exactly apache is trying to serve so you can determine what is wrong (permissions or config, etc).

----------

## Rukie

#bash : /etc/init.d/apache2 restart

 * Apache2 has detected a syntax error in your configuration files:

Syntax error on line 21 of /etc/apache2/vhosts.d/00_default_vhost.conf:

Invalid command 'SSLEngine', perhaps mis-spelled or defined by a module not included in the server configuration

Uhm, not sure what set this off, its the line "SSLEngine On"

SSL should be setup fine... 

*confused*

----------

## badchien

Take this one step at a time. Comment out the SSL... options for the moment and restart apache again. See if you can at least get your http site working, then we can look at ssl.

----------

## Rukie

hmm, wierd... commented out the SSL and now I get

 *Quote:*   

> 
> 
>  * Apache2 has detected a syntax error in your configuration files:
> 
> /usr/sbin/apache2: error while loading shared libraries: libexpat.so.0: cannot open shared object file: No such file or directory
> ...

 

re-emerged and solved the problem. 

Now I get one of t hose pages on localhost where you see all of your folders. When I click on htdocs Konquerer acts like its a text document, while it goes into other folders just fine.

----------

## badchien

You mean all your web docs are actually in /var/www/rukie.ath.cx/htdocs ?

Then you need to change your DocumentRoot in 01_rukie.ath.cx_vhost.conf to this directory.

Restart apache and try it again. We're getting closer  :Smile: 

----------

## Rukie

hmm, I get the 403 forbidden error again in  htdocs, and localhost works---sort of

I don't get any of my graphics.. uhm.. None of the html is rendered (whats the word, compiled? no..)

Basically, when I go to http://localhost it loads the index.php page.... but I see the actual php code and  html code.. *wierd*

----------

## badchien

If you are using php you'll want to uncomment this line in httpd.conf and restart again.

```
#LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
```

----------

## badchien

[quote="Rukie"]hmm, I get the 403 forbidden error again in  htdocs[quote]

Exactly what URL are you putting in your browser when you get the 403?

And what does the last line in /var/log/apache2/rukie.ath.cx-error say after you get that 403 error?

----------

## Rukie

its still not doing anything to the php code...

/me is confused.

it says 

 *Quote:*   

> 
> 
> [Mon Apr 03 23:14:12 2006] [error] [client 127.0.0.1] File does not exist: /var/www/localhost/htdocs/redir.php
> 
> 

 

and the address is http://localhost when I get the server working, (but for some reason php is not working anymore

the error 

when I use http://rukie.ath.cx I get the error

 *Quote:*   

> 
> 
> [Mon Apr 03 23:20:53 2006] [error] [client 127.0.0.1] Directory index forbidden by rule: /var/www/rukie.ath.cx/htdocs/
> 
> 

 [/profile][/quote]

----------

## badchien

Ok, you're missing (at least) one more line in httpd.conf for php:

```
AddType application/x-httpd-php .php
```

 *Quote:*   

> when I use http://rukie.ath.cx I get the error
> 
>  *Quote:*   [Mon Apr 03 23:20:53 2006] [error] [client 127.0.0.1] Directory index forbidden by rule: /var/www/rukie.ath.cx/htdocs/ 
> 
>  
> ...

 That's easy. You have no index.html or index.php in that directory. Do you have any files in /var/www/rukie.ath.cx/htdocs/ ? Add at least an index.html and try http://rukie.ath.cx/ again.

----------

## kg

The gentoo-wiki page seems a bit out of date (and even says the config files have changed considerably).

Not to say it won't work, but trying to figure out the differences will be challenging.

I'd think about reverting to the original config (making sure it works), get php working, and then 

setup the virtual hosts one at a time.

On the php side...

Do you have a libphp5.so module in /usr/lib/apache2/modules?

How about a 70_mod_php5.conf in /etc/apache2/modules.d?

----------

## Rukie

muwahhaha... its working! its aliiive!

when u said there was no index page I thought that had to be wrong... 

so I went checking..

and....

/var/www/rukie.ath.cx/htdocs/htdocs/index.php he he he...

WhenI copied the directory I placed it in itself... so now its working great  :Very Happy: 

Unfortunately, SSL still doesn't work

 * Apache2 has detected a syntax error in your configuration files:

Syntax error on line 19 of /etc/apache2/vhosts.d/01_rukie.ath.cx_vhost.conf:

Invalid command 'SSLEngine', perhaps mis-spelled or defined by a module not included in the server configuration

----------

## badchien

Great!  :Smile: 

For SSL, check /etc/conf.d/apache2 

You may need to add " -D SSL" to APACHE2_OPTS

----------

