Internal Server Error from perl script solved by adding "-w" to the shebang line. But Why? - apache

I spent hours and hours trying to fix an Internal Server Error on a perl program. I distilled the program down to the very simplest, and nothing would work. In fact, here's the entire program:
#!/usr/local/bin/perl
use strict;
print "Content-type: text/html\n\n";
print <<"thepage";
<html><head><title>Test</title></head><body>
<p>help</p>
</body></html>
thepage
Couldn't get it to work. Permissions correct. Same directory where I have literally a hundred other scripts running constantly. httpd.conf fine. It runs from the command line when SSHing into the server. Error message says:
[Mon May 18 09:59:29 2020] [error] [client 98.190.183.148] (13)Permission denied: exec of '/data/www/facialsurgery/root/cgi-bin/test_print_2.pl' failed
[Mon May 18 09:59:29 2020] [error] [client 98.190.183.148] Premature end of script headers: test_print_2.pl
But I fixed it! By adding "-w" to the shebang line, so the line says:
#!/usr/local/bin/perl -w
But I have, as I mentioned, many many programs running fine without the -w.
What can I do to trace this down more, so I don't eventually run into more trouble with more important programs?? Thanks so much for any insight in this.

The error:
(13)Permission denied: exec of '/data/www/facialsurgery/root/cgi-bin/test_print_2.pl' failed
This means that the web server (Apache) wasn't able to execute the script due to a permission error. (13 is error number for Permission denied.) This has nothing to do with presence or absence of -w.[1]
First, determine as which user the web server (Apache) runs. For the remainder of this post, I'm going to assume it's the default, www-data.
Then, make sure the following file is readable (grants the r permission) and executable (x) by the www-data user (or its group):
/data/www/facialsurgery/root/cgi-bin/test_print_2.pl
This includes making sure the following directories are accessible (x) by the www-data user (or its group):
/data/www/facialsurgery/root/cgi-bin
/data/www/facialsurgery/root
/data/www/facialsurgery
/data/www
/data
If there's no problem with the permissions of those, you could also be running afoul or volume-wide limitations (e.g. noexec attribute on the value) or other security measures (e.g. SELinux restrictions)
I think that ancient systems used to treat everything after the shebang (#!) as the command to execute. On such a system, the kernel would try to execute the non-existent file /usr/local/bin/perl -w. But that would result in errno 2 (No such file or directory), and I don't believe any modern system does this.

Related

Pmwiki can not acquire lock file

When i want to edit a page of my pmwiki, i get a screen containing this message:
PmWiki can't process your request
Cannot acquire lockfile
We are sorry for any inconvenience.
More information
Return to http://aim-bigfoot.uzh.ch/~morpho
The message in apache's error_log is
[Tue Aug 13 12:17:51.969802 2019] [php7:warn] [pid 28521] [client xxx.xxx.xxx.xxx:34994] PHP Warning: fopen(wiki.d/.flock): failed to open stream: Permission denied in /server2/home/morpho/public_html/wiki/pmwiki.php on line 579, referer: http://server1.loc.ch/~morpho/
If i delete .flock, and try again, the same error is reported.
This happens for all pages in this particular pmwiki.
The permissions for the wiki.d directory
drwxrwxrwx. 2 morpho morpho 4096 Aug 13 12:17 /server2/home/morpho/public_html/pmwiki/wiki.d/
The security context for this directory:
drwxrwxrwx. morpho morpho unconfined_u:object_r:httpd_sys_rw_content_t:s0 /server2/home/morpho/public_html/pmwiki/wiki.d/
If i disable SELinux with sudo setenforce 0, the page can be edited.
I have a second pmwiki system with the same permissions and security contexts, differing only in the user name, where editing is not a problem.
How can i make this pmwiki editable (with enforced SELinux)?
This question is not about PmWiki engine, it is about PHP writing permission on your server. The problem is that PHP is unable to create files in /wiki.d and probably other directories.
To point the problem, you can create simple php-script like:
<?php
touch( __DIR__ . '/test.file' );
?>
When executed, it should create file /test.file , but on your server this will not work, and this is a real problem to solve.
I suggest asking your hosting provider support for help to solve this problem.

Apache error - mod_fcgid: too many processes, skip the spawn request- Hangs Server

We are running a LAMP stack on a Dreamhost dedicated server. Since updating to PHP 5.6 FastCGI we have been getting more frequent server outages and slow response times even with nominal server load. Apache is throwing the following error:
[Tue Jul 14 14:58:09 2015] [error] mod_fcgid: domain=<domain>.com too many /dh/cgi-system/php56.cgi processes (current:20, max:20), skip the spawn request
I have read of some FastCGI configurations that might help, but Dreamhost did not suggest modifying these settings. Would it be safe to update these settings on a Dreamhost server and would this help?
We are planning an audit of all CURL requests to add timeouts. Will this help the issue? Is there something else we can do to stop the php spawn requests from being skipped? Is there a way to identify an offending script that might be hanging the server?

mod mono server 4 constantly crashes with soap requests

I have a c# Soap service that I have running on my Linux Suse 12.1 VPS server. This has been working fine without problems until I made a small change to the soap service and copied it onto my VPS. I thought it must have been an issue with my change so I rolled back my changes and still not working. Even some methods that haven't been touched are failing.
However, I have tested on my Dev machine which is on windows and is working fine and have also copied the soap interface on to a linux dev machine which is set up in the exact samme way as my VPS, i.e. OpenSuse 12.1 and has all the same stuff as my VPS web server. Both work absolutely fine, not got any problems what so ever.
On the VPS host, however, mod-mono-server is constantly crashing and even though it starts up, the asmx file cannot be read, just displays server error, and I need to run rcapache2 restart to get the test page to load up.
In the apache error log file I have the following:
[Thu Aug 30 20:10:19 2012] [error] (70014)End of file found: read_data
failed [Thu Aug 30 20:10:19 2012] [error] Command stream corrupted,
last command was 1 [Thu Aug 30 20:08:47 2012] [error] Command stream
corrupted, last command was 7
I have no idea what the problem might be, I've tried rebooting the VPS but no difference.
I am using the ASP.net 4 version of mod-mono-server.
Thanks for any help you can provide.
UPDATE 1
I have just noticed something else in the apache error. The log file contains the following
[Thu Aug 30 20:46:31 2012] [notice] caught SIGTERM, shutting down
[Thu Aug 30 20:46:32 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Thu Aug 30 20:46:32 2012] [error] Not running mod-mono-server.exe because no MonoApplications, MonoApplicationsConfigFile or MonoApplicationConfigDir specified.
UPDATE 2
Have just made a discovery, not entirely sure if it helps. The soap service is working fine on the server as long as it doesn't require accessing a mysql database. If it performs a query, it displays an an internal server error 500 within the test page. but if called from PHP it causes it to crash mono. The database is a mysql database and is a local database. There's 34% RAM Free so I don't believe this is a memory issue. I've also emptied the database table to determine if this fixes it if it its something to do with the amount of data, but this hasn't fixed it either.
Thanks to #knocte suggestion I managed to figure out the problem.
When the Soap Service accesses the database it reads a config.xml to determine what username and password to use to access the database, I'm guessing that this config file managed to get corrupted during the transfer. Although I could read it in vi, but maybe there was something that was wrong with the file that stopped the soap service reading the config.
All I did was delete the file and copy and paste the content into the file manually.
For some reason mod-mono when it couldn't access the database it crashes mono, even though all the MySQL stuff within the soap service has MySQL Exception handling. #knocte suggestion of testing the soap service proved useful as when this was used to access the database from the soap service xsp4 would stop but display the error saying that it didn't have permission to access the database, even though it had the correct username and password in the config file.
Once I had re-created the config file the soap service works correctly again.
Thanks for your help.

Running binaries via the apache cgi-bin

I am trying to run a binary via the common gateway interface (cgi-bin). But whenever I try to access http://localhost/cgi-bin/binary from my browser I get HTTP 500 Internal error, with the following log entry in /var/log
[Sat May 26 15:31:55 2012] [error] [client 127.0.0.1] malformed header from script. Bad header=HTTP_HOST=localhost: binary
L.E.: This doesn't seem to happen if the cgi-bin object is a php script or python.
Make sure at the beginning of your code you output at least:
Content-type: text/html\n\n
Try this.
`#!/usr/pkg/bin/perl
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<BODY>\n";
print "<H1>Hello, world!</H1>\n";
print "</BODY>\n</HTML>";`
And make sure the 1st line #!/usr/pkg/bin/perl is also very important for it should fit your perl default directory.
You can use $ whereis perl to find the directory.

Newly Added Files Getting Permissions Error

I'm running a local WAMP server and have just batch-processed a bunch of images in Photoshop, automatically saving them to a directory. When I try to access these images from my browser, I get a 403 error.
This has not yet happened to me on this server, though I have not yet done any batch processing.
I'm running Windows 7 Professional, and I've tried giving full-access to all users across-the-board for these images, but I'm still getting this same Apache error. Here's what my logs look like:
[Tue Sep 27 15:02:37 2011] [error] [client 127.0.0.1] (OS 5)Access is denied. : file permissions deny server access: C:/wamp/www/site/img/4142.jpg, referer: http://site.local/index.html
What am I doing wrong?
Turns out Windows was encrypting these files for some reason. This is what helped me solve this:
I noticed that all my file-names in Explorer were written in Green.
After a bit of digging around, it turns out they were encrypted, so I
turned encryption off on them and everything's good now!
In order to disable decryption, select your files, right-click and go
to properties, and under "General" go to "Advanced" and remove the
tick that says "Encrypt File Contents". The file-names will then turn
back to black, and everything was fine
Source: http://www.wampserver.com/phorum/read.php?2,43642