5

The server is a VPS running CentOS 7 64bit with CyberPanel. Perl is already present (ver 5.16.3) and will run scripts from the command line.

However, clicking a link to a Perl script just results in the browser attempting to download the script file.

I have tried modifying the $PATH on the server. I have updated Perl and attempted to add modules involved in CGI such as httpd and Perl-CGI but they were already present. Oh, and the scripts' permissions are set to allow execution.

If necessary, server set-up can be rerun to start over clean and there are even choices of Linux operating systems if something other than CentOS 7 64bit would be a better option.

I have googled a lot of info and it seems there are configuration files that may need to be edited but different sources referenced different files and that was never the only step. I could not seem to find info directly related to my situation. Efforts to adapt the available info to this situation have been unsuccessful.

I am not a professional but have been programming in Perl and creating and maintaining websites on "managed" servers for more than 20 years. This is an unmanaged server. So, I need information to set up cgi myself.

If that info is already on this site, please advise. My searches were unsuccessful. Otherwise, any help would be appreciated.

No doubt, additional information may be necessary to provide assistance and I will try to respond to any requests as quickly as possible.

1st edit to add/clarify

First - Thanks for the assistance.

Found /etc/httpd/conf.modules.d/XX-cgi.conf (actual file=01-cgi.conf) and verified the LoadModule line is present and not commented out. It is actually in a conditional statement:

<IfModule mpm_worker_module>
   LoadModule cgid_module modules/mod_cgid.so
</IfModule>
<IfModule mpm_event_module>
   LoadModule cgid_module modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
   LoadModule cgi_module modules/mod_cgi.so
</IfModule>

Added the Options +ExecCGI and AddHandler cgi-script .cgi .pl commands to the httpd.conf file in the appropriate Directory directive that also included AllowOverride None and Require all granted.

<Directory "/home/wannabesports.site/public_html/games/cgi-bin/">
AllowOverride None
Options +ExecCGI
AddHandler cgi-script .cgi .pl
Require all granted
</Directory>

Per the Apache Tutorial, a SciptAlias command was also modified to point to the appropriate directory:

ScriptAlias /cgi-bin/ "/home/wannabesports.site/public_html/games/cgi-bin/"

The systemcfl restart command fails

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

So, I did a VPS reboot from the host's hPanel which may not have been a sufficient alternative as the problem persists. If you can provide any additional insight, it would be appreciated.

Also, is there any clue in the fact that a URL pointing to a script file results in the browser downloading that file rather than printing it out or displaying an error?

2nd edit to add/clarify

Ran the commands to see the error and received the following:

[root@WANNABEsports /]# systemctl status httpd.service -l
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2023-03-23 06:21:48 UTC; 3min 23s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 14999 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 14999 (code=exited, status=1/FAILURE)

Mar 23 06:21:48 WANNABEsports.name systemd[1]: Starting The Apache HTTP Server...
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: (98)Address already in use: AH00073: make_sock: unable to listen for connections on address [::]:80
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: (98)Address already in use: AH00073: make_sock: unable to listen for connections on address 0.0.0.0:80
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: no listening sockets available, shutting down
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: AH00015: Unable to open logs
Mar 23 06:21:48 WANNABEsports.name systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Mar 23 06:21:48 WANNABEsports.name systemd[1]: Failed to start The Apache HTTP Server.
Mar 23 06:21:48 WANNABEsports.name systemd[1]: Unit httpd.service entered failed state.
Mar 23 06:21:48 WANNABEsports.name systemd[1]: httpd.service failed.

and . . .

[root@WANNABEsports /]# journalctl -xe
--
-- Unit httpd.service has begun starting up.
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: (98)Address already in use: AH00073: make_sock: unable to listen for connections on address [::]:80
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: (98)Address already in use: AH00073: make_sock: unable to listen for connections on address 0.0.0.0:80
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: no listening sockets available, shutting down
Mar 23 06:21:48 WANNABEsports.name httpd[14999]: AH00015: Unable to open logs
Mar 23 06:21:48 WANNABEsports.name systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Mar 23 06:21:48 WANNABEsports.name systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
--
-- The result is failed.
Mar 23 06:21:48 WANNABEsports.name systemd[1]: Unit httpd.service entered failed state.
Mar 23 06:21:48 WANNABEsports.name systemd[1]: httpd.service failed.
Mar 23 06:21:48 WANNABEsports.name sudo[14995]: pam_unix(sudo:session): session closed for user root

I can see both contain reference to failure but don't understand what's needed to correct the situation.

3rd edit to add/clarify

I believe this server is running openlitespeed rather than apache. How does that effect what's needed to get CGI working?

1 Answer 1

3

There are three pieces of Apache configuration that you need:

  1. The CGI module is loaded
  2. The ExecCGI permissions is enabled.
  3. Handler configuration for your script's file extension.

Loading the CGI module

The CGI module is usually installed with Apache, but it (and many other modules) are not loaded by default. Somewhere in your Apache configuration there should be a line like LoadModule cgid_module modules/mod_cgid.so. On CentOS, this should be in /etc/httpd/conf.modules.d/XX-cgi.conf. You need to make sure that line isn't commented out. If it starts with a # you need to remove the # and restart the webserver with sudo systemctl restart httpd.service.

Enabling CGI execution

The Apache directory configuration where your script is located needs to have Options +ExecCGI. Look for the <Directory>...</Directory> directive in your Apache configuration that matches the place where your script is located and add that line within it. If you make changes to Apache conf, you again need to restart the Apache service.

Alternately, if you are using .htaccess, this line can be added to the .htaccess file in same directory as your script. Then you don't need to restart the server. But this only works if AllowOverride All is specified in the relevant <Directory> configuration.

Handler configuration

You also need to tell CGI that it should be handling .cgi or .pl scripts. This should usually be on the next line after the Options +ExecCGI. The line is: AddHandler cgi-script .cgi .pl. Again, you need to restart apache if you make changes to config files.

See Apache Tutorial: Dynamic Content with CGI

2
  • I believe this server is running openlitespeed rather than apache.
    – jMyk17
    Mar 23, 2023 at 11:31
  • Thank you Stephen Ostermiller. You were spot on. Once I realized my server was not apache, it was changed to apache and using your info it is now operating as intended.
    – jMyk17
    Mar 24, 2023 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.