Gestion dynamique des dossiers

De Wiki de Jordan LE NUFF
Sauter à la navigation Sauter à la recherche

Présentation

Cette page a pour objet de proposer des configurations permettant de publier dynamiquement des dossiers dans Apache. Cela permet de ne pas à avoir à modifier la configuration Apache lors d'un ajout d'un(e) dossier/arborescence supplémentaire.

Mise en œuvre

Dans le cas où il n'est pas envisageable de modifier la configuration Apache à chaque création d'un nouveau dossier, il est possible de donner accès à des dossiers correspondant à une expression régulière (voir la documentation à propos de la directive Directory). Voici un exemple :

Exemple simple

# Appli de recette
<VirtualHost *:80>
	ServerAdmin mymail@mydomain.com
	DocumentRoot "/data/www/REC"
	ServerName rec-appli.mydomain.com
	RewriteEngine On
	ErrorLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_error.log 10M"
	CustomLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_access.log 10M" combined
	php_flag log_errors on
	php_flag display_errors off
	# 32767 for E_ALL, 8 for E_NOTICE, 2 for E_WARNING, 1 for E_ERROR
	# More information on https://www.php.net/manual/fr/errorfunc.constants.php
	php_value error_reporting "8"
	php_value error_log /data/logs/rec-appli.mydomain.com_php_error.log
	LogLevel debug
	
	<Directory ~ "/data/www/REC/appli.*">
		Options FollowSymLinks
		AllowOverride All
		Order allow,deny
		Allow from All
	</Directory>
</VirtualHost>

Dans cet exemple, seuls les dossiers commençant par /data/www/REC/appli seront publiés.

Exemple plus recherché

Autre exemple un peu plus recherché :

Define app_name myapp.mydomain.com
# Instance de développement
<VirtualHost *:80>
	Define url_app dev-${app_name}
	ServerName ${url_app}
	DocumentRoot "/data/www/DEV"
	ErrorLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_error.log 10M"
	CustomLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_access.log 10M" combined
	LogLevel debug
	
	php_flag log_errors on
	php_flag display_errors off
	# 32767 for E_ALL, 8 for E_NOTICE, 2 for E_WARNING, 1 for E_ERROR
	# More information on https://www.php.net/manual/fr/errorfunc.constants.php
	php_value error_reporting "8"
	php_value error_log /data/logs/${app_name}/${url_app}_php_error.log

	AliasMatch "^/(\w*)/(.*)$" "/data/www/DEV/$1/MyApp/public/$2"
	<Directory ~ "/data/www/DEV/\w*/MyApp/public">
		DirectoryIndex index.php
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
	UnDefine url_app
</VirtualHost>
UnDefine app_name

Exemple plus dynamique

Define app_name myapp.mydomain.com
Define doc_root_parent "/data/www"
Define doc_root_child "MyApp/public"
# Instance de développement
<VirtualHost *:80>
	Define url_app dev-${app_name}
	ServerName ${url_app}
	DocumentRoot "${doc_root_parent}/DEV"
	ErrorLog "|/local/www/2.4.12/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_error.log 10M"
	CustomLog "|/local/www/2.4.12/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_access.log 10M" combined
	LogLevel debug
	
	php_flag log_errors on
	php_flag display_errors off
	# 32767 for E_ALL, 8 for E_NOTICE, 2 for E_WARNING, 1 for E_ERROR
	# More information on https://www.php.net/manual/fr/errorfunc.constants.php
	php_value error_reporting "8"
	php_value error_log /data/logs/${app_name}/${url_app}_php_error.log

	AliasMatch "^/([[:alpha:]]+)(/.*)?" "${doc_root_parent}/DEV/$1/${doc_root_child}$2"
	<Directory "${doc_root_parent}/DEV/*/${doc_root_child}">
		DirectoryIndex index.php
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
	UnDefine url_app
</VirtualHost>

# Instance de recette
<VirtualHost *:80>
	Define url_app rec-${app_name}
	ServerName ${url_app}
	DocumentRoot "${doc_root_parent}/REC/${doc_root_child}"
	ErrorLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_error.log 10M"
	CustomLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_access.log 10M" combined
	LogLevel debug	
	
    php_flag log_errors on
    php_flag display_errors off
	# 32767 for E_ALL, 8 for E_NOTICE, 2 for E_WARNING, 1 for E_ERROR
	# More information on https://www.php.net/manual/fr/errorfunc.constants.php
	php_value error_reporting "32767"
	php_value error_log /data/logs/${app_name}/${url_app}_php_error.log
	
	<Directory "${doc_root_parent}/REC/${doc_root_child}">
		DirectoryIndex index.html index.php
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
	UnDefine url_app
</VirtualHost>

# Instance de intégration
<VirtualHost *:80>
	Define url_app int-${app_name}
	ServerName ${url_app}
	DocumentRoot "${doc_root_parent}/INTEGRATION/${doc_root_child}"
	ErrorLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_error.log 10M"
	CustomLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_access.log 10M" combined
	LogLevel debug	
	
    php_flag log_errors on
    php_flag display_errors off
	# 32767 for E_ALL, 8 for E_NOTICE, 2 for E_WARNING, 1 for E_ERROR
	# More information on https://www.php.net/manual/fr/errorfunc.constants.php
	php_value error_reporting "32767"
	php_value error_log /data/logs/${app_name}/${url_app}_php_error.log
	
	<Directory "${doc_root_parent}/INTEGRATION/${doc_root_child}">
		DirectoryIndex index.html index.php
		AllowOverride All
		Require all granted
	</Directory>
	UnDefine url_app
</VirtualHost>

# Instance de préproduction
<VirtualHost *:80>
	Define url_app pprd-${app_name}
	ServerName ${url_app}
	DocumentRoot "${doc_root_parent}/PREPROD/${doc_root_child}"
	ErrorLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_error.log 10M"
	CustomLog "|/local/www/current/bin/rotatelogs -t -l -n 15 /data/logs/${app_name}/${url_app}_http_access.log 10M" combined
	LogLevel debug	

	php_flag log_errors on
	php_flag display_errors off
	# 32767 for E_ALL, 8 for E_NOTICE, 2 for E_WARNING, 1 for E_ERROR
	# More information on https://www.php.net/manual/fr/errorfunc.constants.php
	php_value error_reporting "32767"
	php_value error_log /data/logs/${app_name}/${url_app}_php_error.log

	<Directory "${doc_root_parent}/PREPROD/${doc_root_child}">
		DirectoryIndex index.html index.php
		AllowOverride All
		Require all granted
		SetEnv APP_ENV "pprd"
	</Directory>
	UnDefine url_app
</VirtualHost>
UnDefine doc_root_child
UnDefine doc_root_parent
UnDefine app_name