LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   apache configuration (gentoo) (http://www.linuxquestions.org/questions/linux-server-73/apache-configuration-gentoo-642474/)

Gryyphyn 05-15-2008 04:39 PM

apache configuration (gentoo)
 
Before we get started here I've checked the threads and the webs and found nothing for this issue.

Current system configuration:
Sabayon 3.4f (patched/updated)
Apache2 updated last night (05142008) on updated portage
vsftpd for ftp server (to be used in conjunction with apache)
SSH and SSL packages all updated, configured and working (for current configuration)

Here's the problem:
I've installed Apache2 and it's looking to /usr/bin/apache2 for the server root (install location of the modules directory). The server loads, both remote and local, but the index.html file isn't being read for the default page. I've created a new dir in /var/www called /Section-9 but I can't figure out how to a) get the document root pointed there and b) how to get the index.html to work despite the fact that it's currently in the document directory the apache2 server is looking for content (/var/www/localhost/htdocs I think). The other problem is that the only configuration file I can see is httpd.conf in /etc/init.d/apache2/conf. So here's what I need:

A link to a good, functional and direct approach to apache2 configuration (not apache1).

-or-

A direct guide to basic apache2 configuration posted here including what files should be used for configuration and where apache2 prefers to pull it's content from.

-or-

A recommendation for a good book on apache2/LAMP configuration.

Everything has changed since I was in school so I'm at a complete loss for where I'm supposed to be at right now. Any help is appreciated. Please, only real posts, no 'go back to windows noob' posts or the like.

Gryyphyn, out.

Wim Sturkenboom 05-16-2008 01:02 AM

Code:

wim@webserver:~$ locate httpd.conf
/etc/httpd/httpd.conf
/etc/httpd/original/httpd.conf
wim@webserver:~$ cd /etc/httpd/original
wim@webserver:/etc/httpd/original$ ls
extra/  httpd.conf
wim@webserver:/etc/httpd/original$ grep DocumentRoot *
httpd.conf:# DocumentRoot: The directory out of which you will serve your
httpd.conf:DocumentRoot "/srv/httpd/htdocs"
httpd.conf:# This should be changed to whatever you set DocumentRoot to.
httpd.conf:    # access content that does not live under the DocumentRoot.
wim@webserver:/etc/httpd/original$

Just as an example from my Slackware webserver
run a locate to find the httpd.conf file
pick the one that seems appropriate
cd to that directory
analyse/edit the httpd.conf
restart apache to make the changes take effect
if no changes, you had the wrong file

Once you have the correct httpd.conf, you can find references to other config files in there (e.g. for ssl, virtual hosts etc).

Gryyphyn 05-16-2008 04:01 PM

Quote:

Originally Posted by Wim Sturkenboom (Post 3154890)
Code:

wim@webserver:~$ locate httpd.conf
/etc/httpd/httpd.conf
/etc/httpd/original/httpd.conf
wim@webserver:~$ cd /etc/httpd/original
wim@webserver:/etc/httpd/original$ ls
extra/  httpd.conf
wim@webserver:/etc/httpd/original$ grep DocumentRoot *
httpd.conf:# DocumentRoot: The directory out of which you will serve your
httpd.conf:DocumentRoot "/srv/httpd/htdocs"
httpd.conf:# This should be changed to whatever you set DocumentRoot to.
httpd.conf:    # access content that does not live under the DocumentRoot.
wim@webserver:/etc/httpd/original$

Just as an example from my Slackware webserver
run a locate to find the httpd.conf file
pick the one that seems appropriate
cd to that directory
analyse/edit the httpd.conf
restart apache to make the changes take effect
if no changes, you had the wrong file

Once you have the correct httpd.conf, you can find references to other config files in there (e.g. for ssl, virtual hosts etc).

What about declarations for serverroot and documentroot? That's the one that I'm struggling with the most. Thanks for the input!

Gryyphyn, out.

Wim Sturkenboom 05-17-2008 03:23 AM

I've never had a need for to modify ServerRoot, so not familiar with that one

You can point DocumentRoots anywhere as long as apache can read them.

E.g
Code:

DocumentRoot "/home/youruser1/domain1/www"
DocumentRoot "/home/youruser1/domain2/www"
DocumentRoot "/home/youruser2/domain3/www"

I use the above for virtualhosts. Each virtual host has one of the above lines.
If a visitor visits domain1, pages from /home/youruser1/domain1/www are served
If a visitor visits domain3, pages from /home/youruser2/domain3/www are served
You can figure out for yourself which pages are served when one visits domain 2 ;)

