As far as I've tried, none of the usual solutions works for me. Well, my problem, I'm receiving an 500 Error every time I upload a "large file" (600 KB ~), with smaller images it works fine. So..., even with this (extreme) .htaccess file it keeps happening, and yes, .htaccess are active:
upload_max_filesize = 100M
post_max_size = 100M
memory_limit = 128M
max_input_time = 6000
max_execution_time = 6000
So, I take a look at the logs and find this (is only one line, just pasted it as easy to read with line jumps):
[Mon Jul 27 17:09:28.<port> 2015] [:error] [pid 21423] [client <ip>]
ModSecurity: Access denied with code 44 (phase 2).
Match of "eq 0" against "MULTIPART_UNMATCHED_BOUNDARY" required.
[file "/etc/httpd/conf.d/mod_security.conf"]
[line "35"] [id "<another id>"]
[msg "Multipart parser detected a possible unmatched boundary."]
[hostname "<my host>"] [uri "<my script>"] [unique_id "<id (useless I think)"]
But, now I not able to find how to edit the mod_security (it has the default config, and empty activated_rules) config in order (i think) to allow this "large" file uploads. I'm running PHP 5.3 in Apache 2.4/CentOS 7.
The fact you have a ModSecurity alert means that you can't have empty activated_rules folder or you are including the rules in some other way.
There are known problems with ModSecurity for this error and it seems very susceptible to false positives.
The main advice when I rule is raising too many false positives is to just turn off that rule (I'm assuming it's rule 200003 that's firing but replace the id as appropriate):
SecRuleRemoveById 200003
I got the same error:
ModSecurity: Access denied with code 44 (phase 2). Match of "eq 0" against "MULTIPART_UNMATCHED_BOUNDARY" required. [file "/etc/httpd/conf.d/mod_security.conf"] [line "34"] [id "200003"] [msg "Multipart parser detected a possible unmatched boundary."]
But #nilpo answer was correct
I got this issue due to the image name and after changing the name issue solved.
But it's not something I want because I know the solution but my customer did't know that they have to change the name.
try to check FcgidBusyTimeout parameter in fcgi configuration
Rename the file you are attempting to upload. This error indicates the file name contains a character that is disallowed by mod_security. Rename the file and then try uploading it again. By disabling the mentioned line in mod_security.conf, it will happily skip past this check but that leaves your server open to vulnerabilities.
all i am found SOLUTION!!!
UBUNTU 16.04 + Apache (MY mod_secure WORK AND UPLOAD OK)
0. apache a2enmod headers (activate headers and .htaccess)
1. CHECK .htaccess !!!!!
//in .htaccess
php_value upload_max_filesize 50M
php_value post_max_size 50M
//if you want custom in .htaccess
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
https://www.maketecheasier.com/securing-apache-ubuntu/ instruction for commands
sudo nano /etc/apache2/mods-enabled/security2.conf - last 2 lines i am comment
sudo nano /etc/modsecurity/modsecurity.conf - configuration mod_secure is easy
sudo nano /etc/apache2/apache2.conf - apache configuration CTRL+W
//on/off
bash->a2dismod mod-security2 //off
or
bash->a2dismod security2 //off
bash->a2enmod mod-security2 //on
bash->a2enmod security2 //on
If you want you can remove specific rules:
http://www.inmotionhosting.com/support/website/modsecurity/find-and-disable-specific-modsecurity-rules
SecRuleRemoveById 950004 in modsecurity.conf
4. Byteconverter - http://whatsabyte.com/P1/byteconverter.htm
THIS IS ENOUGHT!!!!
4 hour!!
Related
I can't import in new localhost site my previous site which is on server? I am exported .wpress file and now I want to import. I using All-in-one plugin and toxedo plugin for maximum upload file size. Error which i got is
"Unable to import Unable to open file for reading. File:
C:\Bitnami\wordpress-5.3-0\apps\wordpress\htdocs\wp-content\plugins\all-in-one-wp-migration\storage\wdfoahbbl74z\myapp.com-20191120-060914-394.wpress"
When i go to see logs a see this:
Nov 20 2019 12:38:59 {"type":2,"message":"POST Content-Length of
711871094 bytes exceeds the limit of 41943040
bytes","file":"Unknown","line":0}
Nov 20 2019 12:39:02 {"Number":2,"Message":"filesize(): stat failed
for
C:\Bitnami\wordpress-5.3-0\apps\wordpress\htdocs\wp-content\plugins\all-in-one-wp-migration\storage\wdfoahbbl74z\myapp.com-20191120-060914-394.wpress","File":"C:\Bitnami\wordpress-5.3-0\apps\wordpress\htdocs\wp-content\plugins\all-in-one-wp-migration\functions.php","Line":233}
Nov 20 2019 12:39:02 {"Number":2,"Message":"Division by
zero","File":"C:\Bitnami\wordpress-5.3-0\apps\wordpress\htdocs\wp-content\plugins\all-in-one-wp-migration\lib\model\import\class-ai1wm-import-validate.php","Line":67}
Nov 20 2019 12:39:02
{"Number":2,"Message":"fopen(C:\Bitnami\wordpress-5.3-0\apps\wordpress\htdocs\wp-content\plugins\all-in-one-wp-migration\storage\wdfoahbbl74z\myapp.com-20191120-060914-394.wpress):
failed to open stream: No such file or
directory","File":"C:\Bitnami\wordpress-5.3-0\apps\wordpress\htdocs\wp-content\plugins\all-in-one-wp-migration\lib\vendor\servmask\archiver\class-ai1wm-archiver.php","Line":98}
Did anyone know where is my mistake ?
according to
Nov 20 2019 12:38:59 {"type":2,"message":"POST Content-Length of 711871094 bytes exceeds the limit of 41943040
bytes","file":"Unknown","line":0}
you need to change php settings to allow bigger POST size than 40M. the new value should be a bit bigger than your backup filesize
EDIT: during the chat we figured that bitnami has it's own php.ini in C:/Bitnami/wordpres/php/php.ini and this one had the bad (small) value. updating this file finally allowed to fix the issue with the POST limit.
#flinty2000 solved it in https://wordpress.org/support/topic/unable-to-open-file-for-reading-5/.
In my case, it worked just adding the extension (downloading the "basic" from https://import.wp-migration.com/ and uploading in my website through the plugin uploader).
This issue happens in case when we use pulgin to increase the max import size or incase we haven't properly increased the the max import size in php service .
You can try below steps :
This might be weird solution but worked for me.
Step 1: find php.ini file in /etc folder or / folder by running below cmd:
grep -rl "post_max_size" | xargs ls -lrth
Here I have used the post_max_size keyword to search the "php.ini" file in /etc folder ,but in some systems you can find this on /var/www/html or /var/www/wordpress folders.
We have multiple posts on the internet as if the php.ini file is not present in the WordPress folder then you can create but in my case that doesn't work.
Step 2:
Edit php.ini file and change the value like this.
post_max_size = 100M
upload_max_filesize = 100M
In the above you can set any value as per your requirement.
Step 3:
Restart the httpd or Nginx or apache and PHP service, or as per setup, you can restart the web service.
For me httpd and php-fpm service restart worked in centos 8 :
service httpd restart
service php-fpm restart
I use apache httpd on Centos7 (SELinux) and am trying to create an output filter to modify all served html pages. I've browsed some tutorials on how to create them, but I keep stumbling on step one even before I get to the coding part.
Currently I have this in my httpd.conf
ExtFilterDefine portal_header mode=output intype=text/html cmd="/var/www/root/main/portal/portal.php"
SetOutputFilter portal_header
To pinpoint my problem I have deleted all the actual code in the file /var/www/root/main/portal/portal.php for the moment and currently it looks like this
#!/usr/bin/php
<php?
/* test */
?>
But when I know try to access any html on the server I get "500 Internal Server Error". After commenting out the SetOutputFilter line in httpd.conf the pages work so the error is generated by the filter.
In my error log it reads
[Fri Feb 10 14:36:55.458174 2017] [ext_filter:error] [pid 171495] (13)Permission denied: [client 10.2.8.109:49278] AH01458: couldn't create child process to run `/var/www/root/main/portal/portal.php'
[Fri Feb 10 14:36:55.458215 2017] [ext_filter:error] [pid 171495] (13)Permission denied: [client 10.2.8.109:49278] AH01467: can't initialise output filter portal_header: aborting
I have at least
changed the file permissions to 777
verified that php is located at /usr/bin/php and owned by apache group with proper rights
tried to add and remove ScriptAlias and/or SetHander cgi-script for the directory in httpd.conf
tried with completely empty script file
but none of the above has any effect. The only change in matters was that when I deliberately mis-spelled the file name I got "No such file or directory" error instead.
Does anyone have an idea what I should do to make this work? For the moment I would be happy to see the script to even do nothing at all, if it just didn't break, and only afterwards add some functionalities into it.
UPDATE: I was able to pinpoint the problem to SELinux policies, since after disabling them (setenforce 0) the error vanished. So currently I'm trying to figure out how I should alter the policies.
I ran into a similar problem when trying to improve on a simple sed filter command.
According to the https://httpd.apache.org/docs/2.4/mod/mod_ext_filter.html documentation it should be possible to use a command like sed as a filter and indeed it does:
The following filter works for me and replaces global links to local ones so that i can use a docker image with data from an existing site.
# Filter configuration
# mod_ext_filter directive to define a filter which
# replaces text in the response
#
ExtFilterDefine fixtext mode=output intype=text/html \
cmd="/bin/sed s#http://ceur.ws.org#http://capri:8880#g"
<Location "/">
# core directive to cause the fixtext filter to
# be run on output
SetOutputFilter fixtext
</Location>
when trying to replace the sed command with accessing a script with
"cmd=/root/bin/filter.sh"
I got the error message :
AH01458: couldn't create child process to run `/root/bin/filter.sh'
AH01467: can't initialise output filter fixtext: aborting
which is your original reason for your question.
Now i am also looking for a better solution and tried:
cmd="/bin/bash /root/bin/filter.sh"
assuming that the shebang resolving might be the culprit. Interestingly i then get:
AH01461: apr_file_write(child input), len 0
AH01468: ef_unified_filter() failed
and that's why i am already posting this answer in the hope I'll find a proper solution soon or others might be able to help because the list of related AH014## error codes is getting longer in this Q&A thread.
See https://github.com/omnigroup/Apache/blob/master/httpd/modules/filters/mod_ext_filter.c for the relevant source code.
I am assuming that the apr_proc_create is not capable of calling scripts using a shebang. So my workaround was to
call the command directly
switch to awk
Working apache filter.conf
# Filter configuration
# mod_ext_filter directive to define a filter which
# replaces text in the response
#
ExtFilterDefine fixtext mode=output intype=text/html \
cmd="/usr/bin/awk -f /var/www/filter.awk"
<Location "/">
# core directive to cause the fixtext filter to
# be run on output
SetOutputFilter fixtext
</Location>
working awk script to filter links
# WF 2020-06-03
#
# filter HTML output thru this awk script to fix global links to local ones
#
# you might want to try out this filter from the command line with
# cat /var/www/html/index.html | awk -f filter.awk
#
# setup the replacement
BEGIN {
port=8880
host="capri"
sourceServer="http://ceur-ws.org"
targetServer=sprintf("http://%s:%s",host,port)
}
# for each line
{
# get the line
line=$0
# replace any sourceServer reference with the targetServer reference
gsub(sourceServer,targetServer,line)
# output the modified line
print line
}
/root/bin/filters.sh
#!/bin/bash
# WF 2020-06-02
# filter all html output thru this script
port=8880
host=capri
# substitute all hard links in CEUR-WS with a local link
/bin/sed s#http://ceur.ws.org#http://$host:$port#g
# try out this filter with
# cat /var/www/html/index.html | /root/bin/filter.sh | grep capri
I had a LAMP application running wordpress and I deleted the whole directory and replaced with new files - php based.
Now, when I go to view my server running CentOS - it just shows a 500 Internal Server error.
I've tried:
restarting server
restarting apache service itself
both completed successfully, but this didn't fix anything. Now, I do not know where to go from here.
apache logs # /usr/local/apache/logs/error_log on apache:
[Tue Apr 22 11:12:15 2014] [error] [] SoftException in Application.cpp:357: UID of script "index.php" is smaller than min_uid
I found the fix myself, this wasn't an error with Mysql at all, but rather a permissions issue with the index.php file I had.
The error, which I found in /usr/local/apache/logs/error_log was:
:is smaller than min_uid Premature end of script headers: index.php
To fix, I did this:
ls -l in the directory causing the issue (mine was public_html)
You should see the index file (e.g. index.php) that should be causing the issue. It is due to a root user having the only permission to the file and not your CPanel (or system) username. (note this system/cpanel name)
Run the following within the errorneous directory(Note: this command must be run within all subdirectories of the primary errorneous directory.):
sudo chown yoursystemuserhere:yoursystemgroupuserhere index.php
or to apply to the whole directory (thanks to #Prix):
sudo chown -R user:group /folder
You're all set.
Further literature here: http://www.inmotionhosting.com/support/website/general-server-setup/uid-smaller-than-min-uid
I hope this helps someone else in the future.
I had similar symptoms on my cPanel VPS - I was able to use easyApache to recompile Apache and PHP which fixed the problem for me.
(I realise my problem was slightly different to yours, but it may be helpful for people in the future who have the same problem I had).
chown -R user.usergroup /path_to_the_directory
Will resolve this. It is basically permission issues.
just install wordpress latest version make sure you have atleast php version 5.3 and above also look global register variable if it off or just delete htacess file from server and see what will happens
generally 500 internal server gives when file permission is missing so you should delete htacess file
I found many errors like this one
[Wed Nov 06 14:34:01 2013] [warn-phpd] mmap cache can't open C:\www\somefile.php (pid 4484 th 1668)
in my Apache error.log file. I tried to pinpoint the source of the error for some time but with no luck so far.
I find out that PHP Opcache is not the culprit.
error_log did not help. I think that my PHP source codes do not affect the error.
My stack: Apache 2.4.6, Windows, PHP 5.4.20
Did anyone encounter the same error?
Note: The error message I get is not the same as, for example, the error:
Mon Dec 1 21:08:20 2008] [warn-phpd] mmap cache can't open /var/www/vhosts/domain.com/httpdocs/file.php - Permission denied (pid 7831)
where there is a reason why mmap can't open the file.
This is caused by the total number of files that are opened by the server. If this is on a hosting company then they would be able to resolve this for you, if you are on your own system then try these steps:
Edit the apache startup script, \Program Files\Apache Software Foundation\Apache2.2\etc\init.d\httpd (may be different on your system) and add this before anything else:
ulimit -n 20480 #Raise the ulimit to a higher value then you have
Then Restart apache using httpd.exe restart
Hope this points you in a general direction
Disable MMAP. It's not supported on Windows.
It's an efficient method to map files to memory, to work on their content. Similar story with sendfile, an efficient method to send the content of a file as a response.
# https://httpd.apache.org/docs/2.4/en/mod/core.html#enablemmap
EnableMMAP On
EnableSendfile Off
Mon Dec 1 21:08:20 2008] [warn-phpd] mmap cache can't open
/var/www/vhosts/domain.com/httpdocs/file.php - Permission denied (pid
7831)
It seems that mmap doesn't has the rights to open the file, check file's folder rights .
Check file's folder properties .
I am having issue on PHP where my app is trying to run a php backup file and suddenly getting HTTP Error 500 Code. I have checked the logs and this what it saying.
[Tue Aug 28 14:17:28 2012] [warn] [client x.x.x.x] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://example.com/backup/backup.php
[Tue Aug 28 14:17:28 2012] [error] [client x.x.x.x] Premature end of script headers: backup.php, referer: http://example.com/backup/backup.php
Anyone knows how to fix this? I'm really stuck in here and can't find solution in internet.
Hope anyone could share their knowledge.
Thanks.
James
I managed to solved this by adding FcgidBusyTimeout . Just in case if anyone have similar issue with me.
Here is my settings on my apache.conf:
<VirtualHost *:80>
.......
<IfModule mod_fcgid.c>
FcgidBusyTimeout 3600
</IfModule>
</VirtualHost>
I had very similar errors in the Apache2 log files:
(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
Premature end of script headers: phpinfo.php
After checking the wrapper scripts and Apache2 settings, I realized that /var/www/ did not have accordant permissions. Thus the FCGId Wrapper scripts could not be read at all.
ls -la /var/www
drwxrws--- 5 www-data www-data 4096 Oct 7 11:17 .
For my scenario chmod -o+rx /var/www was required of course, since the used SuExec users are not member of www-data user group - and they should not be member for security reasons of course.
if you want to install a PHP version < 5.3.0, you must replace
--enable-cgi
with:
--enable-fastcgi
in your ./configure statement, excerpt from the php.net doc:
--enable-fastcgi
If this is enabled, the CGI module will be built with support for FastCGI also. Available since PHP 4.3.0
As of PHP 5.3.0 this argument no longer exists and is enabled by --enable-cgi instead. After the compilation the ./php-cgi -v should look like this:
PHP 5.2.17 (cgi-fcgi) (built: Jul 9 2013 18:28:12)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
NOTICE THE (cgi-fcgi)
I had this issue and realized that the file cgi-bin/php-fcgi had no execution rights.
It had 644 mode while is should have 755 mode.
Setting the correct mode was impossible (probably because the file was opened or sth), so I copied that file from another domain directory where it had proper rights already set and that fixed everything.
I had the same problem with a different and simple solution.
Problem
I installed PHP 5.6 following the accepted answer to this question on Ask Ubuntu.
After using Virtualmin to switch a particular virtual server from PHP 5.5 to PHP 5.6, I received a 500 Internal Server Error and had the same entries in the apache error log:
[Tue Jul 03 16:15:22.131051 2018] [fcgid:warn] [pid 24262] (104)Connection reset by peer: [client 10.20.30.40:23700] mod_fcgid: error reading data from FastCGI server
[Tue Jul 03 16:15:22.131101 2018] [core:error] [pid 24262] [client 10.20.30.40:23700] End of script output before headers: index.php
Cause
Simple: I didn't install the php5.6-cgi packet.
Fix
Installing the packet and reloading apache solved the problem:
sudo apt-get install php5.6-cgi if you are using PHP 5.6
sudo apt-get install php5-cgi if you are using a different PHP 5 version
sudo apt-get install php7.0-cgi if you are using PHP 7
Then use service apache2 reload to apply the configuration.
The famous Moodle "replace.php" script can generate this situation too.
For me it was taking ages to run and then failed with a 500 message in the browser and also with the above error message in my apache error log file.
I followed up on #james-wise answer:
FcgidBusy is readably described in the Apache documentation. I tried this: doubled the amount of time which apache would give my script to run, by inserting the following line in /etc/apache2/mods-available/fcgid.conf
FcgidBusyTimeout 600
Then I restarted Apache and tried to run my replace.php script again.
Fortunately this time the script instance ran to completion, so for my purposes this served as a solution.
I came across this one while debugging a virtualmin/apache related error.
In my case, I am running virtualmin and had in my virtual machine's php.ini
safe_mode=On.
In my Virtual Machine's error log, I was getting the fcgi Connection reset by peer: mod_fcgid: error reading data from FastCGI server
In my main apache error log I was getting:
PHP Fatal error: Directive 'safe_mode' is no longer available in PHP in Unknown on line 0
In my case, I simply set safe_mode = Off in my php.ini and restarted apache.
stackoverflow.com/questions/18683177/where-to-start-with-deprecated-directive-safe-mode-on-line-0-in-apache-error
Not in this questions askers case but often:
What does the "premature end of script headers" error mean?
That error means that the FCGI call was exited unexpectedly.
In some cases it means that the script "backup.php" did crash.
How to fix this?
If the crash of a script was the cause, fix the script so that it does not crash. Then this error is fixed, too. To find out if and why a script crashes, you need to debug it. For example you can check the PHP error log. Errors logged to STDERR normally go into the error handler of the FCGI.
I had the same problem with long-running scripts with the error messages
"Premature end of script headers: index.php" and "Connection reset by peer: mod_fcgid: error reading data from FastCGI server" in error_log.
After hours of testing this helps for me (CentOS 6, PHP-FPM 7, Plesk 12.5.30):
edit the config file:
/etc/httpd/conf.d/fcgid.conf
Set a higher running time. In my case 600 seconds
create the new entry:
FcgidBusyTimeout 600
adapt following entries:
FcgidIOTimeout 600
FcgidConnectTimeout 600
restart httpd:
service httpd restart
In CentOS releases suexec is compiled to run only in /var/www. If you try to set a DocumentRoot somewhere else you have to recompile it - the error in apache log are:
(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
Premature end of script headers: php5.fcgi
Just install php5-cgi
in debian
sudo apt-get install php5-cgi
in Centos
sudo yum install php5-cgi
Check /var/lib/php/session and its permissions. This dir should be writable by user so the session can be stored
As already mentioned this could be happening due to fcgi handler permission issues. If you're using suexec - don't forget to check if apache has this module enabled.
I increased max execution time to 600 seconds job done !
If you're on a shared server like me the host said it was a result of hitting memory limits, so they kill scripts which results in the "Premature end of script headers" seen in this error. They referred me to this:
https://help.dreamhost.com/hc/en-us/articles/216540488-Why-did-procwatch-kill-processes-on-my-Shared-serv
Given an increase in memory, the issues went. I think a backup plugin Updraft on wordpress was perhaps over zealous in its duty/settings.
In my case I was using a custom extension for my PHP files and I had to edit /etc/apache2/conf-available/php7.2-fpm.conf and add the following code:
<FilesMatch ".+\.YOUR_CUSTOM_EXTENSION$">
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>
I've tried the majority of answers that I've found on this issue. My issue was with wp-cron.php executing a particular function.
I'm working on Plesk CentOS7, Apache server.
I used this related question and suggested answer to help me find out how to adjust the fcgid.conf memory limit utilizing the command line.
Upon trying to troubleshoot the limits on the fcgid.conf file (/etc/httpd/conf.d/fcgid.conf) and restarting apache gracefully, I found that there was no change.
After seeing that other cron jobs were running properly, I decided to refer back to my function declared in functions.php and found that some of the arguments declared were not being specified properly, so there was a loop occurring that would eventually lead to the timeout.
Upon fixing this and running the cron again, it ran as it should.
Hope this helps someone else in a similar position!
I got the same problem (with Plesk 12 installed).
However, when i switched from execute PHP as FastCGI to Apache Module the website worked.
Checked my suexec log:
$ cd /var/log/apache2/
$ less suexec.log
When you find something like this:
[2015-03-22 10:49:00]: directory is writable by others: (/var/www/cgi-bin/cgi_wrapper)
[2015-03-22 10:49:05]: uid: (10004/gb) gid: (1005/1005) cmd: cgi_wrapper
try this commands
$ chown root:root /var/www/cgi-bin/cgi_wrapper
$ chmod 755 /var/www/cgi-bin/cgi_wrapper
$ shutdown -r now
as root.
I hope it can help you.