Use IfModule sections to wrap Apache directives for dynamically-loaded (DSO) modules
Code:
Syntax error on line $number of /home/$username/public_html/.htaccess:
Invalid command 'suPHP_ConfigPath', perhaps misspelled or defined by a module not included in the server configuration
To avoid difficulty like that seen by the aforementioned error detail, please ensure to use IfModule sections to wrap directives for dynamically-loaded Apache (DSO) modules such as suPHP. For usage information I recommend referring to the official Apache/httpd documentation:
To help determine which modules are compiled-in (static) or DSO (shared), please consider the following methods:
- The following command will output a list of Apache modules that are statically compiled-in:
Code:
# /usr/local/apache/bin/httpd -l
- The following command should list any DSO modules that may be installed in the default path:
Code:
# find /usr/local/apache -maxdepth 2 -type f -regex '.*\(libexec\|modules\)/.*\.so' -print | sort
- Both of the following commands will list all loaded modules and indicate if each is static (compiled-in) or shared (DSO); this will work for Apache version 2.2, may work for Apache version 2.0, but may not work for the End-of-Life (EOL) Apache version 1.3:
Code:
# /usr/local/apache/bin/httpd -M
# /usr/local/apache/bin/httpd -t -D DUMP_MODULES
When the syntax check is performed, only statically-compiled-in modules are loaded unless the custom configuration file happens to load the needed module. If performing a syntax check and no configuration file is specified, the syntax check is performed on the main Apache configuration "httpd.conf" file, which should always load all required DSO modules and included configuration files, like php.conf that loads the suPHP module. However, when a syntax check is performed on other Apache configuration files, such as .htaccess files, it is normal to expect that they might not load the same modules or include the same configuration files that are normally handled by the main Apache configuration "httpd.conf" file. When using the Apache "httpd" binary to test configuration files through a syntax check it is dependent upon the specified configuration file to load any required modules, thus when a specified .htaccess file attempts to use a directive for a module that is not loaded, such as suPHP, you will see a syntax error unless the directive is wrapped within an IfModule section.
Here is are a few examples of what could be used to safely wrap a custom suPHP directive within an IfModule section:
-
Code:
<IfModule mod_suphp.c>
suPHP_ConfigPath /full/path/to/directory
</IfModule>
-
Code:
<IfModule mod_suphp.c>
suPHP_ConfigPath /usr/local/lib
</IfModule>
-
Code:
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/$username/public_html
</IfModule>
To perform the syntax check that is seen when a redirect is setup via cPanel, the path to your configuration file, specifically the path to your custom Apache .htaccess file, is passed to the "httpd" binary. The following command may be used to perform a syntax check via root SSH access; in this example please replace "$username" with the actual cPanel account username and ensure the file path matches the location of the applicable Apache .htaccess file to be tested:
Code:
# /usr/local/apache/bin/httpd -t -f /home/$username/public_html/.htaccess
For comparison and testing purposes, any of the following commands may be used to perform a syntax check on the main Apache configuration file:
Code:
# /usr/local/apache/bin/apachectl configtest
# /usr/local/apache/bin/httpd -t
# /usr/local/apache/bin/httpd -t -f /usr/local/apache/conf/httpd.conf