# Apache2 config

## mystified

I recently upgraded apache to apache-2.0.49-r4 and unforunately ran etc-update without checking and it overwrote my config file.  Stupid I know.  Anyway, I need to reconfigure apache but I don't remember where I got the instructions for configuring the first time.

I'm running webmin, apache, mysql and php.  When I log in through localhost:10000 I get the message that apache is running but that configuration file has changed.

Can someone please help?

----------

## hugelmopf

If you are looking for the place to configure Apache2, it is here:

/etc/apache2/conf/

There are some things that have to be changed in apache2.conf and commonapache2.conf (like where your htdocs are, permissions, etc.)

These files are pretty well explained in themselves, but if you need any help, I can try to answer your questions. Or you have a look at apache.org

Frank

----------

## g4j

While we're on the "helpme Apache" thread, I'm going nuts with Apache2. I can't get PHP to run (PHP pages show code, but not the formatted result), nor can I get usrdir's to do anything other than display "Forbidden, You don't have permission to access /~(username)/ on this server." And finally, I can't get SSL to run.

Everything works fine on my SuSE box. Install it and it runs. But Gentoo.... that's another story. I've gone through the config files but haven't seen what I'm missing. In webmin, I can't get any of the modules in question to show as installed.

I've emerged mod_php, but mod_ssl want's to instal Apache 1.xxx, which is a step backwards. I have no idea what to emerge for mod_usrdir.

Any help on any of these Apache issues would be appreciated.

Thanks,

~Rolf

----------

## hugelmopf

About the Permission-problem: In commonapache2.conf there is a section, where you have to set the permissions for your various directories. There you have to enable, whatever you need. For example my websites are in /home/frank/websites/, so I have the following entry there:

```

### This should be changed to whatever you set DocumentRoot to.

###

<Directory /home/frank/websites>

#

# This may also be "None", "All", or any combination of "Indexes",

# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".

#

# Note that "MultiViews" must be named *explicitly* --- "Options All"

# doesn't give it to you.

#

    Options Indexes FollowSymLinks MultiViews

#

# This controls which options the .htaccess files in directories can

# override. Can also be "All", or any combination of "Options", "FileInfo",

# "AuthConfig", and "Limit"

#

    AllowOverride All

#

# Controls who can get stuff from this server.

#

    <IfModule mod_access.c>

      Order allow,deny

      Allow from all

    </IfModule>

</Directory>

```

Try this to fix the permission problems (of course replace /home/frank/websites/ with whatever you set your Document-Root to). I guess you have to configure the same thing for the user-directory section.

PS: Don't forget to restart apache2 after changing, otherwise there will be nothing new  :Wink: 

# /etc/init.d/apache2 restart

----------

## hanj

Hello g4j

Check your /etc/conf.d/apache2 file

Make sure this value is set:

```
APACHE2_OPTS="-D PHP4"
```

If not.. add it and restart apache

I hope this helps.

hanj

----------

## hugelmopf

Oh, I forgot about the other questions, but good that hanj took care of that.

I suppose, getting SSL to work is the same deal: 

```

APACHE2_OPTS="-D PHP4 -D SSL"

```

As long as these modules are present (I have libphp4.so after emerging PHP) and configured, this should work.

Modules and their configuration in:

/usr/lib/apache2/modules/

/etc/apache2/conf/modules.d/

----------

## mazaryk

g4j:

I had to add the php mime type:

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

to /etc/apache2/conf/commonapache2.conf (after DefaultType text/plain) to get apache to process the php code. 

Also, i just learned that permission to a dir is denied if both the following are true:

1) Directory browsing (IndexOptions +FancyIndexing) is not enabled for said dir.

2) said dir doesn't contain a default index file [index.htm, etc... (see DirectoryIndex)].

----------

## g4j

Thanks for the PHP & SSL help. I've been playing with the -D PHP -D SSL settings, at first with no luck, but then SSL mysteriously started working.

I'll try adding the PHP mime type when I get home tonight. Hopefully that will do the trick.

