Unable to get Apache2 to run simple test perl script

Bagheera

Member
Joined
Sep 2, 2024
Messages
91
Reaction score
22
Credits
870
NOTE: document root is mywebsite

localhost.mywebsite correctly displays the home page
localhost.mywebsite/cgi-bin/testPerl.pl displayed the perl script rather than execute it

cgi-bin directory with 755 permissions (recursive)
cgi-bin/testPerl.pl confirmed also with 755 permissions

So, after reading up on this and checking various online guidance, I further configured Apache2 thus:-

Within etc/Apache/Apache.conf, I added the following section :-

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI
AddHandler cgi-script .cgi .pl .py .sh .rb .go .js .php
Require all granted
</Directory>

NOTE: I've noticed that /usr/lib/cgi-bin was setup by Apache2 as an empty directory. Also, there is no such File System/cgi-bin directory.

and then restarted Apache.

localhost.mywebsite/cgi-bin/testPerl.pl now displays Not Found ... doh!

Access logs
127.0.0.1 - - [31/Aug/2025:20:57:49 +0100] "GET /public_html/home2.htm HTTP/1.1" 200 5038 "http://localhost.mywebsite/" "Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0"
127.0.0.1 - - [31/Aug/2025:20:58:07 +0100] "GET /cgi-bin/testPerl.pl HTTP/1.1" 404 504 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0"
127.0.0.1 - - [31/Aug/2025:21:02:28 +0100] "GET /cgi-bin/testPerl.pl HTTP/1.1" 404 504 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0"

NOTE: If I comment out the new section I added within Apache.conf, browser returns to displaying the testPerl.pl script again rather than executing it.

I'd put off trying to get Perl CGI scripts to work on the local site because deep down I feared something like this was likely to stump me. I was right. I'm now lost, despondent, and don't know what else to do :( Could someone please help if possible?
 
Last edited:


I checked that the apache2 cgi module was installed and it is.
Backed out the Apache2.conf addition above and ensured instead following section :-

<Directory /var/www/>
Options Indexes FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .pl .py .sh .rb .go .js .php
AllowOverride None
Require all granted
</Directory>

Restarted Apache server and retried ... Not found, again

BTW: The Perl shebang line used is
#!/usr/bin/perl
Is this wrong?

Another guidance says to ensure the Mime type is correct
etc/apache2/mods-available/mime.conf

and ensure AddHandler cgi-script is UNcommented out.

Restarted Apache server and retried ... Not found, yet again

In order to save the project, I've had no choice now but resort to using XAMPP on my old Windows 7 laptop which does run Perl CGI scripts successfully. Wish I'd done this a while back but really wanted to persevere with Linux.

The moment someone can help me get Apache2 Perl to work on Linux Mint, I'd much prefer to stick with Linux. Unfortunately at the moment, Linux Apache Perl has forced me back to Windows7 XAMPP.

Do I need to re-phrase the Perl problem on Linux Apache above, or is it that Perl on Apache is just too difficult for most of us to solve?

At least it's not critical now as this part of the project has now been transferred to Windows XAMPP and is moving forward again, albeit behind schedule.
 
Last edited:
File manager search reveals ...

/etc/perl/Net
/etc/perl/XML

/lib/x86_64-linux-gnu/perl
/lib/x86_64-linux-gnu/perl/5.34
/lib/x86_64-linux-gnu/perl/5.34.0
/lib/x86_64-linux-gnu/perl/cross-config-5.34.0
/lib/x86_64-linux-gnu/perl/debian-config-data-5.34.0

This was a standard Apache2 Perl2 module install from the cmd line.

ps: Lovin' your handle name.
 
Last edited:
which perl will give an exact match
Sorry, I don't understand your question.

In the cmd line if I cd to var/www/mywebsite/cgi-bin
and then enter ... perl testPerl.pl
the script runs as it should within the terminal window.
 
Last edited:
Sorry, I don't understand your question.

In the cmd line if I cd to var/www/mywebsite/cgi-bin
and then enter ... perl testPerl.pl
the script runs as it should within the terminal window.
you have to give Apache2 the exact path of your Perl binary. To know where your Perl binary is, you have to enter the command
Code:
which perl
in your commandline. when you have the correct path, you have to adjust your apache2 config file accordingly. Sorry for my bad English
 
Sorry, I don't understand your question.
I was replying to @tinfoil-hat response about whereis perl which searches for everything not just executable in PATH.
Shebang is correct if set to output of which perl

In the cmd line if I cd to var/www/mywebsite/cgi-bin
and then enter ... perl testPerl.pl
the script runs as it should.

---

Apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .pl .py .sh .rb .go .js .php
AllowOverride None
Require all granted
</Directory>
According to docs the handler should be set in httpd.conf:
 
