venerdì 24 luglio 2009

Linux - Installare apache 2.2 con supporto ssl, mod_rewrite, php e webdav

Scaricate httpd-2.2 dal sito www.apache.org e php dal sito www.php.net.

In questa guida si fa riferimento alle seguenti versioni:

A) httpd-2.2.9

B) php-5.2.6

Il tutto verrà installato nella dir /usr/local

Scompattare httpd-2.2.9.tar in /usr/local:

#cd /usr/local

#tar -xvf httpd-2.2.9.tar

Creiamo la dir /usr/local/apache:

#mkdir /usr/local/apache

Stariamo php-5.2.6.tar dentro /usr/local/apache:

#cd /usr/local/apache

#tar -xxvf php-5.2.6.tar

Fatto questo nella dir /usr/local/apache bisogna creare il link simbolico php che punta la dir php-5.2.6:

#ln -s /usr/local/apache/php-5.2.6 php

Spostiamoci in /usr/local/httpd-2.2.9 eseguire i seguenti comandi:
#./buildconf
#./configure --prefix=/usr/local/apache --with-mpm=prefork --enable-mods-shared=all --enable-modules=all --enable-authn-anon -enable-usertrack --enable-proxy --enable-ssl --enable-http --enable-dav --enable-info --enable-cgi --enable-dav-fs --enable-dav-lock --enable-speling --enable-rewrite --enable-so
#make
#make install

Ora andiamo nella dir /usr/local/php e lanciamo i seguenti comandi:

#cd /usr/local/php

#./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql --prefix=/usr/local/apache/php --with-config-file-path=/usr/local/apache/php --enable-force-cgi-redirect --disable-cgi --with-zlib --with-gettext --with-gdbm
#make
#make install
#libtool --finish /usr/local/apache/php-5.2.6/libs
#cp -p php.ini-recommended /usr/local/apache3/php/php.ini

Aggiungi queste direttive in /usr/local/apache/conf/httpd.conf (se già ci sono verifica la loro correttezza):

LoadModule php5_module modules/libphp5.so
AddHandler php5-script php

Aggiungi index.php alla tua riga DirectoryIndex :


DirectoryIndex index.html index.php

Inoltre, nello stesso file httpd.conf non dimenticare di aggiungere anche:

AddType text/html php

AddType application/x-httpd-php-source phps

Dentro il file httpd.conf inoltre verificare i moduli che vengono caricati dai vari LoadModule e controllare che le voci relative a mod_ssl, mod_dav, mod_dav_fs, mod_rewrite, mod_usertrack siano scommentate
Esempio di un mod_ssl correttamente caricato:

LoadModule ssl_module modules/mod_ssl.so

Ora configuriamo apache2 sempre attraverso il file httpd.conf
. Modifichiamo i Listen:

Listen INDIRIZZOIP:80

Listen INDIRIZZOIP:443

Scriviamo il ServerName nel file /usr/local/apache/conf/httpd.conf :

ServerName www.MIOSERVER.it

Scommentare gli Include necessari nel file /usr/local/apache3/conf/httpd.conf :

# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf


# Multi-language error messages

#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
Include conf/extra/httpd-autoindex.conf

# Language settings
Include conf/extra/httpd-languages.conf

# User home directories
Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
Include conf/extra/httpd-info.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
Include conf/extra/httpd-dav.conf

Editiamo il file /usr/local/apache/conf/extra/httpd-ssl.conf
Editare il parametro Listen:
Listen INDIRIZZOIP:443

Generiamo il certificato ssl con il comando openssl:
openssl req -new -x509 -days 9999 -keyout /usr/local/apache/conf/server.key -out /usr/local/apache3/conf/server.crt
Generating a 1024 bit RSA private key
....++++++
.++++++
writing new private key to '/usr/local/apache3/conf/server.key'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:



You are about to be asked to enter information that will be incorporated into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.


Country Name (2 letter code) AU:IT
State or Province Name (full name) Some-State:Mi
Locality Name (eg, city) :Milano
Organization Name (eg, company) Internet Widgits Pty Ltd:MIAAZIENDA Srl
Organizational Unit Name (eg, section) :MIAAZIENDA Team
Common Name (eg, YOUR name) :www.MIOSERVER.it
Email Address :indirizzodiposta@miodominio.it

Se, come me, la odiate potete togliere la pass phrase dal certificato ssl:

#cp /usr/local/apache/conf/server.key /usr/local/apache/conf/server.key.bak
#openssl rsa -in /usr/local/apache/conf/server.key.bak -out /usr/local/apache/conf/server.key

Verificare il corretto path dei file .key e crt appena creati nel file /usr/local/apache/conf/extra/httpd-ssl.conf (eventualmente correggete il path)
Ora editiamo il file /usr/local/apache/conf/extra/httpd-vhosts.conf
Nel nostro esempio conterrà:


ServerAdmin indirizzodiposta@miodominio.it
DocumentRoot "/usr/local/apache/htdocs"
ServerName www.MIOSERVER.it
ErrorLog "logs/www.MIOSERVER.it-error_log"
CustomLog "logs/www.MIOSERVER.it-access_log" combined env=!dontlog
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

RewriteEngine on
RewriteLog logs/www.MIOSERVER.it.rewrite.txt
RewriteLogLevel 4

Editiamo il file /usr/local/apache/conf/extra/httpd-ssl.conf
Nel nostro esempio va editata la seguente parte:


# General setup for the virtual host
DocumentRoot "/usr/local/apache/htdocs"
ServerName www.MIOSERVER.it
ServerAdmin indirizzodiposta@miodominio.it
ErrorLog "/usr/local/apache/logs/www.MIOSERVER.it-443-error_log"
TransferLog "/usr/local/apache/logs/www.MIOSERVER.it-443-access_log"
RewriteEngine on
RewriteLog logs/www.MIOSERVER.rewrite.txt
RewriteLogLevel 0



Editiamo il file /usr/local/apache/conf/extra/httpd-dav.conf

IL CONTENUTO DEL FILE DOVRA' ESSERE ESATTAMENTE QUESTO A PARTE IL PATH DEI FILES DavLockDB E AuthUserFile che vanno adattati a seconda del caso:

#
# Distributed authoring and versioning (WebDAV)
#
# Required modules: mod_dav, mod_dav_fs, mod_setenvif, mod_alias
# mod_auth_digest, mod_authn_file
#

# The following example gives DAV write access to a directory called
# "uploads" under the ServerRoot directory.
#
# The User/Group specified in httpd.conf needs to have write permissions
# on the directory where the DavLockDB is placed and on any directory where
# "Dav On" is specified.

DavLockDB /usr/local/apache/var/DavLock

Alias /webdav /usr/local/webdav


SSLRequireSSL
DAV On
Order Allow,Deny
Allow from all

AuthType Basic
AuthName "WebDAV Restricted"
AuthUserFile "/usr/local/apache/webdavuser"
Require user webdav



#
# The following directives disable redirects on non-GET requests for
# a directory that does not include the trailing slash. This fixes a
# problem with several clients that do not appropriately handle
# redirects for folders with DAV methods.
#
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully


Creare la dir /usr/local/webdav e settarne i permessi:

#mkdir
/usr/local/webdav
#chown -R daemon:staff /usr/local/webdav
#chmod -R 744
/usr/local/webdav

Creare l'utenza webdav:

#cd /usr/local/apache/bin
#./htpasswd -c /usr/local/apache/webdavuser webdav

Creare la dir /usr/local/apache/var e settare i permessi:

#mkdir /usr/local/apache/var
#chmod -R 744 /usr/local/apache/var
#chown -R daemon:staff /usr/local/apache/var

Ora possiamo startare apache:

#/usr/local/apache/bin/apachectl start

Verifichiamo Apache via web:

http://www.MIOSERVER.it
https://www.MIOSERVER.it

Verifichiamo webdav lanciando konqueror e scrivendo la seguente URL:
webdavs://www.MIOSERVER.it/webdav
AUTENTICARSI CON L'UTENTE WEBDAV E PROVARE A CREARE DIRECTORY DI TEST

Verifichiamo php creando nella dir /usr/local/apache/htdocs il file testphp.php dentro al quale scriviamo:



// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>

Con il nostro browser apriamo la seguente pagina:

http://www.MIOSERVER.it/testphp.php

Se visualizzeremo correttamente le proprietà della nostra versione di php abbiamo terminato l'installazione del nostro server apache.

lunedì 20 luglio 2009

Questo Blog....

finalmente on line, se riuscirò ad avere tempo raccoglierò in questo spazio esperienze di lavoro e di vita...una piccola goccia nell'oceano di internet...