For the usrdir issue, I don't want to change the document root to /home/me/public_html. That would not solve the problem, as my goal is to enable multiple usres web space by using the URL machine/~user

I tried tweaking the commonappache2.conf file, by uncommenting the usrdir section starting with the /home/*/public_html line, but that alone isn't doing the trick.

Do I need to do a chmod in the public_html directory?

Thanks for your help.

~Rolf

----------

## SerfurJ

make sure the permissions are correct.  i had the same problem.

https://forums.gentoo.org/viewtopic.php?t=169454&highlight=

----------

## g4j

Adding the PHP mime type resulted in Mozilla asking me what to use to open the file, so that was a step backwards. But making the index searchable did the trick. Thanks, mazaryk.

I also got the usrdir to work, thanks to the tip from SerfurJ. I had to chmod /home/(user) to 751, and now usrdirectories work like a charm. I should have thought about that sooner.

----------

## Carnager

Hope this doesn't sound stupid  :Wink:  but:

 *g4j wrote:*   

> Adding the PHP mime type resulted in Mozilla asking me what to use to open the file, so that was a step backwards. But making the index searchable did the trick. [..]

 

- Did you remove the mime type again?

- How did you make the index searchable?

----------

## g4j

There are several ways to make an index unsearchable - which is what we don't want for the sake of php. 

The .htaccess file can determine search ability. .htaccess is an Apache configuration file that can exist in any directory/subdirectory which contains web files. You could if you wanted have an .htaccess in every directory. Do a search on .htaccess and index, and you should find all of the juicy details. (I'm at work at the moment, and all of my Linux boxes are at home, so forgive me if I'm vague.)

The Apache configuration file also has an option to limit searchable indexes. Look in /etc/conf.d/apache2   Appache2 has several configuration files -- I think that's the right one. I don't remember the exact line of code, but search the file for the word "index," and you should find it.

And finally, the directory permissions (if I remember correctly) can impact things. If the directory were a file, you would want it "executable" by all. But for directories, "executable" means "searchable." Making it searchable does not necessarily mean readable. Use the chmod command or any other utility that lets you tweak permissions. (My favorite crutch is Midnight Commander.)

PHP Mime types: This was both simple and perplexing. The file to edit is /etc/apache2/conf/commonapache2.conf   What didn't work for me was the line

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

The result of that was Mozilla started prompting me for the type of application to use to open a PHP page. At first, removing the line didn't seem to resolve the issue. But what I discovered was that Mozillia would prompt me only when attempting to open that one page -- or rather, URL. No problem with other PHP pages, and no problem with the original test page if I renamed it or moved it - so Mozilla must remember that particular URL as something that it didn't understand.

Hope this helps.

----------

## Carnager

Thanks g4j for your reply! I've gotten it to work ^^

----------

## j3rm

I've followed all suggestions in this post, including adding mime types and making the index searchable.  Still, PHP doesn't work.  This is pretty frustrating.  It worked a week ago before I upgraded.    :Mad: 

----------

## j3rm

Alright, I figured it out.  Like I should have done before, I went straight to the PHP doc site, and it tells you exactly what to do.

http://www.php.net/manual/en/install.apache2.php

Turns out the newest version of apache requires an additional LoadModule statement in the configuration file.  I don't even think having "-D <whatever>" in /etc/conf.d/apache2 even does anything anymore.

----------

## g4j

Thanks j3rm. I just updated Apache the other day and didn't even notice that PHP was dead until I read your post. I've got some tweaking to do tonight.

----------

## g4j

Son of a gun! What made matters worse before I upgraded, is now essential with Apache2. "AddType..." caused me grief before I upgraded. But now that I'm on Apache2, PHP will not run without adding it. As mazaryk pointed out above: 

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

must be added to /etc/apache2/conf/commonapache2.conf -- if and only if (in my experience) you are using Apache2. If you haven't upgraded to 2 yet, leave the application type out.

----------

## j3rm

Aye, a lot of frustration due to a little thing.  It might be prudent for Gentoo to add an alert at the end of the newest apache emerge about this.    :Confused: 

----------

