Last time I was using Apache2+PHP5 as my web server and it run normally unless too slow when server is process my script and I had change it to lighttpd + fastcgi. It faster than and low memory usage.
My problem is when lighttpd running some time it "No input file specified." but some time is ok. But when I restart lighttpd every come to normally.
I don't know why and how to solve it.
This is my config.
$SERVER["socket"] == ":80" {
$HTTP["host"] == "xxx.xxx.xxx.xxx" {
server.document-root = "/var/www/public_html"
server.errorlog = "/var/www/public_html/logs/error.log"
accesslog.filename = "/var/www/public_html/logs/access.log"
compress.cache-dir = "/var/www/public_html/cache"
}
$HTTP["host"] == "sub.domain.com" {
server.document-root = "/var/www/public_html"
server.errorlog = "/var/www/public_html/logs/error.log"
accesslog.filename = "/var/www/public_html/logs/access.log",
compress.cache-dir = "/var/www/public_html/cache"
}
index-file.names = ( "index.php", "index.html", "index.htm", "default.htm" )
url.rewrite-if-not-file = (
"^/image(.*)" => "/image-api.php$1",
"^/go/([a-zA-Z0-9_-]+)" => "/index.php?go=$1",
"^/oembed(.*)" => "/oembed_provider/index.php$1",
"^/player$" => "/library/plugin/video-player/player.swf",
"^/v(.*)" => "/cvd.php$1",
"^/me" => "/user.php",
"^/#(.*)\?(.*)" => "/profile.php?indentity=$1&$2",
"^/#(.*)" => "/profile.php?indentity=$1",
"^/url?g=(.*)" => "/url.php?g=$1",
"^/social_auth/(.*)" => "/partner_api/$1.php",
"^/c/(.*)" => "/view.php?view=$1",
"^/u/(.*)" => "/profile.php?indentity=$1",
"^/project/(.*)" => "/section.php?page=$1",
"^/min/(.*)" => "/mini/index.php$1",
"^/src/(.*)" => "/src/$1",
"^/library/(.*)" => "/library/$1",
"^/\?(.*)" => "/index.php?$1",
"^/(.*)\?(.*)" => "/page.php?p=$1&$2",
"^/(.*)" => "/page.php?p=$1"
)
$HTTP["host"] == "domain.org" {
url.redirect = ("/(.*)$" => "https://domain.com/$1")
}
$HTTP["host"] == "domain.info" {
url.redirect = ("/(.*)$" => "https://domain.com/$1")
}
$HTTP["host"] == "domain.net" {
url.redirect = ("/(.*)$" => "https://domain.com/$1")
}
}
From the FAQ, it looks like there are several possibilities:
I get the error "No input file specified" when trying to use PHP
Sadly, this error message can mean a lot of things.
A common explanation attempt: PHP is unable to locate or open the file which it
is supposed to parse.
This can have a lot of reasons:
You forgot to
add ''cgi.fix_pathinfo=1 to your php.ini'' file. See the comments in
the PHP docs. The issue here is that the environment variable
SCRIPT_FILENAME is not being passed to PHP.
Make sure you did not set
doc_root or userdir in php.ini, or if you have set it, make sure it
has the correct value (doc_root should match lighttpd's
server.document-root option in this case)
If open_basedir is set, make
sure the requested file is below one of the directories which is
specified there. In the past PHP parsed files which were not inside
open_basedir as well, but this security problem was fixed (in
php-5.2.3 or so).
If you are running PHP with different permissions
than lighttpd (spawn-fcgi with -u/-g, execwrap, suexec, ...), check
that PHP can really read the file
If you are unable to find / fix the
problem, you can use strace to see if it is a (OS-related) permission
problem (look out for stat*(...YOURFILE...) = RETURNCODE). It might
help to set max-procs to 1 and PHP_FCGI_CHILDREN as well (see fastcgi
docs) in that case, so that you can easily attach strace to the
correct php-cgi process.
Related
I got 2 server under same network and I hope to redirect domain.com/page to 192.168.2.16:22348 so i got this in lighttpd.conf according to this: lighttpd as reverse-proxy
$HTTP["url"] =~ "^/page" {
proxy.server = ( "" => ( ( "host" => "192.168.2.16", "port" => 22348 ) ) )
}
but I ended up getting redirected to 192.168.2.16/maps which doesn't exist (I only got index.html but I can't change it) and returned 404.
Is there any way to only pass IP and port but not /page?
(I also tried domain.com/google to google.com by the same way but ended up to google.com/google)
Others I also tried:
https://redmine.lighttpd.net/projects/1/wiki/Docs_ModProxy
Others I also tried: https://redmine.lighttpd.net/projects/1/wiki/Docs_ModProxy
I think you should look at proxy.header "map-urlpath" on the same page.
So instead of using www.domain.com/page, i decided to use subdomain.domain.com.
Here's what I got.
$HTTP["host"] =~ "subdomain.domain.com" {
proxy.server = ( "" => ( ( "host" => "192.168.2.16", "port" => "22348" ) ) )
}
Since there is nothing after subdomain.domain.com/, it won't pass anything but only ip and port (192.168.2.16:22348) so I don't need to modify anything from the second machine. I think this is easier to configure instead of using /page.
I'm attempting write a Perl script that asks the user to enter a MAC address. I'm using the Net::MAC module to convert whatever format MAC address the user enters to a standard format for me to use later in the script. I've got most of it working but I can't seem to figure out how to handle a situation in which they enter an invalid MAC. Something that couldn't possibly be a MAC address. Such as an entry that includes letters that aren't A-F.
I'm thinking something like the following should work but when it dies it just flat out kills the entire script rather than re-asks the user to enter the MAC again.
use Net::MAC;
my $proceed = "no";
while ($proceed eq "no"){
print "Enter the MAC address: ";
my $mac;
$mac = <>;
chomp($mac);
my $tempMac = Net::MAC->new('mac' => $mac, 'die' => 0);
if ($tempMac->die() eq "0"){
print "Looks like you entered an invalid MAC address. Please try again.\n";
} else {
my $newMac = $tempMac->convert('base' => 16,'bit_group' => 8,'delimeter' => ":");
$proceed = "yes";
}
}
Should this instead use something like a Try, Catch statement? I think in other words, I need to know how to appropriately handle the die() event without having the script completely bail on me.
See https://mvp.kablamo.org/essentials/die-eval for some info on how exceptions work in Perl and how to handle them. Consider Syntax::Keyword::Try for a familiar try/catch paradigm.
use Syntax::Keyword::Try;
my $newMac;
try {
my $tempMac = Net::MAC->new('mac' => $mac);
$newMac = $tempMac->convert('base' => 16,'bit_group' => 8,'delimeter' => ":");
$proceed = "yes";
} catch {
print "Looks like you entered an invalid MAC address. Error: $# Please try again.\n";
}
You can also validate the mac address before passing it to Net::MAC using something like Regexp::Common.
use Regexp::Common 'net';
my $newMac;
if ($mac =~ m/$RE{net}{MAC}/) {
my $tempMac = Net::MAC->new('mac' => $mac);
$newMac = $tempMac->convert('base' => 16,'bit_group' => 8,'delimeter' => ":");
$proceed = "yes";
} else {
print "Looks like you entered an invalid MAC address. Please try again.\n";
}
I am sending email using Dancer2 via the Dancer2::Plugin::Email package. The main code that I have for this is:
sub sendEmail {
my ($params,$email_address,$template) = #_;
my $text = '';
my $tt = Template->new({
INCLUDE_PATH => config->{views},
INTERPOLATE => 1,
OUTPUT => \$text
}) || die "$Template::ERROR\n";
my $out = $tt->process($template,$params);
my $email = email {
from => XXXXX,
to => $email_address,
subject => XXXXX,
body => $text,
'Content-Type' => 'text/html'
};
}
where I have hidden a couple of the fields. I have gotten the following error:
Route exception: open body: Invalid argument at
/usr/local/share/perl/5.22.1/MIME/Entity.pm line 1878. in
/usr/local/share/perl/5.22.1/Dancer2/Core/App.pm l. 1454
It is not occurring all of the time and I haven't been able to find a consistent piece of code that always fails.
I have set the host parameter of the mail server that I am using in the configuration as explained here: https://metacpan.org/pod/Dancer2::Plugin::Email Simple tests show it works, but I get sporadic errors that I can't track down.
I would like to test restful API test for file uploading.
I try to run:
$I->sendPOST($this->endpoint, $postData, ['file' => 'example.jpg']);
and I would like it to behave the same as user sent example.jpg file in file input with name file but it doesn't seem to work this way. I'm getting:
[PHPUnit_Framework_ExceptionWrapper] An uploaded file must be an array or an instance of UploadedFile.
Is it possible to upload file using REST plugin in codeception? Documentation is very limited and it's hard to say how to do it.
I'm also testing API using Postman plugin to Google Chrome and I can upload file without a problem using this plugin.
I was struggling with the same problem recently and found out that there is another way to solve the issue without using Symfony's UploadedFile class. You only need to pass the array with file data in the same format as if it were the $_FILES array. For example, this code works perfectly well for me:
$I->sendPOST(
'/my-awesome-api',
[
'sample-field' => 'sample-value',
],
[
'myFile' => [
'name' => 'myFile.jpg',
'type' => 'image/jpeg',
'error' => UPLOAD_ERR_OK,
'size' => filesize(codecept_data_dir('myFile.jpg')),
'tmp_name' => codecept_data_dir('myFile.jpg'),
]
]
);
Hope this helps someone and prevents from inspecting the framework's source code (which I was forced to do, as the docs skip such an important detail)
After testing it seems to make it work we need to use UploadedFile object as file.
For example:
$path = codecept_data_dir();
$filename = 'example-image.jpg';
// copy original test file to have at the same place after test
copy($path . 'example.jpg', $path . $filename);
$mime = 'image/jpeg';
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile($path . $filename, $filename, $mime,
filesize($path . $filename));
$I->sendPOST($this->endpoint, $postData, ['file' => $uploadedFile]);
['file' => 'example.jpg'] format works too, but the value must be a correct path to existing file.
$path = codecept_data_dir();
$filename = 'example-image.jpg';
// copy original test file to have at the same place after test
copy($path . 'example.jpg', $path . $filename);
$I->sendPOST($this->endpoint, $postData, ['file' => $path . $filename]);
The below worked for myself,
On server:
$uploadedResume= $_FILES['resume_uploader'];
$outPut = [];
if (isset($uploadedResume) && empty($uploadedResume['error'])) {
$uploadDirectory = 'uploads/users/' . $userId . '/documents/';
if (!is_dir($uploadDirectory)) {
#mkdir($uploadDirectory, 0777, true);
}
$ext = explode('.', basename($uploadedResume['name']));
$targetPath = $uploadDirectory . md5(uniqid()) . '.' . end($ext);
if (move_uploaded_file($uploadedResume['tmp_name'], $targetPath)) {
$outPut[] = ['success' => 'success', 'uploaded_path' => $targetPath];
}
}
return json_encode($output);
Sorry for the long description code :P
On Testing side:
//resume.pdf is copied in to tests/_data directory
$I->sendPOST('/student/resume', [], ['resume_uploader' => codecept_data_dir('resume.pdf') ]);
#Yaronius's answer worked for me after I removed the following header from my test:
$I->haveHttpHeader('Content-Type', 'multipart/form-data');
I'm using a lighttpd 404 error handler, with a static 404 page. The entire conf file looks like this:
server.document-root = "/home/www/local/www/mysite/html"
url.rewrite = (
"^(.*)/($|\?.*)" => "$1/index.html",
"^(.*)/([^.?]+)($|\?.*)$" => "$1/$2.html"
)
server.error-handler-404 = "/404.html"
$HTTP["scheme"] == "http" {
url.redirect = ( "^/blog.html$" => "/blog/",
// various individual redirects
)
}
$HTTP["scheme"] == "https" {
$HTTP["url"] !~ "^/blog/admin/" {
url.redirect = ( "^/(.*)" => "http://www.mysite.com/$1" )
}
}
However, when I go to an address that should 404, I do correctly see our 404 page, but the status code is 200.
The lighttpd docs say that you should get a 404 status code if using a static page.
I think we're using a static page, but could something about the way we're redirecting mean that we're actually not?
Sorry for the newbie question.
Fixed this by using server.errorfile-prefix instead - think it is simply a bug in server.error-handler-404.
Seems to be a known bug in some versions of lighttpd. I was actually using a later version than 1.4.17, but still seeing the same problem.