How do I use a directory name as variable for apache.conf?

Alles, was den Apache betrifft, kann hier besprochen werden.

How do I use a directory name as variable for apache.conf?

Postby techie2013 » 07. July 2021 16:57

I dont have much coding experience and Im still learning.

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.
techie2013
 
Posts: 1
Joined: 07. July 2021 16:17
XAMPP version: 2.4
Operating System: Linux

Re: How do I use a directory name as variable for apache.con

Postby Altrea » 07. July 2021 20:05

We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11934
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to Apache

Who is online

Users browsing this forum: No registered users and 70 guests