Entries Tagged 'PHP' ↓

Nice guide to upgrading magento

http://www.nicksays.co.uk/2010/03/fool-proof-magento-upgrades/

CODE:
  1. ./pear upgrade --force magento-core/Mage_All_Latest

fixing a hacked site

One of our Joomla! sites was "hacked" with some stupid script and the fuckers put a iframe in every page :(

But with sed that was fixed in a matter of seconds:

CODE:
  1. find . -type f -print |xargs sed -i 's/<iframe.*iqdoza.ru.*<\/iframe>//g'

OR:

CODE:
  1. find . -type f -print |xargs sed -i 's/<iframe.*.ru.*<\/iframe>//g'

Searching for hacked sites:

CODE:
  1. egrep -lir "<iframe|hacked" /home/*/public_html/*index*

Drawback is that it doesn't removed the inserted newline :S Because it isn't the design of sed (wha-evah).
Also it doesn't handle files with spaces in the filename. But that's only minor because in my case I didn't have any php or html files with spaces in them :)

script-kiddie

Choosing a new editor: Emacs vs. Vim

For php I use Zend Studio for Linux. We have a license at work for it and it is in my opinion the best editor for php. It's relatively fast and you can use it to quickfix php over an ftp connection.

For Ruby I use netbeans. I would also like to use it for php but it doesn't allow to quicly open a file via ftp/scp or whatever. And it can sometimes be sloooooowwww. I've  seen netbeans used on a Windows platform and there it is much faster.

When I right-click on a project in netbeans for the first time, it takes 5 seconds (not lying!) to render the popup-menu. Come onm take forever!

And because I was now developing with Python I decided to try a new editor. Something more hardcore and lighter. Something nerdy :) So ofcourse I only have two decent options: Vim & Emacs.

I already had try them with Ruby. But I found good Ruby (& Rails) support rather lacking by both of them. I believe that the python comminity is more hardcore and therefore are using more arcane editors :) And maybe because they aren't afraid to hack away in another language than their own (lisp, vimscript).

I think I have been comparing the two editors for nearly two weeks now. I have spent hours and hours comparing, trying and browsing for blog posts about the two. At the end, I really didn't know which one to choose. I really suck at deciding something :) So I made a little list of what I find to be strong points of each editor:

VIM:

  • Better syntax highlighting/theming supprt (wombat ftw!!)
  • Faster/smaller
  • No weird handling of new buffers like with emacsclient
  • No daemon like: emacs --daemon
  • Better python integration
  • Easier to make extensions
  • Preview of docstrings when using omni completion

EMACS:

  • Better python-mode
  • No commandmode/normalmode
  • Directory browser/editor
  • Debugger (better integration with external tools)
  • easier to begin
  • Everyting is a buffer™

And now I have chosen to be the editor with which I am going to work is...... (drum roll please) .......:

Gedit!

No, it's (g)Vim :)

And while writing this article I was looking for a WordPress/blog plugin for Vim and Emacs. At a glance it looked like the wordpress plugin for Emacs was a little bit better. So already I was doubting my decision... So it could be that I switch editor in the next few months :) But I'm first going to really use gvim to see if it fits with my workflow and is really useable for me.

As cherry on the pie, a nice screenshot of my gvim in action:

Vim with python-mode

[update]
I've installed Netneans 6.8m2 and it feels a lot faster than 6.7 but python completion is as bad as in 6.7.
[/update]

[update2]
Found out about Vim's netrw. So Emacs no longer got "Directory browser/editor" as a strong point.
[/update2]

Zend and Compiz/visual effects

Zend logoWhen enabling Visual effects Zend wouldn't maximize anymore. So after a bit of googling I found a nice tutorial to fix the problem with Zend.

Problems with suexec/fastcgid and virtualmin

Since a few version of virtualmin I had some problems with checking the server configuration.

Virtualmin 3.72.gpl_webmin_error

The problem is that I have manually patched suexec and the php fcgid script is in /var/www and not /home.

I had this error for quite a while but last week I fixed it. It was quite simple. Just change this code in "/usr/share/webmin/virtual-server/feature-web.pl:

CODE:
  1. # Make sure home base is under base directory, or template CGI directory is
  2. if ($tmpl->{'web_suexec'} && $suhome &&
  3. !&same_file($suhome, $home_base) &&
  4. !&is_under_directory($suhome, $home_base) &&
  5. (!$cgibase || !&is_under_directory($suhome, $cgibase))) {
  6. return &text('check_ewebsuexechome',
  7. "<tt>$home_base</tt>", "<tt>$suhome</tt>");
  8. }
  9.  
  10. <p style="text-align: left;">return undef;
  11. }

To:

CODE:
  1. # Make sure home base is under base directory, or template CGI directory is
  2. return undef;
  3. if ($tmpl->{'web_suexec'} && $suhome &&
  4. !&same_file($suhome, $home_base) &&
  5. !&is_under_directory($suhome, $home_base) &&
  6. (!$cgibase || !&is_under_directory($suhome, $cgibase))) {
  7. return &text('check_ewebsuexechome',
  8. "<tt>$home_base</tt>", "<tt>$suhome</tt>");
  9. }  return undef;
  10. }

So just add "return undef;" to the top of that piece of code. Then it will step out of the function before the additional check is executed.

# Make sure home base is under base directory, or template CGI directory is
if ($tmpl->{'web_suexec'} && $suhome &&
!&same_file($suhome, $home_base) &&
!&is_under_directory($suhome, $home_base) &&
(!$cgibase || !&is_under_directory($suhome, $cgibase))) {
return &text('check_ewebsuexechome',
"<tt>$home_base</tt>", "<tt>$suhome</tt>");
}
return undef;
}

Burning from the commandline

cdrecord logoI download a Debian Sid livecd on my home server/HTPC and there's a cd burner in there. So I would like to burn the downloaded iso. There no X Server running (yet) on the box so I was searching for a nice commandline utility.

I found cdw and it really looked nice so I installed it:

CODE:
  1. aptitude install cdw

After running it with "cdw" it detected my cd-writer so no configuration needed: nice. Because I once tried mybashburn (or something like that) and that piece of software needed all kinds of configuration. And I don't like that.

I wanted to burn the debian sid iso with cdw but I couldn't find an option for doing so. After some searching I found out that I had to go to "preferences" and change the value of "Default image file". WTF? That's not very nice I thought. But I tried it. But a no-go. The path to my iso was to long to fit in the box. So I couldn't even select it.

Don't get me wrong: cdw IS nice for burning music cd's or just some files to backup. But isos.... pfff

So I resorted to cdrecord. It's got a bit of a "hacker" feeling to it but it did the job nicely:

CODE:
  1. cdrecord driveropts=burnfree /home/leon/debian-live-sid-amd64-xfce-desktop.iso

What I don't understand is why I have to manually enable burnfree. I mean: the last 5 cdr drives I had, all had burnfree. I'm doubting if they even make cd recorders without burnfree. So why not make it the default? Because apparently "Maybe it causes problems with *some* drives withput burn-free support". Hja, retards.

But there might be a solution to this problem. Cdrecord checks for "/etc/cdrecord.conf". And there you can change the default cdrecord parameters. My "/etc/cdrecord.conf" now contains:

CODE:
  1. driveropts=burnfree

But if it's correct of if it works: I don't know. I haven't yet tested it.

Phoogle: a _good_ fixed version

Recently phoogle broke because of some Google maps update. The original creators of Phoogle haven't updated the code (yet). And when searching online for newer, fixed versions all that showed up were crappy hacked Phoogle files by people who don't know what they're doing.

So hereby I present to you: a fixed Phoogle files which is hacked decent.

Installing fcgid with suexec AND phusion passenger


It was a troublesome day today. All did not go as planned.

I had to install fcgid + suexec on one of our servers, I had delayed it too long. So I used my how-to and it still worked flawless. But I noticed I hadn't mentioned what the right were of the suexec binary. So here it goes:

CODE:
  1. chown root:www-data suexec
  2. chmod 4754 suexec

After the install I restarted Apache and looked at one of the sites. And it worked! I was baffled. That's the first time I installed fcgid without hours long of searching where the flaw was.

But then I looked at our support system (Redmine) and it didn't work too well :)

All controllers were being executed 'n stuff. But the stylesheets, images and javascripts were not loaded. When requesting an image in the browser I got Rails 404-error page. Huh? Apache should have handled that request. At first I thought it was because of some changes I made to the virtualserver configuration of an other Rails site. But after some trial and error I couldn't find anything that was wrong.

Then I removed the .htaccess from the public directory of Redmine. That once worked for one of my rails sites. But no cigar. Then I noticed that there were a lot of dispatch*example.rb's in the public directory. And: after removing them, the stuff worked. So it seems like Rails or Phusion Passenger uses some kind of fuzzy matching when searching for a dispatch.rb. And it first just worked because fcgid was not installed. So I don't know who's to blame. But the problem is solved. Phew!

Released github widget

I think you all noticed my fabulous new sidebar widget: My projects :P

It shows all of my github projects. I directly turned it into a plugin for you to enjoy. You can download and read the documentation in the wordpress plugin directory.

mime_magic errors with php4

I went to a customer for our three-weekly sprint review, I opened my mail there and it was full with hundreds of failed cronjobs. Ah, shit! Another night at the datacenter? But it wasn't that bad :)

The server had ran an update of php that night and it broke. When I ran php4 from the commandline I got these errors:

CODE:
  1. PHP Warning: mime_magic: type search/400 \\input text/x-tex invalid in Unknown on line 0
  2. PHP Warning: mime_magic: type search/400 \\section text/x-tex invalid in Unknown on line 0
  3. PHP Warning: mime_magic: type search/400 \\setlength text/x-tex invalid in Unknown on line 0
  4. PHP Warning: mime_magic: type search/400 \\documentstyle text/x-tex invalid in Unknown on line 0
  5. PHP Warning: mime_magic: type search/400 \\chapter text/x-tex invalid in Unknown on line 0
  6. PHP Warning: mime_magic: type search/400 \\documentclass text/x-tex invalid in Unknown on line 0
  7. PHP Warning: mime_magic: type regex [Cc]onstant[[:space:]]+[Ss]tory text/x-inform invalid in Unknown on line 0

Wait a minute... I know these errors! But, of course, I hadn't documented the solution when I first fixed them. So after much searching I found the workarround again:

CODE:
  1. In the /usr/share/misc/magic.mime file, find the section that begins "# TeX documents, from Daniel Quinlan" and comment out the lines in that section.
  2.  
  3. # TeX documents, from Daniel Quinlan (quinlan@yggdrasil.com)
  4. #0 search/400 \\input text/x-tex
  5. #0 search/400 \\section text/x-tex
  6. #0 search/400 \\setlength text/x-tex
  7. #0 search/400 \\documentstyle text/x-tex
  8. #0 search/400 \\chapter text/x-tex
  9. #0 search/400 \\documentclass text/x-tex
  10.  
  11. # Type: Inform interactive fiction language
  12. # URL: http://www.inform-fiction.org/
  13. # From: Reuben Thomas
  14. #0 regex [Cc]onstant[[:space:]]+[Ss]tory text/x-inform

NOTE: For Debian, it appears that this file is located at /usr/share/file/magic.mime!