If you don't use virtual hosts, just modify the one in httpd.conf (or whichever file defines the document root).


The reason why I use the user's home direrctories is that I don't have to think about ftp access (just lazy); I've seen too many posts with problems accessing the 'default' DocumentRoot in combination with ftp. In my ftp setup, users are limited to their home directory but as that is where the web pages live, there is no problem.

Only disadvantage that I've found till now:
If you write web pages where apache needs to write to the user's home directory, you need to create a directory where apache indeed can write (I use a subdirectory under www for that and assign group permissions to apache).

Gryyphyn 05-17-2008 12:35 PM

Quote:

Originally Posted by Wim Sturkenboom (Post 3156020)

Only disadvantage that I've found till now:
If you write web pages where apache needs to write to the user's home directory, you need to create a directory where apache indeed can write (I use a subdirectory under www for that and assign group permissions to apache).

Makes sense to me. So I should be able to

Code:

DocumentRoot "/var/www/domain"
without any issues. The only problem is, even though I've declared that in /etc/apache2/conf/httpd.conf and there's an index.html there it's not pulling that page, just showing the directory. Is it possible there's multiple httpd.conf files and they're just not visible? I've used
Code:

locate httpd.conf
but I haven't seen any others anywhere.

Gryyphyn, out.

Wim Sturkenboom 05-19-2008 12:02 AM

I suppose that when you open index.html in your browser, it is the correct one. If so, the following lines occur in my httpd.conf:
Code:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
#WimS: add index.php
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

As you request a directory but get the listting, I suspect that to be missing or incomplete.

With regards to DocumentRoot "/var/www/domain", I suggest to change it to DocumentRoot "/var/www/domain/web" or something similar. The reason is the following:
If you have php-pages that contain confidential information and you place them in the document root (or a subdirectory under it), they are readable by the whole world when they are found. This can be e.g. the connection/login information for a database. I set it up as followes:
Code:

/var/www/domain/
          +--web
          +--inc

For the 'sensitive' stuff, I write functions and store them in php files in the inc directory. This diretory is not accessible by the outside world as it's not in the document root (but apache can access it).
The actual webpage php files go in web and will use include statements to access the php files in inc.

Gryyphyn 05-19-2008 11:09 AM

Quote:

Originally Posted by Wim Sturkenboom (Post 3157556)
I suppose that when you open index.html in your browser, it is the correct one. If so, the following lines occur in my httpd.conf:
Code:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
#WimS: add index.php
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

As you request a directory but get the listting, I suspect that to be missing or incomplete.

With regards to DocumentRoot "/var/www/domain", I suggest to change it to DocumentRoot "/var/www/domain/web" or something similar. The reason is the following:
If you have php-pages that contain confidential information and you place them in the document root (or a subdirectory under it), they are readable by the whole world when they are found. This can be e.g. the connection/login information for a database. I set it up as followes:
Code:

/var/www/domain/
          +--web
          +--inc

For the 'sensitive' stuff, I write functions and store them in php files in the inc directory. This diretory is not accessible by the outside world as it's not in the document root (but apache can access it).
The actual webpage php files go in web and will use include statements to access the php files in inc.

Hadn't thought about the .php files scenario before, that's good info. As far as the the DirectoryIndex line though, yes, it's in there and declared properly (as far as I can tell). I'll grab my declarations tonight and post them, see what you think.

I'm also going to uninstall/reinstall apache, make sure that everything is where it's supposed to be and just start from scratch, see what happens. I do think that part of the problem is that the location portage installed everything to is incorrect.

*append* I looked at one of your earlier posts and there was something I missed, or didn't take in to account, before. The last time I was playing with this seriously I checked the server root and worked the httpd.conf file from there. I had a dirty read in vi due to a messy swap file and had to delete the swap manually to correct. Once I corrected the issue the serverroot declaration had changed completely and was pointing somewhere it never had before. That's the primary reason for reinstalling, layer 8 error (or pebkac, ID10T or your other fav phrase here).

Gryyphyn, out.


All times are GMT -5. The time now is 06:50 AM.