I have an apache2 config file under /etc/init.d/apache2/conf.d/ which uses Perl Sections.
I am just trying to test if a module is loaded and configure apache as appropriate.
if( Apache->module( "mod_ssl.c" ) )
{
...
} else { ... }
This is the error I see though when restarting. I've also tried Apache2->method but get same error.
# /etc/init.d/apache2 restart
Restarting web server: apache2Building Appliance configuration for Debian 5.0.7
Syntax error on line 73 of /etc/apache2/conf.d/foobar.conf:
\t(in cleanup) Can't locate object method "module" via package "Apache" (perhaps you forgot to load "Apache"?) at /etc/apache2/conf.d/foobar.conf line 357.\n
failed!
I don't think it is an #INC problem... And apache and libapache2-mod-perl2 packages are both installed. In fact if I comment that line out the rest of the perl actually runs fine.
perl -e 'print join "\n",#INC'
/etc/perl
/usr/local/lib/perl/5.10.0
/usr/local/share/perl/5.10.0
/usr/lib/perl5
/usr/share/perl5
/usr/lib/perl/5.10
/usr/share/perl/5.10
/usr/local/lib/site_perl
I've also tried using the Apache::compat and "Apache2->module".
I suspect the problem is something is missing in startup.pl - but I've been googling and reading the mod perl docs and going round in circles. Any suggestions stackoverflow???
BTW- my startup.pl:
#!/usr/bin/perl -w
use strict;
use lib qw( /usr/lib/perl5/ /usr/lib/perl5/Bundle /usr/lib/perl5/Apache2 ) ;
BEGIN
{
use Apache2 ();
my $hostname = `hostname`;
}
use Apache;
use Apache::DBI ();
use Apache2::Const ();
use Apache2::Log ();
use Apache2::URI ();
use Apache2::compat;
use LWP::UserAgent ();
use DBI() ;
1;
The documentation on porting from 1.0 to 2.0 suggests Apache2::Module::loaded()
Related
I have two servers with the same configurations: httpd + mod_perl (I thought the settings were 100% the same), but in one server I got some perl warnings, while in the other server the same warnings get me FATAL errors. Look:
Server A log:
Use of uninitialized value in numeric eq (==) at
Server B log:
[Wed Jun 08 14:32:47 2016] [error] Use of uninitialized value in string eq at
In server A the request flow goes on and the user gets the desired result, but in server B the user gets a 500 error.
I am using
use strict;
use warnings;
in the file on both servers.
Any thoughts ?
Example of the code causing this warning/FATAL:
$allowed_sellers = any { $_ == $user->{user_id} } (111,123,222,345);
UPDATE:
I found this code in a module that I am using (Moo):
package Moo::_strictures;
use strict;
use warnings;
sub import {
if ($ENV{MOO_FATAL_WARNINGS}) {
require strictures;
strictures->VERSION(2);
#_ = ('strictures');
goto &strictures::import;
}
else {
strict->import;
warnings->import;
}
}
1;
But the env variable MOO_FATAL_WARNINGS seems to not be defined. Any thougts ?
SOLVED:
Guys, thanks a lot! We have finally discovered the problem: In server A the version of module Moo was 1.003 while server B was using a newer version 2.000001
Before version 2, calling use Moo; enabled strictures, which makes all warnings fatal except for a few categories. This caused a lot of problems*, so warnings are no longer fatal in version 2 and up.
To fix, upgrade Moo to the latest version. While you're at it, you should really fix the cause of the warnings, too.
* See the following discussions:
Default fatalization of warnings needs mst's clarification before new major strictures
fatal warnings are a ticking time bomb
Moo 2 and strictures 2
Ubuntu 16.04
PHP 7.0.4
Phalcon 2.1.x
Zephir
$~: php -v
PHP Fatal error: Class 'jsonserializable' not found in Unknown on line 0
When add phalcon.so in php.ini
Somehow I found the answer on and old bug report here:
Segmentation fault after update to 2.1.x
The problem is that the phalcon extension is being loaded before the json extension, so I guess that you, as myself, added the extension=phalcon.so line in the main php.ini
What you have to do is add a file in /etc/php/7.0/mods-available called phalcon.ini with the line in it: extension=phalcon.so
Then you just go and make a softlink that points from /etc/php/7.0/cli/conf.d/50-phalcon.ini to that phalcon.ini file, (important to put a number higher than 20 so it gets loaded after the json extension) and that's it!
Repeat the process to any other configuration that you have for php (apache, nginx, etc).
I'm using a perl cgi script that uses our own libraries, which use the "no autovivification" pragma. E.g.
/usr/lib/company/mysim.cgi:
#!/usr/bin/perl -w
use strict;
# ... other use
use Company::Module1;
/usr/lib/perl5/Company/Module1.pm
package Company::Module1;
no autovivification;
use strict;
use warnings;
Approximately 50% of the time, when accessing the URL to reach the cgi script the compilation fails with...
[Fri Dec 04 15:40:10.744901 2015] [:error] [pid 30455:tid 2961136448] Bareword "A_HINT_STRICT" not allowed while "strict subs" in use at /usr/lib/i386-linux-gnu/perl5/5.20/autovivification.pm line 144.\nBareword "A_HINT_WARN" not allowed while "strict subs" in use at /usr/lib/i386-linux-gnu/perl5/5.20/autovivification.pm line 144.\nBareword "A_HINT_FETCH" not allowed while "strict subs" in use at /usr/lib/i386-linux-gnu/perl5/5.20/autovivification.pm line 144.\nBareword "A_HINT_STORE" not allowed while "strict subs" in use at /usr/lib/i386-linux-gnu/perl5/5.20/autovivification.pm line 144.\nBareword "A_HINT_EXISTS" not allowed while "strict subs" in use at /usr/lib/i386-linux-gnu/perl5/5.20/autovivification.pm line 144.\nBareword "A_HINT_DELETE" not allowed while "strict subs" in use at /usr/lib/i386-linux-gnu/perl5/5.20/autovivification.pm line 144.\nCompilation failed in require at /usr/lib/company/mysim.cgi line 14.\nBEGIN failed--compilation aborted at /usr/lib/company/mysim.cgi line 14.\n
(taken from /var/log/apache2/ssl/error.log as this script sits on the https port).
My environment is:
- debian jessie (8.2)
- tomcat7
- apache2 (2.4)
- perl 5.20.2
- libautovivification-perl 0.12-1+b1
My questions are:
Has anyone seen this before? It seems odd that the autovivification module fails to compile due to a "use strict" pragma.
Can anyone explain the intermittent nature of the compilation error? Even more odd, the cgi fails to compile ~half the time, and works fine (i.e. runs and returns expected results) the other ~half.
Thanks for your time.
09/12/2015: Some additional information...
Thanks all for the feedback.
There's no explicit creation of threads, though this is in the context of apache so there's presumably threading of requests.
The root cause does seem to be a failure in the XSLoader. At least this minimal working example...
package autovivification;
use 5.008_003;
use strict;
use warnings;
our $VERSION;
BEGIN {
$VERSION = '0.12';
}
BEGIN {
require XSLoader;
XSLoader::load(__PACKAGE__, $VERSION);
}
my %bits = (
strict => A_HINT_STRICT,
warn => A_HINT_WARN,
fetch => A_HINT_FETCH,
store => A_HINT_STORE,
exists => A_HINT_EXISTS,
delete => A_HINT_DELETE,
);
compiles, whereas this
package autovivification;
use 5.008_003;
use strict;
use warnings;
our $VERSION;
BEGIN {
$VERSION = '0.12';
}
#BEGIN {
# require XSLoader;
# XSLoader::load(__PACKAGE__, $VERSION);
#}
my %bits = (
strict => A_HINT_STRICT,
warn => A_HINT_WARN,
fetch => A_HINT_FETCH,
store => A_HINT_STORE,
exists => A_HINT_EXISTS,
delete => A_HINT_DELETE,
);
fails with the same error.
So, I'll go a-poking around for a load error in the apache logs.... somewhere.
Thanks again for your time.
16/12/2015: Update - Fixed
The root cause was mod_perl, combined with a (possible) change between apache 2.2 and 2.4. The apache configuration for the script, which gives it a ScriptAlias URI of /cgi-bin/script, occurs before setting up the URI /cgi-bin to be handled by mod_perl. In apache 2.2, this ordering seems to be important and the script was not handled by mod_perl. However, in apache 2.4 the ordering does not seem to be important and the script is now handled by mod_perl.
The error arose because this script was not (and never meant to be) handled by mod_perl. The fix was to change the URI for the script to /somethingelse/script.
Thanks to everyone for the comments.
The root cause was mod_perl, combined with a (possible) change between apache 2.2 and 2.4. The apache configuration for the script, which gives it a ScriptAlias URI of /cgi-bin/script, occurs before setting up the URI /cgi-bin to be handled by mod_perl. In apache 2.2, this ordering seems to be important and the script was not handled by mod_perl. However, in apache 2.4 the ordering does not seem to be important and the script is now handled by mod_perl.
The error arose because this script was not (and never meant to be) handled by mod_perl. The fix was to change the URI for the script to /somethingelse/script.
– HalfOpenedEye
I am completely new to Seleniu, and am trying to set up PHPUnit with Selenium 2, following this tutorial https://www.youtube.com/watch?v=zva_GETXimI
So far this is what I've done:
Installed PHPUnit using PHAR as instructed here https://phpunit.de/manual/current/en/installation.html
Installed Selenium Server
Upgraded to PHP5.6 (but my Apache is still 2.22 instead of 2.4)
Installed PHPUnit_selenium package using Composer
Created a testLogin.php file:
<?php
class testLogin extends PHPUnit_Extensions_Selenium2TestCase{
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/Achievers');
}
}
When I run testLogin.php using 'phpunit testLogin.php' I get an error:
Class 'PHPUnit_Extensions_Selenium2TestCase' not found in /home/osadmin/projects/Sel/testLogin.php on line 5
Since I am just starting out, I have no idea how to fix this. On googling the error, it shows to add this line to my php file:
require_once('PHPUnit/Extensions/Selenium2TestCase.php');
But I'm not sure how I can use this since there is no PHPUnit folder, just a file linked to the PHAR.
Could someone please shed some light on how to fix this issue?
Thanks.
EDIT:
As per Ushakov's suggestion, I tried /path/to/phpunit.phar testLogin.php
But it gives the same error.
If I add this line to the testLogin.php: require_once('/usr/local/bin/phpunit');
and run /path/to/phpunit.phar testLogin.php
I get this:
#!/usr/bin/env php
PHP Notice: Constant __PHPUNIT_PHAR__ already defined in /usr/local/bin/phpunit on line 18
PHP Notice: Constant __PHPUNIT_PHAR_ROOT__ already defined in /usr/local/bin/phpunit on line 19
PHP Fatal error: Cannot redeclare class DeepCopy\DeepCopy in phar:///usr/local/bin/phpunit/myclabs-deep-copy/DeepCopy/DeepCopy.php on line 15
Solved it by adding this line to the PHP file:
require_once 'vendor/autoload.php';
No tutorial I have seen mentions this, but it can be found in github projects
For anyone else coming late to the party - this worked for me:
class testLogin extends \PHPUnit\Extensions\Selenium2TestCase
(Using PHP 7.0.3 and installing Selenium package with Composer ).
This is for a shared config file that should include another file if it exists, but still work otherwise. If I do
Include foo.conf
and foo.conf doesn't exist, apache will complain:
could not open document config file /etc/httpd/conf/foo.conf
I came up with a clever solution, though there may be a better way. Put one of the characters in brackets so Apache will treat it as a glob pattern, which is allowed to match zero files without causing an error. E.g.:
Include foo.con[f]
According to http://httpd.apache.org/docs/2.4/mod/core.html#include you could use "IncludeOptional":
Alternatively, the following command will just be ignored in case of missing files or directories:
IncludeOptional conf/vhosts/*/*.conf
IncludeOptional foo.conf
Apache httpd version 2.3.6 and later
https://httpd.apache.org/docs/2.4/mod/core.html#includeoptional
I tried the same as Wouter Van Vliet, but I still got errors. Then I found this link. I added this snippet to my /etc/apache2/apache2.conf and it works like a charm!
Note: You need mod_perl for it!
Here is the code:
<perl>
use File::stat;
foreach $file (glob '/srv/www/vhosts/*/conf/vhost.conf') {
my $stat = stat($file);
if ($stat->uid != 0 || $stat->gid != 0) {
warn "$file is not owned by root:root, skipping!\n";
next;
}
if ($stat->mode & 0002) {
warn "$file is world-writable, skipping!\n";
next;
}
push #Include, $file;
}
</perl>