Web

php debug from a sysadmin’s perspective’ish

As I’m helping a dev figuring out a broken wp theme, I came over this, imho, super-tip on howto print contents of a variable to the httpd log file.

In this particular case I’ve narrowed it down to a variable that seem to behave different between a 2 minor wordpress versions.

file_put_contents('php://stderr', print_r($foo, TRUE))

Will print the content of variable $foo to the httpd log, in my case I put that into places in the code to track content for a couple variables in the code, I added a ‘mark’ as well to easily grep it from the weblog

file_put_contents('php://stderr', print_r('Here man: $foo', TRUE));

I found this over at stackoverflow.com

Reload your vcl in Varnish without restart

Using varnishadm you can reload your vcl after editing it, without restarting varnish.
That means your cache is intact:

# varnishadm
varnish> vcl.load default /usr/local/varnish/etc/varnish/default.vcl
200
VCL compiled.
varnish> vcl.use default
200

varnish>

What I found really practical was that this way I also could detect and fix errors in my vcl config, without varnish going down.

varnish> vcl.load default /usr/local/varnish/etc/varnish/default.vcl
106        
Message from VCC-compiler:
Expected ')' got '{'
(program line 73), at
('input' Line 105 Pos 51)
        if ( !( req.url ~  "(login_form|manage)") {
--------------------------------------------------#

Running VCC-compiler failed, exit 1
VCL compilation failed

Have puppet replace a folder with a symlink

I’ve got some perl webapps that tend to have ‘wrong’ directory setup when I checkout the code from github. We use puppet to take care of these things for us (I will always forget these settings on at least 1 node for every upgrade) .
I noticed puppet may complain about :

[...]ensure: change from directory to link failed: Could not remove existing file

You solve this easily with the:

force => true

directive in your puppet config .

The puppet documentation is extensive, though I find it a bit cumbersome everytime I need a fast lookup for some minor detail.
Thanks to groups.google.com I found this solution quick !
(But puppet already tried to tell me that with : “: Not removing directory; use ‘force’ to override”, but I’m slow :p)

Ruby, bundle install –without development test might be troublesome in FreeBSD

I’m setting up a new Redmine installation on a FreeBSD server. I’m having trouble with:

# bundle install --without development test
Installing sqlite3 (1.3.7) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
...

Turns out I have to install the sqlite3 gem by giving bundle a hint on where to find the sqlite3.h file .

# gem install sqlite3 -- --with-sqlite3-include=/usr/local/include
Building native extensions.  This could take a while...
Successfully installed sqlite3-1.3.7
1 gem installed
Installing ri documentation for sqlite3-1.3.7...
Installing RDoc documentation for sqlite3-1.3.7...

Operating perl applications as a non perl programmer

I’ve used

cpanm --installdeps .

To install all perl module dependencies for a perl application we’re running, when trying to deploy the same app on other servers the application doesn’t work, even though I’m using the same version of perl and following the same steps for installing perl modules. (sigh)
I’m suspecting there could be some problem with newer versions of perl modules ’cause the perl code itself is rsync’ed from the working server .
Here’s how you could create an autobundle package in perl, and use cpan to install the same modules in an other environment / server .

# on the working server:
perl -MCPAN -eautobundle
Wrote bundle file
    /path/to/cpan/.cpan/Bundle/Snapshot_2012_10_04_01.pm

Now copy the […].cpan/Bundle/Snapshot_2012_10_04_01.pm to the new server / instance, put it in […].cpan/Bundle/ and issue

perl -MCPAN -e 'install Bundle::Snapshot_2012_10_04_01'

Notice: leaving out the .pm file extension when referring to the Snapshot .
Oh, and by the way
How do I list all installed perl modules ? :

cpan -l

That’s not really intuitive when you’re not a perl programmer, I’ve always started up cpan in interactive mode, haven’t figured out that one before.
Also try:

perldoc -q installed

While you’re at it, it mentions cpan -a as well, which makes that Snapshot file .
Thank you gugod.org

Using Apache as a proxy in conjunction with the Apache alias directive

When using ProxyPass in apache, it won’t obey any aliases. Apachectl configtest won’t complain, so you could end up messing around with this for a while (like I did) . For example:

[...]
Alias /foo /absolute/path/to/foo
ProxyPass / localhost:8080
[...]

In the example above the alias directive wont have anything to ‘say’. In my access.log I noticed this when clients trying to access stuff from the alias’ed dir got a 404 .
You can fix this easily by:

Alias /foo /absolute/path/to/foo
ProxyPass /foo !
ProxyPass / localhost:8080

you’re simply telling apache not to oproxy /foo ūüôā
Thank you mail-archives.apache.org and httpd.apache.org mod_proxy documentation.

Redmine 1.4. upgrade on FreeBSD 8.1 release

I stumbled over a broken Redmine 1.3 install on a server this morning. The installation is broken in 1.3 related to rubytree something something … I’m kind of a noob in FreeBSD, ¬†and even more of a noob ¬†in regard to Ruby on rails applications… today was my first look at anything related to that stuff. I’m uppgrading to Redmine 1.4 since according to maillinglists it should fix the rubytree problem, so I’m following¬†http://www.redmine.org/projects/redmine/wiki/RedmineUpgrade?version=53¬†.

 

rake generate_session_store
an error occured while installing sqlite3 (1.3.6), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.
# (fuck)
uname -a
FreeBSD pdev.mid.dmz 8.1-RELEASE-p2 FreeBSD 8.1-RELEASE-p2 #5: Tue Dec 14 11:14:21 CET 2010     root@--.amd64  amd64
ls -l /usr/local/include/sqlite3.h 
-rw-r--r--  1 root  wheel  295268 Feb 14  2011 /usr/local/include/sqlite3.h
setenv CONFIGURE_ARGS "with-sqlite3-include=/usr/local/include" # (tcsh/csh)

../gems/bin/bundle install --without development test
Fetching gem metadata from http://rubygems.org/.......
Using rake (0.9.2.2) 
Using activesupport (2.3.14) 
Using rack (1.1.3) 
Using actionpack (2.3.14) 
Using actionmailer (2.3.14) 
Using activerecord (2.3.14) 
Using activeresource (2.3.14) 
Using coderay (1.0.7) 
Using fastercsv (1.5.5) 
Using i18n (0.4.2) 
Using mysql (2.8.1) 
Using net-ldap (0.3.1) 
Using pg (0.14.0) 
Using rails (2.3.14) 
Using rmagick (2.13.1) 
Using ruby-openid (2.1.8) 
Installing sqlite3 (1.3.6) with native extensions 
Installing tzinfo (0.3.33) 
Using bundler (1.1.5) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Got it to work in the end, and got a small insight in Rugy on Rails, and gem install stuff .
Gem install help
Note: during Redmine upgrade rake told me I had to do a bundle install –without development test, and I ran into ‘command not found’ which was because the ‘bundle’ command was a Ruby gem, and those gem’s wasn’t in my path, I had to locate the ‘bundle’ gem, and call it with an absolute path (or fix my PATH variable) .

Btw: they say that “UNIX Is User Friendly. It’s Just Selective About Who Its Friends Are.”, I have a feeling Unix hasn’t selected me yet …