Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include external file in apache conf

Tags:

apache

I am running apache 2.4 on my web servers and I am always trying to find ways to streamline. Is it possible to include a conf file for every Joomla website and another one for every Wordpress site that I host? I put the Joomla .htaccess configuration (https://docs.joomla.org/Special:MyLanguage/Preconfigured_htaccess) inside of the domainname.com.conf file and specify Allowaccess none for performance reasons.

It would be great to have a single file for different versions of Joomla, Wordpress or other apps that require Apache configurations instead of needing to edit dozens of conf files when the app requirements change.

I found the include directive from Apache, but not sure if it would work on an individual vhost. http://httpd.apache.org/docs/2.4/mod/core.html#include

like image 743
prophoto Avatar asked Feb 26 '26 20:02

prophoto


1 Answers

The Include does work for individual vhosts. The documentation you linked (https://httpd.apache.org/docs/2.4/mod/core.html#include) states this in the header block of the section:

Context: server config, virtual host, directory

That means that the "Include" directive can be used, amongst other places, in the virtual host section of the configuration. See here for a definition of the contexts: https://httpd.apache.org/docs/2.4/mod/directive-dict.html#Context

So you could do this:

<VirtualHost *:80>
  ServerName joomla1.example.com
  Include "conf/joomla.conf"
</VirtualHost>

<VirtualHost *:80>
  ServerName joomla2.example.com
  Include "conf/joomla.conf"
</VirtualHost>

<VirtualHost *:80>
  ServerName wordpress1.example.com
  Include "conf/wp.conf"
</VirtualHost>

<VirtualHost *:80>     
  ServerName wordpress2.example.com
  Include "conf/wp.conf"
</VirtualHost>

joomla.conf and wp.conf would contain the directives that are common to either Joomla or Wordpress.

like image 60
Christian Brandel Avatar answered Feb 28 '26 13:02

Christian Brandel