I got the error below when attempting to configure a Django project to be served by FastCGI via Apache for the first time. I have configured FastCGI but it had been awhile and the server I was working with had ISPConfig installed on it and what I thought to be mod_fastcgi. Below I explain the error, my mix up, and how to resolve on a Linux server.
Syntax Error: Invalid command ‘FastCGIExternalServer’, perhaps misspelled or defined by a module not included in the server configuration
I received the above error when attempting to restart Apache using the httpd init.d script as shown below.
Attempt To Restart Apache After httpd.conf Configuration Changes:
- [root@dev conf.d]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Syntax error on line 16 of /etc/httpd/conf.d/fcgid.conf:
- Invalid command 'FastCGIExternalServer', perhaps misspelled or defined by a module not included in the server configuration
The changes I made were in a httpd.conf configuration extension file located in the /etc/httpd/conf.d directory. As you know apache will look in that directory and load all .conf files as well as the main httpd.conf file. So the issue in my case was I assumed mod_fcgid was mod_fastcgi. This is not the case and mod_fcgid does not include a server directive called FastCGIExternalServer which will cause the error above and apache to not start. So you need to install mod_fastcgi instead by downloading the source, unpacking, modifying the makefile, compiling, and then configuring Apache. Below are the steps in detail.
Install mod_fastcgi To Work With Apache On CentOS Linux:
- Download mod_fastcgi: First download fastcgi by using the below command.
- wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
- Unpack mod_fastcgi Package: Now unpack the package you have downloaded by using a command similar to the below. Your command may change a bit if a newer version of mod_fastcgi has been released. After it is unpacked change into the new mod_fastcgi-X directory.
- tar -zxvf mod_fastcgi-current.tar.gz
- cd mod_fastcgi-2.4.6/
- Modify Makefile: If you attempted to compile the mod_fastcgi program right now you would receive an error similar to the below.
Error Attempting To Compile Before Modifying Makefile:bash
- [root@dev mod_fastcgi-2.4.6]# make
- make: *** No targets specified and no makefile found. Stop.
Instead copy the Makefile.AP2 to Makefile using the below command and then verify line 7 of the newly created Makefile is correct. The default for line 7 is “top_dir = /usr/local/apache2” but if you have installed Apache via yum then you probably need to modify this to “top_dir = /usr/lib/httpd”. If you have trouble locating the top directory then look at the LoadModule directive in httpd.conf and then find the modules that are loaded. If the modules directory is /usr/lib/httpd/modules then the top_dir will be set to /usr/lib/httpd.
Copy FastCGI Makefile.AP2 Example To Makefile:bash
- cp -p Makefile.AP2 Makefile
- Compile mod_fastcgi: It is time to compile mod_fcgi by running the below commands from the /usr/local/src/fastcgi-X/ directory where the Makefile you created is located.
- make install
Below is an example of what it will look like when the “make install” command is issued. You will see mod_fastcgi being installed in the Apache modules directory.
Example Install Of mod_fastcgi:bash
- [root@dev mod_fastcgi-2.4.6]# make install
- make: Entering directory `/usr/local/src/mod_fastcgi-2.4.6'
- /usr/lib/apr-1/build/libtool --silent --mode=install cp mod_fastcgi.la /usr/lib/httpd/modules/
- make: Leaving directory `/usr/local/src/mod_fastcgi-2.4.6'
- Configure Apache For mod_fastcgi: Now you need to tell Apache to load the FastCGI module by adding the below line either directly to httpd.conf or to one of the included configuration files.
- LoadModule fastcgi_module modules/mod_fastcgi.so
- Restart Apache: Last but not least you need to restart Apache using your favorite method so the changes are loaded.
Restart Apache Using httpd init.d Script:bash
- /etc/init.d/httpd restart
After installing the proper module the FastCGIExternelServer directive worked without issue and FastCGI started working without issue. It helps if you load the right Apache modules!