[Update, I've amended to reflect the die
problem that was fixed thanks to comments below]
After upgrading from Fedora 39 to 41, my apache (httpd-2.4.63-1.fc41.x86_64) server is giving strange results. I run scripts out of a public_html (755 permissions) using apache's virtual host with public_html with userdir (I also have it set up to use ssl). Note that I've turned off selinux for this whole exercise, thinking that that was my source of issue. The problem still persists.
I have this very simple script called simpletest.cgi
(which worked as is before the upgrade):
require DB_File;
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>CGI Test Script</TITLE></HEAD>\n";
print "<BODY>\n";
print "Test\n";
tie %dbase, 'DB_File', "/<fullpath>/data/billyard_clean.db" or die "Can't open file: $!<br>\n";
print "(".$dbase{"I14.NAME"}.")<br>\n";
print "\n</BODY>\n</HTML>\n";
exit;
I get two different outputs depending on whether I run it as a command line script or through the httpd server.
Running perl -w simpletest.cgi
in the same directory gives me the expected output:
Content-type: text/html
<HTML><HEAD><TITLE>CGI Test Script</TITLE></HEAD>
<BODY>
Test
(Andrew Philip /Billyard/)<br>
</BODY>
</HTML>
Yet if I run this in the browser with URL https://<address>/~user/cgi-bin/simpletest.cgi
, the code halts at the database tie
line, with only the output:
<HTML><HEAD><TITLE>CGI Test Script</TITLE></HEAD>
<BODY>
Test
The /var/log/httpd/ssl_error_log
file reports that the $!
error generated is Read-only file system. Note that I have verified that SElinux is off and that the script is ran as the same user as when it is ran on the command line.
Any suggestions?
[Update, I've amended to reflect the die
problem that was fixed thanks to comments below]
After upgrading from Fedora 39 to 41, my apache (httpd-2.4.63-1.fc41.x86_64) server is giving strange results. I run scripts out of a public_html (755 permissions) using apache's virtual host with public_html with userdir (I also have it set up to use ssl). Note that I've turned off selinux for this whole exercise, thinking that that was my source of issue. The problem still persists.
I have this very simple script called simpletest.cgi
(which worked as is before the upgrade):
require DB_File;
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>CGI Test Script</TITLE></HEAD>\n";
print "<BODY>\n";
print "Test\n";
tie %dbase, 'DB_File', "/<fullpath>/data/billyard_clean.db" or die "Can't open file: $!<br>\n";
print "(".$dbase{"I14.NAME"}.")<br>\n";
print "\n</BODY>\n</HTML>\n";
exit;
I get two different outputs depending on whether I run it as a command line script or through the httpd server.
Running perl -w simpletest.cgi
in the same directory gives me the expected output:
Content-type: text/html
<HTML><HEAD><TITLE>CGI Test Script</TITLE></HEAD>
<BODY>
Test
(Andrew Philip /Billyard/)<br>
</BODY>
</HTML>
Yet if I run this in the browser with URL https://<address>/~user/cgi-bin/simpletest.cgi
, the code halts at the database tie
line, with only the output:
<HTML><HEAD><TITLE>CGI Test Script</TITLE></HEAD>
<BODY>
Test
The /var/log/httpd/ssl_error_log
file reports that the $!
error generated is Read-only file system. Note that I have verified that SElinux is off and that the script is ran as the same user as when it is ran on the command line.
Any suggestions?
Share Improve this question edited Mar 26 at 23:59 jaf0faj asked Mar 26 at 12:14 jaf0fajjaf0faj 515 bronze badges 3- 1 Try using an absolute path instead of a relative one. – choroba Commented Mar 26 at 12:33
- Thanks, but that dIdn't fix the issue. The die command (now properly syntaxed) executes with a "Read-only file system" regardless of whether I use relative or absolute paths, if the script is ran from apache. If run on the command line, it works fine (using either path type). – jaf0faj Commented Mar 26 at 19:45
- @jaf0faj You should edit your question to add updated information – TLP Commented Mar 26 at 20:40
2 Answers
Reset to default 5You are attempting to access a file in a location relative to the script's directory, but you are actually accessing a file in a location relative to the current work directory (which could be anything).
Add
use FindBin qw( $RealBin );
and replace
"../data/billyard_clean.db"
with
"$RealBin/../data/billyard_clean.db"
Note that you are unintentionally ignoring failures because of a bug.
tie %dbase, 'DB_File', "..." || die "...";
means
tie( %dbase, 'DB_File', ( "..." || die( "..." ) ) );
so the die
will never execute. You want
tie %dbase, 'DB_File', "..." or die "...";
This is equvialent to
tie( %dbase, 'DB_File', "..." ) or die( "..." );
Thanks for everyone's input. The culprit was the new systemd that rolled out with Fedora 40. In /usr/lib/systemd/system/httpd.service
there is a switch ProtectHome=read-only
which was causing the read-only file system problem. Solution:
- Edit this file via the command
sudo systemctl edit httpd
and on line 3 (after the first two commented lines at the top) add:
[Service]
ProtectHome=no
- Run
sudo systmctl restart httpd
Note that it is not recommended to edit /usr/lib/systemd/system/httpd.service
directly since package updates may overwrite this fix. Instead, the method above supposedly will transfer this fix to each update.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744146085a4560429.html
评论列表(0条)