First, I was a full-grown adult and I went to see the Jungle Book in the theater. It was a drive-in theater.

Second, if the path to Perl is correct, and your config is correct, you can try temporarily setting all the permissions to 777 to see if it helps.
 
Apparently that was for Apache. For Apache2 it's in Apache2.conf
I'll double check but don't think I have an httpd.conf
apache 1 is out of date, why not using apache2?

There must be httpd.conf, e.g. ls /etc/httpd/conf/httpd.conf
 
First, I was a full-grown adult and I went to see the Jungle Book in the theater. It was a drive-in theater.

Second, if the path to Perl is correct, and your config is correct, you can try temporarily setting all the permissions to 777 to see if it helps.
I'm wondering how much the jungle has matured in between those two events ;)

cgi-bin and testPerl.pl changed to 777 perms. Guess what ... Not found again. Seems to eliminate 1 thing then. Mind you if it were the perms, it'd probably prevent me from running testPerl successfully from within the terminal window.

Out of curiosity KGill, d'you know why Apache insists on saying, 'Not found' instead of say 'Access denied' where
a user fails authorisation?
 
which perl will give an exact match
Thank you CaffeineAddict.

/usr/bin/perl
and this matches the script shebang. So that's something else eliminated from causing the trouble.
 
apache 1 is out of date, why not using apache2?

There must be httpd.conf, e.g. ls /etc/httpd/conf/httpd.conf
I am using apache2. /etc/httpd/ does not exist on my system.

ls: cannot access '/etc/httpd': No such file or directory

I read on some Apache install help site that the httpd.conf settings for Apache2 is held within /etc/apache2/apache2.conf ... which most definitely is on my system
 
Last edited:
I am using apache2. /etc/httpd/ does not exist on my system.

ls: cannot access '/etc/httpd': No such file or directory

I read on some Apache install help site that the httpd.conf settings for Apache2 is held within /etc/apache2/apache2.conf ... which most definitely is on my system
you can use the following command to determine your apache2 config file
Code:
apachectl -V | grep SERVER_CONFIG_FILE
the file that get's output is the config file you want to edit. it should be located in /etc/apache2
 
Nothing wrong with your English tinfoil-hat, it was ME not reading your message properly. My bad and sorry for that.

Thank you also for your latest Linux command help. Result is ...

-D SERVER_CONFIG_FILE="apache2.conf"

and it's located within /etc/apache2/
 
Last edited:
Within my /etc/apache2/apache2.conf
<Directory /var/www/>
# ExecCGI on following line appended with ExecCGI by Bagheera 1 Sep 2025
Options Indexes FollowSymLinks ExecCGI

# Following line added by Bagheera 1 Sep 2025
AddHandler cgi-script .cgi .pl .py .sh .rb .go .js .php
AllowOverride None
Require all granted
</Directory>

and within my /etc/apache2/mods-available/mime.conf
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
# Following line uncommented out and appended with .pl .py .sh .rb .go .js .php by Bagheera - 1 Sep 2025
AddHandler cgi-script .cgi .pl .py .sh .rb .go .js .php

#
# For files that include their own HTTP headers:
#
# Following line uncommented out by Bagheera- 3 Sep 2025
AddHandler send-as-is asis

mywebsite/cgi-bin/testPerl.pl (temporarily cgi-bin and testPerl.pl permissions set to 777)
#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";
print "Perl is working on this Apache!\n";

The /etc/apache2/sites-enabled/mywebsite.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.

ServerAdmin [email protected]
DocumentRoot /var/www/mywebsite
DirectoryIndex public_html/home.htm
ServerName localhost.mywebsite
ServerAlias localhost.bmv mywebsite bmv

ErrorLog /var/www/mywebsite/logs/error.log
CustomLog /var/www/mywebsite/logs/access.log combined

# ErrorLog ${APACHE_LOG_DIR}/error.log
# CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

So it begs the question... why does localhost.mywebsite/cgi-bin/testPerl.pl
always return the the 404 Not Found - the requested URL was not found on this server.

To recap this is probably an Apache2 CGI issue as running the perl script in the terminal window does work.
The access logs are useless as they provide no additional information whatsoever, as can be gleaned from the top of this thread.

Has anyone else managed to get Apache CGI to work with Perl on a Linux Mint platform?
 
Last edited:
Did you install mod_perl?
On Debian/Ubuntu it's probably called something like this.
Code:
libapache2-mod-perl2/stable 2.0.13-2+b2 amd64
  Integration of perl with the Apache2 web server
 
I don't see any mod_perl within my /etc/apache2/mods-enabled
But mod_perl never used to be needed to run perl CGI.

ps: Off the top of your head, d'you happen to know if javascript needs to have its own module installed and configured as well?

'Cos my JS doesn't run either on a page run via Apache.
 
Last edited:


Follow Linux.org

Staff online


Top