Apache

From campisano.org
Jump to navigation Jump to search

Apache directory listing themed by Apaxy

  • NOTE: define a global folder installation path

for example, imagine

/somewhere/
 |-- site/
     |-- app/         # as YOUR_APACHE_APP_DIR_OUTSIDE_APACHE
     |-- www/         # as YOUR_APACHE_ROOT_DIR
         |-- files/   # as YOUR_FOLDER_TO_HAVE_FILELIST

so, the result will be

/somewhere/
 |-- site/
     |-- app/
         |-- apaxy-master/
     |-- www/
         |-- _dir_theme -> ../app/apaxy_master/apaxy/theme
         |-- files
             |-- .htaccess -> ../../app/apaxy_master/apaxy/htaccess.txt

Installation:

# global apaxy install, to be actived locally
cd YOUR_APACHE_APP_DIR_OUTSIDE_APACHE
wget https://github.com/AdamWhitcroft/Apaxy/archive/master.zip
unzip master.zip
rm master.zip
mv apaxy-master/apaxy/theme/htaccess.txt apaxy-master/apaxy/theme/.htaccess
mv apaxy-master/apaxy/htaccess.txt apaxy-master/apaxy/htaccess.txt_orig
cat apaxy-master/apaxy/htaccess.txt_orig | sed -e 's^theme^/_dir_theme^g' -e 's^//_dir_theme^/_dir_theme^g' > apaxy-master/apaxy/htaccess.txt
rm apaxy-master/apaxy/htaccess.txt_orig
cd YOUR_APACHE_ROOT_DIR
ln -s YOUR_APACHE_APP_DIR_OUTSIDE_APACHE/apaxy-master/apaxy/theme _dir_theme
# local apaxy activation
cd YOUR_FOLDER_TO_HAVE_FILELIST
ln -s YOUR_APACHE_APP_DIR_OUTSIDE_APACHE/apaxy-master/apaxy/htaccess.txt .htaccess

Reference

Php as fcgi

apt-get update
apt-get install apache2 apache2-mpm-worker libapache2-mod-fcgid apache2-suexec php5-cgi
a2dismod php5
a2enmod include
a2enmod actions
a2enmod rewrite
a2enmod suexec
a2enmod fcgid
/etc/init.d/apache2 stop
cd /srv/config/init.d
ln -s /etc/init.d/apache2 apache2
cd ../rc.d
ln -s ../init.d/apache2 S75_apache2
ln -s ../init.d/apache2 K25_apache2
cd /etc/apache2/sites-available
cat > SITE.WHR << EOF
<VirtualHost *:80>
    ServerName SITE.WHR

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^SITE.WHR
        RewriteRule ^/(.*)$ http://www.SITE.WHR/$1 [L,R=301]
    </IfModule>
</VirtualHost>

<VirtualHost *:80>
    ServerName www.SITE.WHR
    ServerAdmin root@SITE.WHR
    DocumentRoot /srv/domain/SITE.WHR/www

    LogLevel warn
    ErrorLog /srv/domain/SITE.WHR/log/error.log
    CustomLog /srv/domain/SITE.WHR/log/access.log combined

    <Directory /srv/domain/SITE.WHR/www>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

        <IfModule mod_fcgid.c>
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

            <IfModule dir_module>
                DirectoryIndex index.php index.html
            </IfModule>

            # mediawiki pretty url
            <IfModule mod_rewrite.c>
                RewriteEngine On
                RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
                RewriteRule ^/*$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
            </IfModule>

            AddHandler fcgid-script .php
            FCGIWrapper /usr/bin/php-cgi .php
        </IfModule>
    </Directory>
</VirtualHost>
EOF
cd ../sites-enabled
rm 000-default
ln -s ../sites-available/SITE.WHR 000-SITE.WHR
nano ../mods-available/fcgid.conf
<IfModule mod_fcgid.c>
  AddHandler	fcgid-script .fcgi
  FcgidConnectTimeout 20
### ADD FOLLOW
  FcgidMaxProcesses 5
  FcgidMinProcessesPerClass 1
  FcgidMaxProcessesPerClass 3
  FcgidIdleTimeout 30
  FcgidIdleScanInterval 10
  FcgidMaxRequestsPerProcess 100
  FcgidFixPathinfo 1
### END
</IfModule>
/etc/init.d/apache2 stop
/etc/init.d/apache2 start

Php as module

Apache

root@host:~# apt-get install gcc g++ autoconf automake make gettext binutils file libtool pkg-config libssl-dev libxml2-dev libpcre3-dev libbz2-dev libjpeg62-dev libpng12-dev libxpm-dev libgd2-xpm-dev libcurl4-openssl-dev ssl-cert libmcrypt-dev libmhash-dev libtidy-dev libpq-dev libmysqlclient15-dev libsqlite3-dev libapr1-dev libaprutil1-dev libpspell-dev
root@host:~# wget http://opensource.become.com/apache/httpd/httpd-2.2.17.tar.bz2
root@host:~# tar -xjf httpd-2.2.17.tar.bz2
root@host:~# cd httpd-2.2.17
root@host:~/httpd-2.2.17# ./configure --prefix=/usr/local/apache
root@host:~/httpd-2.2.17# make
root@host:~/httpd-2.2.17# make install
root@host:~# groupadd -g 5001 apache
root@host:~# useradd -g 5001 -u 5001 -d /usr/local/apache apache
root@host:~# chown -R apache:apache /usr/local/apache

Php

root@host:~# wget http://museum.php.net/php5/php-5.3.3.tar.bz2
root@host:~# tar -xjf php-5.3.3.tar.bz2
root@host:~# cd php-5.3.3
root@host:~/php-5.3.3# ./configure --prefix=/usr/local --enable-force-cgi-redirect --enable-fastcgi
root@host:~/php-5.3.3# make
root@host:~/php-5.3.3# make install

SuPhp

root@host:~# wget http://www.suphp.org/download/suphp-0.7.1.tar.gz
root@host:~# tar -xzf suphp-0.7.1.tar.gz 
root@host:~# cd suphp-0.7.1
root@host:~/suphp-0.7.1# ./configure --prefix=/usr/local/suphp --with-apr=/usr/local/apache/bin --with-apxs=/usr/local/apache/bin/apxs
root@host:~/suphp-0.7.1# make
root@host:~/suphp-0.7.1# make install

CORS Origin workaround

<IfModule mod_headers.c>
    # from http://stackoverflow.com/a/22331292
    # tested at http://regexr.com/3e33k
    SetEnvIf Origin "^(https?://(?:[\w-]+\.?)+(?::\d{1,5})?)(?:/.*)?$" CORS_ALLOW_ORIGIN=$1
    Header set Access-Control-Allow-Origin %{CORS_ALLOW_ORIGIN}e env=CORS_ALLOW_ORIGIN
    Header merge Vary "Origin"
    Header set Access-Control-Allow-Credentials "true"
    Header set Access-Control-Max-Age "1728000"
</IfModule>

MPM

Worker