Benutzer-Werkzeuge

Webseiten-Werkzeuge


becki:linux:apache_httpd

Dies ist eine alte Version des Dokuments!


Apache Webserver Tips

Tips for the configuration of the Apache webserver. Unless noted otherwise, the settings were performed on a Slackware Linux system. Necessary steps for other Systems my vary slightly.

General

Tips refer to apache 2.x.

  • chmod +x /etc/rc.d/rc.httpd is necssary to start apache automatically at system boot.
  • To enable per-directory settings with .htaccess files, you have to set the AllowOverride directive for the document root (usually /srv/httpd/htdocs) accordingly. Amongst others, this is usually necessary fot URL Rewriting. When on doubt, set AllowOverride to all. More Info
  • To tell the browsers in the HTTP-header to use UTF-8 as default encoding, add AddDefaultCharset UTF-8 to the DocumentRoot section (<Directory „/srv/httpd/htdocs“>)
  • Uncomment Include /etc/httpd/extra/httpd-autoindex.conf to enable fancy directory listings
  • Uncomment /etc/httpd/extra/httpd-userdir.conf to enable user home directories Include, eg. http://~sandy/
  • See Subversion Tips for using apache as subversion server

Enable Php in Apache

Enable php by doing the following changes in /etc/httpd/httpd.conf (old: /etc/apache/httpd.conf):

<     DirectoryIndex index.html
---
>     DirectoryIndex index.php index.html
< #Include /etc/httpd/mod_php.conf
---
> Include /etc/httpd/mod_php.conf

Make sure that /etc/httpd/php.ini is identical with /etc/httpd/php.ini-recommended.

(Re)start apache with /etc/rc.d/rc.httpd restart

Test apache & php by saving the following line as /var/www/htdocs/index.php

<?php phpinfo(); ?>

Point your browser to http://localhost/. You should see infomations about your php installation there. If you get a download dialog window with something about application/x-httpd-php instead the page, especially with firefox, then empty your browser cache (you go to tools>clear private data) and try again :!:

Note: With Slack 13.0 (PHP 5.2.10) there is a problem with semaphore creating rights. To fix this change session.save_path from /var/lib/php/ back to /tmp in /etc/httpd/php.ini 1). An alternative might be to fix the permission settings of /var/lib/php/.

Note: PHP is also a great alternative to Perl or Bash command line scripts. See PHP Manual

Upgrade from Php4 to Php5

This section refers to Slack 11.0 which ships with Php4. Download & install Php5 Slack package:

wget 'http://ftp.gwdg.de/pub/linux/slackware/slackware-11.0/extra/php5/php-5.2.0-i486-1.tgz'
upgradepkg php-5.2.0-i486-1.tgz

The upgrade script of the package keeps old php.ini & mod_php.conf. We need the new files:

cp -a /etc/apache/php.ini /etc/apache/php.ini.bak
cp -a /etc/apache/php.ini-recommended /etc/apache/php.ini
cp -a /etc/apache/mod_php.conf.example /etc/apache/mod_php.conf

If you made manual changes in your old php.ini, do the same with the new php.ini now.

Note: Ulike in php4 short_open_tag is off by default in php5.

Protect a Directory with Digest Authentication

Quick and dirty example with these parameters:

  • Directory to be protected: /var/www/htdocs/digestTest/
  • Realm: 'Digest Authentication Test' (arbitrary selectable)
  • Username: testuser

Create password file .htpasswd with:

htdigest -c .htpasswd 'Digest Authentication Test' testuser

Create config file .htaccess (for Apache 1.x):

AuthType Digest
AuthName "Digest Authentication Test"
AuthDigestFile /var/www/htdocs/digestTest/.htpasswd
Require valid-user

Create config file .htaccess (for Apache 2.x):

AuthType Digest
AuthName "Digest Authentication Test"
AuthDigestProvider file
AuthUserFile /var/www/htdocs/digestTest/.htpasswd
Require valid-user

Put .htpasswd and .htaccess into /var/www/htdocs/digestTest/

Note that the manual discourages to put .htpasswd into the same directory which is to be protected, however it seems common usage. Check at least .htpasswd and .htaccess will not be displayed in your webbrowser!

More useres can be added to .htpasswd with:

htdigest .htpasswd 'Digest Authentication Test' newusername

More details at Apache manual

Enable Directory Listing

Create an .htaccess file in the regarding directory and add this line:

Options +Indexes

Note that the AllowOverride Directive must allow this. More: htaccess, Options

Virtual Hosts

Vhost documentation start

FIXME

Named Virtual Hosts

You need the NameVirtualHost directive. On Debian Lenny it is already present in /etc/apache2/ports.conf: NameVirtualHost *:80

Cookies helfen bei der Bereitstellung von Inhalten. Diese Website verwendet Cookies. Mit der Nutzung der Website erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Computer gespeichert werden. Außerdem bestätigen Sie, dass Sie unsere Datenschutzerklärung gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website. Weitere Information
becki/linux/apache_httpd.1274017832.txt.gz · Zuletzt geändert: 2010-05-16 13:50 von becki

Impressum - Datenschutzerklärung