I have a large apache config and would like to use variables to clean up the config file. My config file has over 80 similar entries that I believe can be cleaned up if I could figure out how to use the variables.
I want to take the name of the files with in a directory and use it as the variable.
Directory here is /www/pub/sites/8.0/conf/ inside the conf file are the php files of the sites. I want to make or use the name of any file that has .php at the end and use the name as the variable. So if there's a file called clark apache would use the variable ${siteName}
which would be a file called clark.php. Hope I'm explaining myself correctly or you can at least understand what I want to do.
- Code: Select all
Redirect /direct /direct.php
<Directory /pub/www/sites/8.0/htdocs>
Require all granted
# Enable ".htaccess" to password protect directories.
AllowOverride AuthConfig
</Directory>
Alias /forms /pub/www/sites/forms
<Directory /pub/www/sites/forms>
Require all granted
</Directory>
<VirtualHost *:80>
SetEnv siteName gentry
DocumentRoot "/pub/www/sites/8.0/htdocs"
ServerName gentry.testwebs.com
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
<VirtualHost *:80>
SetEnv siteName foster
DocumentRoot "/pub/www/sites/8.0/htdocs"
ServerName foster.testwebs.com
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
<VirtualHost *:80>
SetEnv siteName mcintosh
DocumentRoot "/pub/www/sites/8.0/htdocs"
ServerName mcintosh.testwebs.com
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
<VirtualHost *:80>
SetEnv siteName clark
DocumentRoot "/pub/www/sites/8.0/htdocs"
ServerName clark.testwebs.com
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
### code basically repeats itself. etc ........
this give me an error when I start apache.
[Wed Jul 07 08:09:41.846350 2021] [core:warn] [pid 21457:tid 140546613625472] AH00111: Config variable ${siteName} is not defined
Could I clean it up using something like this?
- Code: Select all
SetEnv sitesName "/www/pub/sites/8.0/conf/${sitesName}.php"
<Directory /pub/www/sites/8.0/htdocs>
Require all granted
# Enable ".htaccess" to password protect directories.
AllowOverride AuthConfig
</Directory>
Alias /forms /pub/www/sites/forms
<Directory /pub/www/sites/forms>
Require all granted
</Directory>
<VirtualHost *:80>
SetEnv sites "/www/pub/sites/8.0/conf/${sitesName}.php"
DocumentRoot "/pub/www/sites/8.0/htdocs"
ServerName ${sitesName}.testwebs.com
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
Thank you for the help in advance.