Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include a file in Apache config without generating an error when it doesn't exist?

Tags:

apache

This is for a shared config file that should include another file if it exists, but still work otherwise. If I do

Include foo.conf 

and foo.conf doesn't exist, apache will complain:

could not open document config file /etc/httpd/conf/foo.conf 
like image 523
Russell Davis Avatar asked Mar 13 '12 18:03

Russell Davis


People also ask

Which configuration option of Apache is used to specify and include other configuration files at runtime?

The main configuration file is usually called httpd. conf . The location of this file is set at compile-time, but may be overridden with the -f command line flag. In addition, other configuration files may be added using the Include directive, and wildcards can be used to include many configuration files.

How do I access Apache config file?

The location of the Apache configuration file On most systems if you installed Apache with a package manager, or it came preinstalled, the Apache configuration file is located in one of these locations: /etc/apache2/httpd. conf. /etc/apache2/apache2.

What are the configuration files inside Apache config and their purpose?

The main file is called httpd. conf. This file contains directives and containers, which enable you to customize your Apache installation. Directives configure specific settings of Apache, such as authorization, performance, and network parameters.


1 Answers

I came up with a clever solution, though there may be a better way. Put one of the characters in brackets so Apache will treat it as a glob pattern, which is allowed to match zero files without causing an error. E.g.:

Include foo.con[f] 
like image 120
Russell Davis Avatar answered Sep 16 '22 13:09

Russell Davis